I have some model classes shared between different dart projects.
Option 1
First, I followed the dart Library convention to do the following:
In the project/package which imports the common lib/package:
- pubspec.yaml:
dependencies:
mycommon:
path: ../mycommon
- some_class.dart:
import 'package:mycommon/models.dart';
the common lib/package:
- pubspec.yaml
name: mycommon
lib/src/model/model_1.dart
lib/src/model/model_2.dart
...
lib/src/model/model_50.dart
lib/models.dart:
library mycommon;
export 'src/model/model_1.dart';
export 'src/model/model_2.dart';
...
export 'src/model/model_50.dart';
Option 2
Treat the common lib as a normal package
In the project/package which imports the common lib/package:
- pubspec.yaml:
dependencies:
mycommon:
path: ../mycommon
- some_class.dart:
import 'package:mycommon/model/model_1.dart';
the common lib/package:
- pubspec.yaml
name: mycommon
lib/model/model_1.dart (no library keyword)
lib/model/model_2.dart
...
lib/model/model_50.dart
I don't find anywhere using Option 2 yet. This is just what I came up with by myself.
My question is simply if the Option 2 way is recommended? I prefer using the Option 2 because I can just import what class I actually want instead of everything. And most of time, I will only need one class model per dart file.
(no library keyword at all. just a normal class)
What does that mean? Where did you get the idea of naming a file.class
? – Nate Bosch