I am new to dart so please bear with me if this is really bad question. I am developing an app using flutter, and I have one question. I have many screens in my app, like About the App, Homepage, Upcoming Events, etc. I have kept all these screens in a folder in lib/screens directory. And to import them in main.dart for routes I have to import each and every file, like
import "screens/homepage.dart";
import "screens/aboutTheApp.dart";
import "screens/upcomingEvents.dart";
Is there a simpler way to do it? Is there a way to import the "screens" directory at once?
I have tried to import the complete folder and tried making it a package, but it isn't helping.
How to list the contents of a directory in Dart. final dir = Directory('path/to/directory'); final List<FileSystemEntity> entities = await dir. list(). toList();
When importing a library file from another package, use the the package: directive to specify the URI of that file. import 'package:utilities/utilities. dart'; When importing a library file from your own package, use a relative path when both files are inside of lib, or when both files are outside of lib.
Exports the current Flutter internationalisation files to a singl CSV so that all translations can be worked on in on document. Once translation is complete, you can then use CreateCommand to generate new arb files to use in your Flutter project.
You can create a file in the screens
directory and call it all.dart
or whatever you like. In this file, you will simply export all of the Dart files in that folder:
export 'homepage.dart';
export 'aboutTheApp.dart';
export 'upcomingEvents.dart';
Now, whenever you want to use any file from that folder, you can just import all.dart
or what you called it:
import 'screens/all.dart`;
...
Other than that, there is no possibility to import a directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With