vmiso 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 69

vmiso #

VMISO State Management (View Model, Inherited Store, Observer)

Getting Started #

VMISO provides super simple state management at the potential expense of some performance.

Currently being used in a number of small to mid scale production apps with no issues.

It works on the principle of maintaining a ViewModel class. Each time that should trigger an update call notify() and all Observers will update.

Under the hood it keeps to sound flutter principles - Observer is just a wrapper around StreamBuilder. Calling notify() passes the current class into a stream to an Observer. It probably sounds more complex than it is, check out the example below:

Simple ViewModel usage #

///
/// make a change, call `notify()`
///
class ExampleViewModel extends ViewModel {
  String name;
  DateTime dateOfBirth;

  updateDateOfBirth(DateTime value) {
    dateOfBirth = value;
    notify();
  }
}

Using a getter and setter #

///
/// You can also enable the view model to update all observers using a getter and setter.
///
/// Be careful doing this as it will trigger a redraw every time the variable is set.
///
class AutomaticNotification extends ViewModel {
  String _name;

  String get name => _name;

  set name(String name) {
    _name = name;
    notify();
  }
}

Observer Example usage #

class ObserverExample extends StatelessWidget {
  final ExampleViewModel exampleViewModel;

  const ObserverExample({Key key, this.exampleViewModel}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Observer(
      viewModel: exampleViewModel,
      builder: (BuildContext context, AsyncSnapshot snapshot) {
        return Text(exampleViewModel.name); //You can just call the instance of the viewmodel or the snapshot.
      },
    );
  }
}

What about inherited store? #

The initial goal was to create a wrapper around an inherited widget that streamlined the store, but because of Dart's lack of reflection I haven't been able to product the results I was hoping for.

Instead I have created and use a live template in Android Studio to quickly generate my "AppState" widget

[1.0.0] - 2019-10-30

  • No pomp and ceremony - releasing as 1.0 as its been extremly stable for all internal use cases.
  • Added some examples
  • Improved Android Studio code completion prompt

[0.0.4] - Changing signature of observer to better represent the underlying streambuilder

[0.0.2] - Pulling out inherited model

  • Pulling out InheritedModel as its not ready for use

[0.0.1] - Hello world!

  • Initial commit, probably don't be cray and use this yet.

example/example.dart

import 'package:flutter/widgets.dart';
import 'package:vmiso/vmiso.dart';

///
/// Basic usage, make a change, call `notify()`
///
class ExampleViewModel extends ViewModel {
  String name;
  DateTime dateOfBirth;

  updateDateOfBirth(DateTime value) {
    dateOfBirth = value;
    notify();
  }
}

///
/// You can also enable the view model to update all observers using a getter and setter.
///
/// Be careful doing this as it will trigger a redraw every time the variable is set.
///
class AutomaticNotification extends ViewModel {
  String _name;

  String get name => _name;

  set name(String name) {
    _name = name;
    notify();
  }
}


///
/// Observer Example usage
///
class ObserverExample extends StatelessWidget {
  final ExampleViewModel exampleViewModel;

  const ObserverExample({Key key, this.exampleViewModel}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Observer(
      viewModel: exampleViewModel,
      builder: (BuildContext context, AsyncSnapshot snapshot) {
        return Text(exampleViewModel.name); //You can just call the instance of the viewmodel or the snapshot.
      },
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  vmiso: ^1.0.0

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:vmiso/vmiso.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
42
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
69
Learn more about scoring.

We analyzed this package on Nov 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/vmiso.dart.

Run flutter format to format lib/vmiso.dart.

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (rxdart).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
rxdart ^0.22.0 0.22.6 0.23.0-dev.1
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test