Just for Flutter.
flyme_generator is a generator for flyme (framework for flutter).
- add flyme_annotation to pubspec.yaml:
dependencies:
flyme_annotation:
git:
url: https://github.com/maybewaityou/flyme_annotation.git
- add flyme_generator to pubspec.yaml:
dev_dependencies:
flyme_generator:
git:
url: https://github.com/maybewaityou/flyme_generator.git
just see the code:
import 'package:$PROJECT_NAME$/core/provider/view_model/view_model.dart';
import 'package:flyme_annotation/flyme_annotation.dart';
import 'user.dart';
part '$VIEW_MODEL_FILE_NAME$.g.dart';
@Properties([
Property(name: "name", type: "String", initial: ""),
Property(name: "age", type: "num", initial: "-1"),
Property(
name: "user",
type: "User",
initial: '''User(name: "", age: -1, email: "")'''),
Property(name: "foo", type: "String"),
Property(name: "boo", type: "String", initial: "Welcome"),
])
class TestModel extends _ViewModelProxy {
String test = 'Hello Test';
@override
void init() {
print("==== Test init ====");
}
}
run build command:
flutter packages pub run build_runner build
.g.dart
file is generated after run the command.
.g.dart
// GENERATED CODE - DO NOT MODIFY BY HAND
part of '$VIEW_MODEL_FILE_NAME$.dart';
// **************************************************************************
// ViewModelGenerator
// **************************************************************************
class _ViewModelProxy extends ViewModel {
String _name = "";
String get name => _name;
set name(String args) {
_name = args;
notifyListeners();
}
num _age = -1;
num get age => _age;
set age(num args) {
_age = args;
notifyListeners();
}
User _user = User(name: "", age: -1, email: "");
User get user => _user;
set user(User args) {
_user = args;
notifyListeners();
}
String _foo = null;
String get foo => _foo;
set foo(String args) {
_foo = args;
notifyListeners();
}
String _boo = "Welcome";
String get boo => _boo;
set boo(String args) {
_boo = args;
notifyListeners();
}
}