how to use local flutter package in another flutte

2020-02-17 05:18发布

问题:

How to use local flutter package in another flutter application?

I created a package using following command:

flutter create --template=package my_new_package

and then in my application source code => main.dart

import "package:my_new_package/my_new_package.dart" // can not find the package

回答1:

locate this file in your flutter application => pubspec.yaml

make local dependency

dependencies:
   flutter:
     sdk: flutter
   my_new_package:
     path: ./my_new_package


回答2:

Path dependency: A Flutter app can depend on a plugin via a file system path: dependency. The path can be either relative or absolute. For example, to depend on a plugin plugin1 located in a directory next to the app, use the following syntax:

dependencies:
  plugin1:
    path: ../your_package/