How do I add an Example Project to a Flutter Package?
Go to your project root folder and run flutter create example
.
Thats it.
To create a Flutter package with an Example in Android Studio
- Create a new Flutter Project
- Select Flutter Package
- After the new project opens in Android Studio, select the "Terminal" tab and then run:
flutter create example
Select "Edit Configuration"-> add configuration -> Select the main.dart file that is located in the example/lib folder
Open your example pubspec.yaml and link to the library by adding:
your_package_name: path: ..\
NOTE: When you open the Example folder it will look like an entire Flutter app nested into your project; that's because it is. Just open the io and android folders to see that they share that pattern:
Create a new project inside the root directory of your project called example and then remove unnecessary files such as CHANGELOG
, LICENSE
and README
as they will be in your package folder.
Here's an example (no pun intended) with a package that I created:
Now in pubspec.yaml
you should include your package as dev dependency like this:
dev_dependencies:
your_package:
path: ../
I believe you can also use regular dependencies, but this worked for me.
Now inside /lib
you can add a main.dart
file, import your package and then create an example project.