/flyme_generator

Primary LanguageDartOtherNOASSERTION

flyme_generator

Just for Flutter.

flyme_generator is a generator for flyme (framework for flutter).

Getting Started

Edit Config file

  1. add flyme_annotation to pubspec.yaml:
dependencies:
  flyme_annotation:
    git:
      url: https://github.com/maybewaityou/flyme_annotation.git
  1. add flyme_generator to pubspec.yaml:
dev_dependencies:
  flyme_generator:
    git:
      url: https://github.com/maybewaityou/flyme_generator.git

Edit ViewModel file

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 ====");
  }
}

Generate ViewModelProxy file

run build command:

flutter packages pub run build_runner build

.g.dart file is generated after run the command.

What does the .g.dart look like

.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();
  }
}