Include Import Another Folder Dart File in Flutter Call Widget Example

Like other programming languages dart dose support external module file system. Now in your mind the question is raise, what is a external file system. In flutter when we would work on a large project then there are so many screens, functions and other things in the project. We have to manage them separately otherwise they will be conflict with each other and we cannot file a particular screen or function in them if they are not organized. So we have to organized them via making module structure in our project. Using the module structure we can easily manage them with their screen names and function names. In today’s tutorial we would learn about Include Import Another Folder Dart File in Flutter and also call the widgets. Using the same method you can also call functions by making the class object. I’ve already made a tutorial on this topic so you can read it from here. So let’s get started 🙂 .

Contents in this project Include Import Another Folder Dart File in Flutter Call Widget Example in Android iOS :-

1. The first step is to open your flutter project and select the lib folder.

2. Now we would make another folder named ad modules inside the lib folder. We have to put all the files inside the lib folder in order to make the use.

3. As you can see in above screenshot there are 1 modules name folder, our main.dart file and textmsg.dart file. We would call two file in our tutorial 1 inside from modules folder and 1 directly from lib folder in our main.dart file.

4. We would also make a file named as color_block.dart in modules folder.

5. Now finally see our below screenshot to understand the complete file structure of our project.

Include Import Another Folder Dart File in Flutter5. Now we have to start coding for the app. First we have to make a file in lib folder named as textmsg.dart. Below is the source code of textmsg.dart file. In this file we would simply making a Text widget with some random text.

6. Creating another file named as color_block.dart inside your lib -> modules folder. In this file we would show a color block with some text.

7. Now open your project’s main.dart file and paste below code to import both above files properly and use their widgets in our main class.

Screenshot of App:

Include Import Another Folder Dart File in Flutter

Leave a Reply

Your email address will not be published. Required fields are marked *