If I create a file like widgets.dart and put the exportation of all my widgets inside that like below:
export 'custom_app_bar.dart';
export 'content_header.dart';
export 'vertical_icon_button.dart';
Then import this file wherever I needed one of these widget inside another file like below:
import './widgets/widgets.dart';
Is it a bad practice and would have overhead process/memory issues?
I am also thinking about put more codes in the same file, for example define 3 different MobileSizeHomeScreen() , TabletSizeHomeScreen(), DesktopSizeHomeScreen() classes/widgets inside one file like home_screen.dart instead of creating 3 different mobile, tablet, desktop files, but don't know doing such a things would cause performance or maintenance issues while the project gets larger and more complexed or not?
As far as I know, that isn't a bad practice. However, Dart presents us with
partandpart ofto do that kind of stuff. You can read more about Dart effective usage here.Suppose all of those four files are within the same directory.
In the above's case,
./widget/widgets.dartwould have this line (above the class declaration):and in each of those three, they will have this line that indicates, they are part of the
./widget/widgets.dart:Then, when you need one of the widgets, you only need to import
widgets.dartI see some of the other Dart developers also use the
exportstuff, so it is a matter of preference. Personally, I would prefer what Dart recommends, which is usingpartandpart of.