view_model 0.2.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 0

view_model

Support MVVM Pattern

Example usages

Installing

Use:

$ cd example/
$ flutter packages pub run build_runner build

For generation ''main.reflectable.dart''

Getting Started

For help getting started with Flutter, view our online documentation.

For help on editing package code, view the documentation.

0.2.1

  • Static provide viewModel

0.2.0

  • Global refactor code, use of reflection to create ViewModel

0.1.2

  • Added example project
  • Refactor ViewModelProvider
  • Deleting Page and PageState
  • Added method ViewModel.newInheritedWidget

0.1.1

  • Initial Release.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:view_model/view_model.dart';
import 'main.reflectable.dart';

void main() {
  initializeReflectable();
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  HomeViewModel viewModel;

  @override
  Widget build(BuildContext context) {
    viewModel = ViewModelProvider.provide(HomeViewModel);
//    var factory = MyViewModelFactory(data: 'Test');
//    viewModel = ViewModelProvider().provide(HomeViewModel, factory: factory);
    return Scaffold(
      appBar: AppBar(
        title: Text('ViewModel test'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            StreamBuilder(
              stream: viewModel.clickStream,
              builder: (context, snapshot) =>
                  Text(snapshot.hasData ? '${snapshot.data}' : '0'),
            )
          ],
        ),
      ),
      floatingActionButton: ViewModelInherited(
          viewModel: viewModel,
          child: MyWidget()),
    );
  }

  @override
  void dispose() {
    viewModel.dispose();
    super.dispose();
  }
}

class MyWidget extends StatefulWidget {
  @override
  _MyWidgetState createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  HomeViewModel viewModel;

  @override
  Widget build(BuildContext context) {
    viewModel = ViewModel.of<HomeViewModel>(context);
    return FloatingActionButton(
      onPressed: () {
        viewModel.increment();
      },
      tooltip: 'Increment',
      child: new Icon(Icons.add),
    );
  }
}

@view_model
class HomeViewModel extends ViewModel {
  StreamController<int> _clickStreamController;
  Stream<int> clickStream;
  String data;

  HomeViewModel({this.data}) {
    _clickStreamController = new StreamController<int>.broadcast();
    var counter = 0;
    clickStream = _clickStreamController.stream.map((val) {
      counter += val;
      return counter;
    });
  }

  void increment() {
    print('======== $data ========');
    _clickStreamController.add(1);
  }

  @override
  void dispose() {
    // implement dispose
    super.dispose();
  }
}

//Use the factory if you need to transfer data to the constructor
class MyViewModelFactory extends ViewModelFactory {
  String data;

  MyViewModelFactory({this.data});

  @override
  T crateViewModel<T extends ViewModel>(Type type) {
    var vm;
    switch (type) {
      case HomeViewModel:
        vm = HomeViewModel(data: data);
        break;
    }
    if (vm == null) throw Exception('Not implemented class $type');
    return vm;
  }

}

Use this package as a library

1. Depend on it

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


dependencies:
  view_model: ^0.2.1

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:view_model/view_model.dart';
  
Version Uploaded Documentation Archive
0.2.1 Jul 30, 2018 Go to the documentation of view_model 0.2.1 Download view_model 0.2.1 archive
0.2.0 Jul 29, 2018 Go to the documentation of view_model 0.2.0 Download view_model 0.2.0 archive
0.1.2 Jul 29, 2018 Go to the documentation of view_model 0.1.2 Download view_model 0.1.2 archive
0.1.1 Jul 27, 2018 Go to the documentation of view_model 0.1.1 Download view_model 0.1.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
0
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Health issues and suggestions

Document public APIs (-9.38 points)

15 out of 16 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

Maintenance issues and suggestions

Add SDK constraint in pubspec.yaml. (-50 points)

For information about setting SDK constraint, please see https://www.dartlang.org/tools/pub/pubspec#sdk-constraints.

Homepage does not exists. (-20 points)

We were unable to access https://github.com/Miolin/view_model at the time of the analysis.

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
flutter 0.0.0
reflectable >=2.0.2 <3.0.0 2.0.8
Transitive dependencies
analyzer 0.33.6 0.34.0
args 1.5.1
async 2.0.8
build 1.0.1
build_config 0.3.1+4
build_resolvers 0.2.2+6
build_runner 1.1.2
build_runner_core 1.1.1
built_collection 4.1.0
built_value 6.1.6
charcode 1.1.2
code_builder 3.1.3
collection 1.14.11
convert 2.0.2
crypto 2.0.6
csslib 0.14.6
dart_style 1.2.0 1.2.1
fixnum 0.10.9
front_end 0.1.6+8 0.1.7
glob 1.1.7
graphs 0.1.3+1
html 0.13.3+3
http 0.12.0
http_multi_server 2.0.5
http_parser 3.1.3
io 0.3.3
js 0.6.1+1
json_annotation 2.0.0
kernel 0.3.6+8 0.3.7
logging 0.11.3+2
matcher 0.12.4
meta 1.1.6
mime 0.9.6+2
package_config 1.0.5
package_resolver 1.0.6
path 1.6.2
pedantic 1.3.0
plugin 0.2.0+3
pool 1.3.6
pub_semver 1.4.2
pubspec_parse 0.1.2+3
quiver 2.0.1
shelf 0.7.3+3
shelf_web_socket 0.2.2+4
sky_engine 0.0.99
source_span 1.4.1
stack_trace 1.9.3
stream_channel 1.6.8
stream_transform 0.0.14+1
string_scanner 1.0.4
timing 0.1.1+1
typed_data 1.1.6
utf 0.9.0+5
vector_math 2.0.8
watcher 0.9.7+10
web_socket_channel 1.0.9
yaml 2.1.15
Dev dependencies
flutter_test