dart

Flutter - Is there an effect on having a single import rather than multiple?


Basically I have a lot of widgets and services and stuff, like most people do, that I need to access throughout the app. I was wondering if have a single file with an export of every single file and then just simply importing that one file in every page/file i need to access something rather than just importing specific files that the page needs, will it slow down the app or cause any issues or increase file size, etc... or will it behave the same?

Example

login_page.dart

import '1.dart'
import '2.dart'

home_page.dart

import '2.dart'
import '3.dart'
import '9.dart'
import '10.dart'

settings_page.dart

import '1.dart'
import '2.dart'
import '9.dart'
import '10.dart'

or...

all_imports.dart:

export '1.dart'
export '2.dart'
export '3.dart'
... (up until)
export '10.dart'

in every dart file:

import 'all_imports.dart'

Solution

  • Using 'all_imports.dart' may cause unneeded dependencies but dart knows how to handle dependencies that called but not used.

    Same implementation of 'all_imports.dart' is used by flutter team on 'material.dart'

    You may wish to just make simple design but when you import 'material.dart' it brings everything to the table ('about.dart', 'app.dart', 'banner.dart') and many others.

    I would advise you structure your application using 'all_import.dart' pattern