mvu_layer 0.1.1 copy "mvu_layer: ^0.1.1" to clipboard
mvu_layer: ^0.1.1 copied to clipboard

outdated

An Elm-inspired state management for leveraging benefits from the Elm architecture while still being Dart friendly.

example/main.dart

import 'package:flutter/material.dart';
import 'package:mvu_layer/mvu_layer.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MsgBuilder<HomeMessenger, HomeModel>(
          messenger: HomeMessenger('Flutter MVU Demo Home Page'),
          builder: homeBuilder),
    );
  }
}

class HomeModel {
  final String title;
  final int counter;
  HomeModel({this.title, this.counter});
  HomeModel copyWith({title, counter}) =>
      HomeModel(title: title ?? this.title, counter: counter ?? this.counter);
}

class HomeMessenger extends Messenger<HomeModel> {
  HomeMessenger(title) : super(Update(HomeModel(title: title, counter: 0)));

  void increment() =>
      modelDispatcher((model) => model.copyWith(counter: model.counter + 1));
}

Widget homeBuilder(BuildContext context, HomeMessenger messenger, HomeModel model) {
  return Scaffold(
    appBar: AppBar(
      title: Text(model.title),
    ),
    body: Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Text(
            'You have pushed the button as MVU this many times:',
          ),
          Text(
            '${model.counter}',
            style: Theme.of(context).textTheme.headline4,
          ),
        ],
      ),
    ),
    floatingActionButton: FloatingActionButton(
      onPressed: messenger.increment,
      tooltip: 'Increment',
      child: Icon(Icons.add),
    ),
  );
}
4
likes
0
pub points
52%
popularity

Publisher

unverified uploader

An Elm-inspired state management for leveraging benefits from the Elm architecture while still being Dart friendly.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

async, flutter

More

Packages that depend on mvu_layer