Native Shopify Mobile App with 20 new features
Kickstart your hyperlocal marketplace in Corona pandemic with a starter guide
Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 18.104.22.168 release ready!
Owner and Founder. Opencart
In this tutorial How To Create Package In Flutter, you’ll learn how to create your own Dart packages to be used in Flutter apps.
How To Create Package In Flutter? Dart packages help us solve issues and create workarounds for problems without having to write the code ourselves from scratch.
Some advantages of being a package publisher:
On your Android Studio’s menu bar, click File ▸ New ▸ New Flutter Project. Then, select Flutter Package and click Next.
Now, follow the instructions to fill in the fields:
Click Finish and wait for Android Studio to create and load your new project.
Or you can you terminal
Next, we’ll create a custom button styled to our liking.
Clear the original code generated by Flutter in the lib/<project name>.dart. Then, add the CustomButton widget
The library <project name> code sets the name of our package to <project name>.
library <project name>
First, we imported the Flutter Material package — this is the root of all Flutter apps. Next, we created a CustomButton class that extends the StatelessWidget class. This causes our CustomButton widget to hold or manage no local state.
We have three properties that the CustomButton widget constructor will receive:
The build method renders a TextButton and styles the button as follows:
Our custom button is something like a smaller version of TextButton. This button renders a customized TextButton. Inside our CustomButton, we increased the padding, elevation, background color, and text style of the TextButton.
Open your new project’s pubspec.yaml file. Notice that the content of the file is grouped into five sections: metadata, environment, dependencies, dev_dependencies, and flutter. For this tutorial, you’ll need only the first three:
Everything users need to find your package comes out of here.
You already provided parts of this information when creating the project. Now you need only a few adjustments:
Use this section to restrict the Dart or Flutter SDK versions of your users. This is useful if, for example, your package relies on a feature introduced in an earlier Flutter release or you still haven’t complied with a breaking change in the API.
Packages can also depend on other packages. This section is no different than the one you find in your apps. You can also use other packages in your package, Specify the dependency, then make sure your section looks like this:
Every good package has an example app. The example app is the first thing your users will turn to if they can’t make your package work right off the bat. It should be as concise as possible while still showcasing every feature.
Create your example project by again clicking File ▸ New ▸ New Flutter Project. This time, select Flutter Application and click Next.
Like you did before, follow the instructions to fill in the fields:
Click Next and, in the following window, type com.YOUR_APP_NAME.example in the Package name field. Finally, click Finish and wait until Android Studio opens your example project in a new window.
Open your example project’s pubspec.yaml and replace the entire dependencies section with:
Open lib/main.dart and add the following code to the _MyHomePageState widget:
We imported the your_flutter package, then we set the CustomButton widget in the Center widget.
Run the example project by running flutter run in the command line. If you’re using VS Code, right-click on the lib/main.dart file and click Run Without Debugging.
How To Create Package In Flutter in this blog we covered a lot in this tutorial. We started by introducing packages in Dart, what they are, and how they are designed to share code with other devs.
Later on, we learned how to scaffold a Flutter package project and how to write the package code. Next, we learned how to test our Flutter package locally.
If you want to learn about how to publish a package on https://pub.dev/ please visit this link:
You can read more blogs from Mobikul on this website: https://mobikul.com/blog/
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
Very good company, we did get app extension for Magento 2 website. The support was very good they help us through the process. Webkul team is very supportive, I would recommend them.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.