flowr 6.0.3 copy "flowr: ^6.0.3" to clipboard
flowr: ^6.0.3 copied to clipboard

FlowR: state management package for the MVVM pattern based on reactive programming.

example/main.dart

import 'package:flowr/flowr_mvvm.dart';
import 'package:flutter/material.dart';

class CounterModel {
  final int value;

  const CounterModel(this.value);

  CounterModel copyWith({int? value}) => CounterModel(value ?? this.value);

  @override
  String toString() => 'CounterModel(value: $value)';
}

class CounterViewModel extends FrViewModel<CounterModel> {
  CounterViewModel() : super(const CounterModel(0));

  void increment() => update(
    (old) => old.copyWith(value: old.value + 1),
    logging: (previous, current) => '$previous -> $current',
  );
}

void main() {
  runApp(
    FrProvider(
      (_) => CounterViewModel(),
      child: const MaterialApp(home: CounterPage()),
    ),
  );
}

class CounterPage extends StatelessWidget {
  const CounterPage({super.key});

  @override
  Widget build(BuildContext context) {
    final counter = context.read<CounterViewModel>();

    return Scaffold(
      appBar: AppBar(title: const Text('FlowR counter')),
      body: Center(
        child: FrView<CounterViewModel, CounterModel>(
          builder: (_, snap, _) => Text('Count: ${snap.data.value}'),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: counter.increment,
        child: const Icon(Icons.add),
      ),
    );
  }
}
2
likes
160
points
662
downloads

Documentation

API reference

Publisher

verified publisherwyattcoder.top

Weekly Downloads

FlowR: state management package for the MVVM pattern based on reactive programming.

Repository (GitHub)
View/report issues

Topics

#flowr #state-management #bloc #mvvm

License

MIT (license)

Dependencies

async, bloc, flowr_dart, flutter, flutter_bloc, get_it, injectable, provider, stack_trace

More

Packages that depend on flowr