Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - multiple files for screens?

Tags:

flutter

I'm currently learning Flutter development (as well as Dart). It's my first mobile programming language.

I'm curious - is there a way to split screens into .dart files, or do they all have to be in the same main.dart file?

The app I'm building will have a lot of pages, so I don't want to make one giant main.dart file with 20+ different pages.

Is Flutter the right choice if I'm trying to make a large application like this?

like image 904
Rohit Ganguly Avatar asked Jul 06 '18 05:07

Rohit Ganguly


People also ask

How do you organize files in flutter project?

start from the domain layer and identify the model classes and business logic for manipulating them. create a folder for each model (or group of models) that belong together. within that folder, create the presentation , application , domain , data sub-folders as needed. inside each sub-folder, add all the files you ...

How do you link two darts in flutter?

Step 1: Create your file that is needed to be referred, by double-clicking on the lib folder and then on “New File“. Give a filename to it and the extension should be . dart. Step 2: Go to your main file where you want to refer to your second file.


1 Answers

You can split your code in as many files as you want. It's encouraged to have as little code as possible in lib/main.dart and all the other code split into various files. The only limitation is that code in one file (library) can not access private members of other files.

See How to reference another file in Dart? for how to import other Dart files.

like image 110
Günter Zöchbauer Avatar answered Sep 21 '22 12:09

Günter Zöchbauer