Transform the Flutter App to Module

Method 1: Copy method (rough and direct)

// create a new Module project$ flutter create --template module hello_module// 2. Copy lib folder to hello_module // 3. Copy the 'pubspec.yaml' file and keep the lines at the bottom module: androidX: true androidPackage: com.example.hello_module iosBundleIdentifier: com.example.helloModuleCopy the code

Method 2: Fine-tuning method (recommended)

  1. Modify thepubspec.yaml, at the very bottom (note the indentation, with two Spaces to the left).
  module:
    androidX: true
    androidPackage: com.example.hello_module
    iosBundleIdentifier: com.example.helloModule
Copy the code
  1. Modify the.metadataThat will beproject_type: appInstead ofproject_type: module.
  2. removeiosandandroidFolder.
  3. Clean and generate.iosand.android.
// Cleanup project
$ flutter clean
// Get the dependency packages again. The.ios and.android folders will also be regenerated
$ flutter pub get
Copy the code

Questions encountered

  1. In the process, I was struggling with the problem of how to run the project when converting to Module. Later, when I think about it in reverse, actually generating module alone can also run, and. Ios and. Android contain a demo project.
  2. Method 2: Be sure to remove the ios and Android folders, otherwise the generated ios demo project will be missing.
  3. What if you want to turn modules into applications? After practice, I found that it is still similar to solution 1, because there is no way to automatically generate ios and Android folders.