Christopher DeCurtins
Christopher DeCurtins

Reputation: 142

Is it much more expensive to import a Flutter widget from a separate Dart file?

For example, say my main.dart file has a Container widget full of some other widgets. I'd like to move that whole Container to another Dart file for the sake of organization while developing, and import the new Dart file at the beginning of main.dart. So no change in functionality, just compartmentalizing.

Is it much more expensive at run-time to do this?

(I assume it will increase compile time at least a little, but I'm not concerned with that.)

Upvotes: 0

Views: 319

Answers (1)

Sisir
Sisir

Reputation: 5398

Short answer: No, it doesn't

Long answer:

There are 2 parts to an APP: compile-time and run-time.

While Compiling, the first step of most compilers is always preprocessing. As part of this step it tries to remove all the #import statements and comments. In general an #import is equivalent to copying the entire code of that file and pasting in the parent file i.e. main.dart in your case. So basically after the first phase of compilation , it doesn't matter whether you have split the code into multiple dart files or you have a huge dart file with all code in 1 place.

Run-time is a different place. It doesn't directly depend upon how your code is structured. Instead it depends upon how your compiled code the APK looks like. For example a debug mode APK will run slower that a release mode APK, because it has extra things in it and no optimization done.

Upvotes: 3

Related Questions