I would like to clean up my Flutter directories early on, not as an afterthought. I know that after a few years I'll have dozens if not hundreds of samples, experimentations, and half-hearted attempts, both my own and from SO or elsewhere. Then I'll want to clean all this up and keep just the actual source files.
Rather than gather up 500KB per sample, with 400 to 2000+ files (depending on the number of target platforms) and clean up later, I'd like to set things up right now so that it's clean from the beginning, and no clean-up is needed later on.
I am a (deeply committed [yes, "there's always one of those"]) Emacs user who is learning Flutter. While experimenting I type
flutter create newproject (edit lib/main.dart in Emacs) (compile and run)
Afterwards I type
> du -hs newproject 460K newproject
I understand that the intermediate files—whether the target is iOS, Android, or the web—must be saved somewhere. Still, these intermediate files are, at least during a learning phase, entirely discardable, and the fact that the logic fits in just one file is quite admirable, being a great improvement over coding in XML+Java/Kotlin or in XML-Storyboard+Swift.
Does there exist a workflow that would enable me to say: this directory consists of 30 different
main.darts; I'd run something from the command line based on just one file, take a 30 second break, and come back when the intermediate files have been generated?
To be clear, it's entirely easy to write a short script to do this on my side. Here I'm wondering whether I can avoid reinventing the wheel, in particular that anything I do will certainly be far less featured than a (semi-)official solution.
Solution 1: rmtmckenzie
You can get close to what you want with
flutter create. If you specify all the same parameters, it will attempt to rebuild rather than replace everything each time. It will overwrite the iOS/Android files as necessary, but it will not overwrite
One way to do it is as follows. You can keep an arbitrary number of your experiments in (
lib/main2.dart, ...) within a single project. You'd keep all the "intermediate" files in place. You can then run different
main.dart files just by typing, for example,
flutter run -d "<device>" lib/main2.dart from the same project.
Technically, all your Dart files would still belong to the same project, but you'd be launching just one screen at a time. The screen you're launching would run independently from the remaining n-1 main.dart files in
However, each time you run one
main_n.dart, it will replace the existing app on the phone (they'd all have the same app id as that's defined in the native side of things). This is suitable for experimenting quickly, but wouldn't be good for actually publishing.