Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 453 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I add an Example Project to a Flutter Package?

#1
Is there a way to autogenerate template code for the example map structure in a package?

Most packages have a /example folder within the package root that showcases the package functionality.
I'm not sure what's the "best" way to create the example is, or if it even matter.

Do I create all files individually?
Do I create a new project and then copy it to the package root?
Can I autogenerate an example project directly in the project?

It's my first attempt on creating a package and I want to get it right the first time.
Reply

#2
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:

[![enter image description here][1]][1]
[![enter image description here][2]][2]


[1]:

[2]:


Now in `pubspec.yaml` you should include your package as dev dependency like this:
```yaml
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.
Reply

#3
Go to your project root folder and run `flutter create example`.
Thats it.
Reply

#4
To create a Flutter package with an Example in Android Studio
1. Create a new Flutter Project
[![enter image description here][1]][1]
2. Select Flutter Package
[![enter image description here][2]][2]
3. After the new project opens in Android Studio, select the "Terminal" tab and then run:

> **flutter create example**

[![enter image description here][3]][3]

4. Select "Edit Configuration"-> add configuration -> Select the main.dart file that is located in the example/lib folder
[![enter image description here][4]][4]
[![enter image description here][5]][5]
[![enter image description here][6]][6]
[![enter image description here][7]][7]

5. Open your example pubspec.yaml and link to the library by adding:

your_package_name:
path: ..\
[![enter image description here][8]][8]

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:
[![enter image description here][9]][9]


[1]:

[2]:

[3]:

[4]:

[5]:

[6]:

[7]:

[8]:

[9]:
Reply

#5
Use the built-in **flutter** command-line tool in the root directory of the project to do all the work:

```
/e/projects/myproject # flutter create example
```
which has this output:
```
Creating project example... androidx: true
example\.gitignore (created)
example\.idea\libraries\Dart_SDK.xml (created)
example\.idea\libraries\Flutter_for_Android.xml (created)
example\.idea\libraries\KotlinJavaRuntime.xml (created)
example\.idea\modules.xml (created)
example\.idea\runConfigurations\main_dart.xml (created)
example\.idea\workspace.xml (created)
example\.metadata (created)
example\android\app\build.gradle (created)
example\android\app\src\main\kotlin\com\example\example\MainActivity.kt (created)
example\android\build.gradle (created)
example\android\example_android.iml (created)
example\android\.gitignore (created)
example\android\app\src\debug\AndroidManifest.xml (created)
example\android\app\src\main\AndroidManifest.xml (created)
example\android\app\src\main\res\drawable\launch_background.xml (created)
example\android\app\src\main\res\mipmap-hdpi\ic_launcher.png (created)
example\android\app\src\main\res\mipmap-mdpi\ic_launcher.png (created)
example\android\app\src\main\res\mipmap-xhdpi\ic_launcher.png (created)
example\android\app\src\main\res\mipmap-xxhdpi\ic_launcher.png (created)
example\android\app\src\main\res\mipmap-xxxhdpi\ic_launcher.png (created)
example\android\app\src\main\res\values\styles.xml (created)
example\android\app\src\profile\AndroidManifest.xml (created)
example\android\gradle\wrapper\gradle-wrapper.properties (created)
example\android\gradle.properties (created)
example\android\settings.gradle (created)
example\ios\Runner\AppDelegate.swift (created)
example\ios\Runner\Runner-Bridging-Header.h (created)
example\ios\Runner.xcodeproj\project.pbxproj (created)
example\ios\Runner.xcodeproj\xcshareddata\xcschemes\Runner.xcscheme (created)
example\ios\.gitignore (created)
example\ios\Flutter\AppFrameworkInfo.plist (created)
example\ios\Flutter\Debug.xcconfig (created)
example\ios\Flutter\Release.xcconfig (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\Contents.json (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\[email protected] (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\[email protected] (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\[email protected] (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\[email protected] (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\[email protected] (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\[email protected] (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\[email protected] (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\[email protected] (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\[email protected] (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\[email protected] (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\[email protected] (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\[email protected] (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\[email protected] (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\[email protected] (created)
example\ios\Runner\Assets.xcassets\AppIcon.appiconset\[email protected] (created)
example\ios\Runner\Assets.xcassets\LaunchImage.imageset\Contents.json (created)
example\ios\Runner\Assets.xcassets\LaunchImage.imageset\LaunchImage.png (created)
example\ios\Runner\Assets.xcassets\LaunchImage.imageset\[email protected] (created)
example\ios\Runner\Assets.xcassets\LaunchImage.imageset\[email protected] (created)
example\ios\Runner\Assets.xcassets\LaunchImage.imageset\README.md (created)
example\ios\Runner\Base.lproj\LaunchScreen.storyboard (created)
example\ios\Runner\Base.lproj\Main.storyboard (created)
example\ios\Runner\Info.plist (created)
example\ios\Runner.xcodeproj\project.xcworkspace\contents.xcworkspacedata (created)
example\ios\Runner.xcworkspace\contents.xcworkspacedata (created)
example\lib\main.dart (created)
example\example.iml (created)
example\pubspec.yaml (created)
example\README.md (created)
example\test\widget_test.dart (created)
Running "flutter pub get" in example... 3.0s
Wrote 68 files.

All done!
[√] Flutter: is fully installed. (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 6.1.7601], locale en-US)
[√] Android toolchain - develop for Android devices: is fully installed. (Android SDK version 29.0.2)
[√] Android Studio: is fully installed. (version 3.5)
[√] Connected device: is fully installed. (2 available)

In order to run your application, type:

$ cd example
$ flutter run

Your application code is in example\lib\main.dart.

```
If using Android Studio 3.5.2, run the default example for assurance:

1. Add a new configuration for the example main.dart by selecting *Edit Configurations...* from the Flutter drop-down on the toolbar.

2. Select the Flutter directory on the left of the *Run/Debug Configurations* dialog and press the *+* button.

3. Select *Flutter*

4. Browse for main.dart in the new example/lib directory by clicking the file folder in the *Dart entrypoint:* dialog.

5. Click the triangle run button on the toolbar.

I just performed these steps for my own project and it worked perfectly.

Then, to customize for your project, edit the example's **pubspec.yaml** file and add a dependency to your project:
```
dependencies:
my_project:
path: ../
```
Reply

#6
*In my case , I had forgot to add the example file . I added this in this way.*
You can check at my pub.dev [location_provider][1] package.

1)Create a directory/package inside you package . Name of package/directory must be "**example**". For more info [***check this.***][2]

2)Open command Terminal and move inside the ***example*** package using



cd example

3)Create Flutter project inside it using command


Flutter create

4)You will see the ***lib/main.dart*** file inside it. Add your example in this file.

5)After adding , push latest code to the github.

6)Increase the version of your package inside ***pubspec.yaml*** file and ***CHELLAGELOG.md*** file . After that, run these command to publish the package to ***pub.dev***.

Flutter publish --dry-run
Flutter publish

*After that you will see ,example Tab in* ***pub.dev***


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through