Reputation: 695
I have the following enum in a module (aka a .dart file):
enum HttpMethods { GET, POST, PUT, DELETE }
I would like to be able to import and use this enum inside a few classes in different modules. How would I go about doing this?
Upvotes: 0
Views: 990
Reputation: 1193
You can simply import the file path inside another file and access it like that.
import '../enums/http_methods.dart';
final HttpMethods _myValue = HttpMethods.GET;
Or, create an enums.dart
export file from which you export all your enums, and import this where you need it. It saves you from a lot of clutter down the line.
enums.dart
export 'http_methods.dart';
import '../enums.dart';
final HttpMethods _myValue = HttpMethods.GET;
Upvotes: 1