How do I create a pub package that works with Flutter?

pub is the Dart package manager. Flutter is a mobile app SDK that uses Dart. How can I create a package that depends on, or target, Flutter?

+3


source to share


2 answers


To declare a dependency on Flutter, from the pub package add this to yours pubspec.yaml

:

dependencies:
  flutter:
    sdk: flutter

      

You should use flutter packages get

instead pub get

because Flutter has to set the appropriate environment variables for sdk: flutter

location mapping .



Use the stagehand tool to quickly and easily create a new pub pack . After installing stagehand follow these instructions:

$ mkdir fancy_project
$ cd fancy_project
$ stagehand package-simple

      

After creating a new package, edit pubspec.yaml

and add sdk:flutter

as shown above.

+4


source


The trick I also use is to simply flutter create foo

(which creates a complete Flutter app, more than you need) and then rm -rf foo/ios foo/android

edit / delete foo/lib/main.dart

, etc.



The stagehand solution by @sethladd is more elegant, but requires a stagehand setup.

+1


source







All Articles