base_mvvm 1.0.7

  • Readme
  • Changelog
  • Example
  • Installing
  • 59

flutter_mvvm #

A new Flutter package.

Getting Started #

dependencies: base_mvvm: ^1.0.5

view

  class TestPageView extends BaseView<TestViewModel> {
  @override
  Widget buildView(BuildContext context) {
    return Container(
        child: Stack(
      children: <Widget>[
        Consumer(
            builder: (context, TestViewModel testViewModel, _) => Stack(
                  children: <Widget>[
                    Center(
                      child: Text('${testViewModel.num}',style: TextStyle(fontSize: 16),),
                    ),
                    Align(
                      alignment: Alignment.bottomCenter,
                      child: GestureDetector(
                        child: Text('click to change',style: TextStyle(fontSize: 16),),
                        onTap: () {
                          testViewModel.getNum();
                        },
                      ),
                    )
                  ],
                )),
      ],
    ));
  }

  @override
  void viewInit(BuildContext context) {}

  @override
  void viewReady(BuildContext context) {
    viewModel.getNum();
  }

  @override
  TestViewModel createViewModel() {
    return TestViewModel();
  }

  @override
  Widget createLoadingPageView() {

    return null;
  }

  @override
  bool canLoading() {
    return false;
  }
}

model

class TestModel extends BaseModel {

  int num = 0;

  Observable<int> getNumber() {
    num += 1;
    return Observable.just(num).delay(Duration(seconds: 1));
  }
}

viewmodel

class TestViewModel extends BaseViewModel {

  int _num;
  TestModel _testModel;

  TestViewModel() {
    _testModel = TestModel();
  }

  void getNum() {
    excute(_testModel.getNumber(), (data)=> {
      setNum(data)
    });
  }

  setNum(int data) {
    _num = data;
    notifyListeners();
  }

  int get num => _num;
}

网络请求采用的rxdart+jsonseraziable 在model里可以直接

Observable<int> netWork() {
    return post('path',param);
  }

记住请在viewmodel里使用excute方法传入Observable 防止内存泄漏

[1.0.7] - TODO: Add release date.

  • TODO: Describe initial release. 依赖库升级到最新版本

example/README.md

example #

A new Flutter project.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  base_mvvm: ^1.0.7

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:base_mvvm/base/config/config.dart';
import 'package:base_mvvm/base/mvvm/base_model.dart';
import 'package:base_mvvm/base/mvvm/base_view.dart';
import 'package:base_mvvm/base/mvvm/base_view_model.dart';
import 'package:base_mvvm/base/network/mf_api_service.dart';
import 'package:base_mvvm/base/network/mf_dio_api.dart';
import 'package:base_mvvm/base/utils/common_util.dart';
import 'package:base_mvvm/base/widget/anim/config/anim_config.dart';
import 'package:base_mvvm/base/widget/anim/fram_aniam_layout.dart';
import 'package:base_mvvm/base/widget/anim/mf_anim_layout.dart';
import 'package:base_mvvm/base/widget/pagestate/mf_page_loading.dart';
import 'package:base_mvvm/base/widget/pagestate/mf_page_reflush.dart';
import 'package:base_mvvm/flutter_mvvm.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
26
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
59
Learn more about scoring.

We analyzed this package on Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Fix lib/base/config/config.dart. (-0.50 points)

Analysis of lib/base/config/config.dart reported 1 hint:

line 40 col 26: The declaration '_addCommon' isn't referenced.

Format lib/base/mvvm/base_model.dart.

Run flutter format to format lib/base/mvvm/base_model.dart.

Format lib/base/mvvm/base_view.dart.

Run flutter format to format lib/base/mvvm/base_view.dart.

Fix additional 9 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/base/mvvm/base_view_model.dart (Run flutter format to format lib/base/mvvm/base_view_model.dart.)
  • lib/base/network/mf_api_service.dart (Run flutter format to format lib/base/network/mf_api_service.dart.)
  • lib/base/network/mf_dio_api.dart (Run flutter format to format lib/base/network/mf_dio_api.dart.)
  • lib/base/utils/common_util.dart (Run flutter format to format lib/base/utils/common_util.dart.)
  • lib/base/widget/anim/config/anim_config.dart (Run flutter format to format lib/base/widget/anim/config/anim_config.dart.)
  • lib/base/widget/anim/fram_aniam_layout.dart (Run flutter format to format lib/base/widget/anim/fram_aniam_layout.dart.)
  • lib/base/widget/anim/mf_anim_layout.dart (Run flutter format to format lib/base/widget/anim/mf_anim_layout.dart.)
  • lib/base/widget/pagestate/mf_page_loading.dart (Run flutter format to format lib/base/widget/pagestate/mf_page_loading.dart.)
  • lib/base/widget/pagestate/mf_page_reflush.dart (Run flutter format to format lib/base/widget/pagestate/mf_page_reflush.dart.)

Maintenance issues and suggestions

Support latest dependencies. (-20 points)

The version constraint in pubspec.yaml does not support the latest published versions for 2 dependencies (provider, rxdart).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
cookie_jar ^1.0.1 1.0.1
dio ^3.0.7 3.0.8
dio_cookie_manager ^1.0.0 1.0.0
flutter 0.0.0
json_annotation ^3.0.0 3.0.1
provider ^3.2.0 3.2.0 4.0.1
rxdart ^0.22.6 0.22.6 0.23.1
Transitive dependencies
charcode 1.1.2
collection 1.14.11 1.14.12
http_parser 3.1.3
meta 1.1.8
path 1.6.4
sky_engine 0.0.99
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test