I have flutter project with tree looks like
...
├── lib
│ ├── UI
│ │ ├── base_widget.dart
│ │ ├── components
│ │ │ ├── card.dart
│ │ │ ├── centered_progressIndicator.dart
│ │ │ ├── gradient_button.dart
│ │ │ └── rounded_network_image.dart
│ │ ├── more
│ │ │ ├── announcements
│ │ │ │ └── announcements.dart
│ │ │ ├── more.dart
│ ├── main.dart
├── pubspec.lock
├── pubspec.yaml
└── test
└── widget_test.dart
In announcements.dart
(also in some other files) I want to import card.dart
. Now I am importing like import '../../components/card.dart';
.
If I change name of components
directory to something else, I have to edit all the files where I import components/card.dart
.
Also, I know relative import with ../
is not recommended, should use package:
.
My question is how to write an import statement that doesn't affect directory structure changes? Is this possible in dart?