mvvm_bloc 2.2.0 copy "mvvm_bloc: ^2.2.0" to clipboard
mvvm_bloc: ^2.2.0 copied to clipboard

Flutter MVVM Architecture with BLoC Pattern

mvvm_bloc #

Flutter MVVM Architecture with BLoC Pattern

Getting Started #

ViewModel #


class MyPageViewModel extends ViewModel {
  @override
  String get name => 'my_page';

  final LifeCycleOwner? parent;

  ServiceLogic({
    Key? key,
    required Widget Function(ViewModel) builder,
    this.parent,
  }) : super(key: key, builder: builder);

  factory MyPageViewModel.build({LifeCycleOwner? parent}) {
    return MyPageViewModel(
      parent: parent,
      builder: (vm) => MyPageView(vm as MyPageViewModel),
    );
  }

  late final LiveData<int> $counter = LivaData(0).owner(this);

  increment(){
    $counter.value++;
  }

  decrement(){
    $counter.value--;
  }
}

View #

class MyPageView extends app.View<MyPageViewModel> {
  const MyPageView(
      MyPageViewModel logic, {
        Key? key,
      }) : super(logic, key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Text(
          'You have pushed the button this many times:',
        ),
        $watch(vm.$counter, builder: (_, value) {
          return Text(
            '$value',
          );
        }),
        RaisedButton(
          child: Text('+'),
          onPressed: () => vm.increment(),
        ),
        RaisedButton(
          child: Text('-'),
          onPressed: () => vm.decrement(),
        ),
      ],
    );
  }
}
5
likes
60
pub points
33%
popularity

Publisher

unverified uploader

Flutter MVVM Architecture with BLoC Pattern

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

bloc_builder, flutter, flutter_live_data, logger

More

Packages that depend on mvvm_bloc