flutter-intellij icon indicating copy to clipboard operation
flutter-intellij copied to clipboard

Unable to add Flutter Module to Flutter Application/Project

Open strangedreamsNY opened this issue 3 years ago • 5 comments

Unable to add Flutter Modules to my Flutter Project so that I can separate out common logic/ui etc that will be used across multiple apps.

Steps to Reproduce

  • Create a new, default, Flutter Project
  • Click on File -> New -> New Module
  • From the 'New Module' dialog box, select Flutter and click Next
  • Change the Project Type to 'Module', leave all other settings as-is and click 'Finish'

Expected

A new Flutter Module to appear in my project.

Actual

An error dialog box appears: 'Internal Error: Unable to determine Flutter project directory'.

Version info

flutter_doctor.txt

strangedreamsNY avatar Sep 09 '22 19:09 strangedreamsNY

IntelliJ modules are not supported in Flutter apps. You can use Dart packages and Flutter plugins instead.

stevemessick avatar Sep 09 '22 21:09 stevemessick

I wasn't adding an Intellij Module, it was a Flutter Module, per the steps above. See attached images for additional reference. Or are you saying that it's not possible, nor planned at any point, to allow users to work on a Flutter Module along side a Flutter App?

Annotation 2022-09-09 193240 Annotation 2022-09-09 193315 Annotation 2022-09-09 193334

strangedreamsNY avatar Sep 09 '22 23:09 strangedreamsNY

Additionally, selecting 'Package' or 'Plugin' from the Project Type dropdown results in the same error message.

strangedreamsNY avatar Sep 09 '22 23:09 strangedreamsNY

File > New > New Module creates an IntelliJ module. These have not turned out to be very useful in Flutter projects, so we don't encourage using them.

Flutter modules, along with plugins and packages, are created as different kind of Flutter projects. The CLI command flutter create --template=module sample will create a Flutter module named "sample". Those templates are also available through the new project wizard in IntelliJ and Android Studio. (Mostly; the plugin_ffi template is missing.)

Most projects use packages and plugins to organize and re-use code. For more info, see the Flutter docs: https://docs.flutter.dev/development/packages-and-plugins/developing-packages Flutter modules are intended for use in adding Flutter-driven capabilities to an existing Android or iOS app.

Also, the Flutter plugin does at least try to support monorepo project organization. You should be able to create some Flutter projects in a common directory, and then open the parent directory to work on all of them together. See the previous release notes for instructions: https://groups.google.com/g/flutter-announce/c/on6eKqmhD3A

Having said all that, it used to be possible to create an IntelliJ module for a Flutter project. Something changed, so I'll keep this open.

stevemessick avatar Sep 12 '22 16:09 stevemessick

@stevemessick Curious. B/C that 'New Module' dialog does still include the Flutter Project as an option. There's probably some way around this. Just to be clear, my intent is to work on Flutter projects similarly to other Java/C# projects where you might have multiple 'primary' applications but a common backing library. In my case, I'm developing a 'lite' version of an application with a subset of features, so moving all the common Widget/Bloc work to a shared module seems to make the most sense. But I'd rather not have to keep 3 instances of Android Studio open to do it.

I have found a workaround in the meantime (I think):

  • Create a new Flutter Module using the command line or as a separate Android Studio project.
  • Open the Project Structure dialog and select 'Modules'
  • Click on the 'add' icon and select 'Import Module'
  • Locate the folder of the previously created Module.
  • Select 'Create module from existing sources' (importing does not work here)
  • Unselect all the detected modules except Flutter. and select 'Next'
  • Keep the detected Android module selected and click 'Finish'

This seems to get the second (or third) Flutter modules attached to the primary project with everything in-sync including separate git remotes. So that's nice.

strangedreamsNY avatar Sep 13 '22 17:09 strangedreamsNY