Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 901 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to remove or identify unused packages from flutter to reduce size of the project?

#1
I used some packages that I no longer need in my flutter project, namely the `wilddog_auth` and `wilddog_sync`, I can remove the imports from `pubspec.yaml` file, and my dart files (aka removing `import 'package:wilddog_sync/wilddog_sync.dart'` etc.) and remove imports in MainActivity.java as well as in Xcode project but I can't purge the unused files installed by flutter, cocoapod and gradle. Now is there a unified command in flutter where I can remove all unused packages at once?

I am pretty sure using `flutter clean` only removes build folder and using `flutter packages get` after removing packages from `pubspec.yaml` doesn't remove packages from `cocoapod` or `gradle` either.

For example, after `flutter clean` and `flutter packages get` I rebuilt the project:

Launching lib/main.dart on Android SDK built for x86 64 in debug mode...
Initializing gradle...
Resolving dependencies...
Running 'gradlew assembleDebug'...
Built build/app/outputs/apk/debug/app-debug.apk.
Installing build/app/outputs/apk/app.apk...
I/FlutterActivityDelegate(11331): onResume setting current activity to this
I/Choreographer(11331): Skipped 107 frames! The application may be doing too much work on its main thread.
D/EGL_emulation(11331): eglMakeCurrent: 0x79f21b4dbec0: ver 2 0 (tinfo 0x79f219b4f160)
I/OpenGLRenderer(11331): Davey! duration=1903ms; Flags=1, IntendedVsync=7544454683637, Vsync=7546238016899, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=7546253803603, AnimationStart=7546253996603, PerformTraversalsStart=7546254171603, DrawStart=7546279222603, SyncQueued=7546288526603, SyncStart=7546295569603, IssueDrawCommandsStart=7546296644603, SwapBuffers=7546334455603, FrameCompleted=7546365204603, DequeueBufferDuration=2892000, QueueBufferDuration=199000,
Syncing files to device Android SDK built for x86 64...
D/ (11331): HostConnection::get() New Host Connection established 0x79f219ab81e0, tid 11383
D/EGL_emulation(11331): eglMakeCurrent: 0x79f21b5e26e0: ver 2 0 (tinfo 0x79f219aa66c0)
W/IInputConnectionWrapper(11331): getCursorCapsMode on inactive InputConnection

[![cocoapods][1]][1]
[![gradle][2]][2]

[1]:

[2]:


Yet all the package files remained.

Of course I could go into `./ios/` to run `pods install` to remove pods:

pod install
Analyzing dependencies
Fetching podspec for `Flutter` from `.symlinks/flutter/ios`
Removing Wilddog
Removing WilddogCore
Removing WilddogSync
Downloading dependencies
Using Flutter (1.0.0)
Generating Pods project
Integrating client project
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

[!] Automatically assigning platform `ios` with version `8.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.

Reply

#2
This behavior seems to be a bug. You can track it here

[To see links please register here]

Reply

#3
You can use this three steps to clear this issue

1. 'flutter clean'
2. Remove the unwanted dependencies in pubspec.yaml
3. Delete the pubspec.lock

Reload the project and again perform 'pub get' and run the iOS/Android project
Reply

#4
The best way to do this is
```
flutter clean
```

If this doesn't work just create a new project copy your old code into the new project and here you can add only the dependencies you want before running pub get.
Reply

#5
delete the hosted folder of *.pub-cache* in flutter SDK directory

cd path/to/flutter_sdk_directory

rm -rf .pub-cache/hosted

delete the *.packages* file in the project root directory

cd path/to/project_root_directory

rm -rf .packages

get packages for the project

cd path/to/project_root_directory

flutter pub get

open the project in Android Studio

done.
Reply

#6
Sometimes there might be packages that is not used in the project but you have installed sometime during the development stage. To find out those, First go to each dart file and remove the unused imports, then go to pubspec.yaml and comment the packages one by one and save the project. And then refresh the application(NOT HOT RELOAD). if the package us used in the project then it will throw you an error. After repeating the steps on all the packages you will be able to remove all the unwanted packages from your pubspec.

Now, delete the pubspec.lock file, and run the pub get again. Your project will now be having only the required packages and this could be the minimum size achievable.

[![enter image description here][1]][1]


[1]:
Reply

#7
There is an intuitive way for it.
Install [this][1] package

dev_dependencies:
dependency_validator: ^x.x.x
Then run `flutter pub run dependency_validator`
It will show all the details about the packages installed.
Example: =>

>These packages are pinned in pubspec.yaml:
* dependency_validator: null -- This is a direct pin.
* permission_handler: null -- This is a direct pin.
* swipe_to: null -- This is a direct pin.

>These packages are used in lib/ but are not dependencies:
* connectivity
* meta
* path

>The following packages contain executables, they are assumed to be used:
* flutter_native_splash
>These packages may be unused, or you may be using assets from these packages:
* cupertino_icons
* firebase_analytics
* http
* loading
* sign_in_with_apple



[1]:

[To see links please register here]

Reply

#8
You can remove by typing in terminal `dart pub remove <packagename>`

Example : To remove `flutter_svg:^0.22.0` ,
type `dart pub remove flutter_svg`

For more informations, check

[To see links please register here]

Reply

#9
There's an obvious way which is easy to overlook or think is not feasible.

If using IntelliJ, simply do "Find in files" (SHIFT+CTRL+F on PC, SHIFT+CMD+F on Mac), select "Directory" and choose the lib-folder of your project.

Then go through your list of plugins and search for the name of each one in turn. The plugin isn't used if

- there are no search results for its name
- it's only used in "generated_plugin_registrant.dart"
- the only hits are import statements that are grey (marked as unused by IntelliJ)

Took me less than a minute to eliminate 8 unused plugins using this method.
Reply

#10
Flutter takes care of that by running this command:

$ flutter pub cache repair

I tried at first to just remove ***webview_flutter: 4.1.0*** from *pubspec.yaml* and run

$ flutter clean
$ flutter pub get

but Flutter keeps a cached version of popular packages in *.pub-cache/hosted* directory so you must either remove the cached packages manually or preferably by running the first command.


I'm using Flutter: 3.7.10 and Dart: 2.19.6
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through