Flutter Application structure: Organising Files In Flutter
By: Gadhavi Uma
Tags: Flutter App Development, Flutter, Flutter App, Learning To Code, Flutter Widget

Flutter Application structure: Organising Files In Flutter

Once you have created Flutter Project, you will see this type of view

Flutter File Structure

Here you can see Main. dart file is open. This is very essentially File, as from here the Flutter application will get started.

This file is having dart code so we will save by giving. dart extension. These simply represent one screen or we can say similar to one activity in Android. To create an application, we will create many dart files like to provide proper navigation and action throughout the application.

As shown in the Image, there will be Folder as .dart_tool, and .idea which are auto generated you don't need to apply any changes into that folders.

After that you can see folder Named android where android specific code will be available. Sometimes we need to perform some platform specific changes only to android then we can manipulate files resident inside this android folder. Once you specify such changes in only android devices, it will reflect. It won't change anything on IOS devices.

Same like android, there will be a folder as ios where ios specific code will be available. You can provide platform specific changes for ios inside this folders code.

By default, the android and ios contain auto-generated platform specific file. Unless you want to perform any Specific change in android or ios, you don't need to change them.

You won't need to create such files or don't require learning Kotlin for android or Swift for ios Flutter will generate android and ios files by converting dart files. so it's not your headache. flutter will do it for you!!. you will touch those files only when you become master!!!

lib: lib folder is the main folder we will deal with. inside lib folder currently only one main.dart file is there which contains a logic of our application.

We will deconstruct main. dart file and understand how to write code in my article “Understanding Flutter Code: hello flutter App ”

After lib folder there will be test folder. Which is in use when you run your app. It will contain cache and other memory efficiency things to make our testing faster. You can delete it. It won't affect your project. Flutter will automatically create it again when you run the application.

Tip: Sometimes when our application crashes and after updating code it don't show the expected changes on app you can try by deleting this test folder and run again. if memory or other related things were reason then it will correct it and show desired output

.gitignore file is for connection between git repository

.metadata: this file contains metadata about the application. On basic level you won't need to change it

.package: this file contains information related to packages

flutter_app.iml: as in my flutter application’s name is flutter_app its shows flutter_app.iml your will according to your project name.iml you don't mostly need to update this file.

pubspeck.lock: this file will be auto-generated and you won’t need to change.

pubspeck.yml: this is a very important file because every asset, plugin we use in application, we have to specify inside this file. We also need to mention any permission and usage related things here in this file.

readme.md: this file is auto-generated you won't deal with it

external libraries: it will contain all the libraries you have used in the project.

scratches and consoles: will contain bug report and other such files

So now you understood that main two things are important: 1) lib folder and 2) pubspec.yml

Tip: When we create big application we will have so many dart files inside the lib folder so it is good practice to maintain them using creating packages (folder-wise) in lib folder like we can separately create design folder for saving all screen designs, we can create a utility folder for writing frequently usable code.

So you understood which file does what so now will learn how to write code in main.dart file and update our default code.