stated 1.2.9 copy "stated: ^1.2.9" to clipboard
stated: ^1.2.9 copied to clipboard

outdated

A neat set of tools aimed at making the state management easier.

stated #

A neat set of tools aimed at making the state management easier.

See: Stated, Store, ObservableList, ListenableBuilder

example #

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

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

/// ViewModel of Counter
class CounterState {
  CounterState({
    required this.counter,
    required this.increment,
  });

  final VoidCallback increment;
  final int counter;
}

/// Counter logic
class CounterBloc extends Stated<CounterState> {
  int _counter = 0;

  @override
  CounterState build() => CounterState(
        counter: _counter,
        increment: () => setState(() => _counter++),
      );
}

/// Counter presenter
class CounterWidget extends StatelessWidget {
  CounterWidget(this.state);
  final CounterState state;

  @override
  Widget build(BuildContext context) => GestureDetector(
        onTap: state.increment,
        child: Text('Counter: ${state.counter}'),
      );
}

/// Usage
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Stated',
      home: Scaffold(
        body: StatedBuilder<CounterState>(
          create: (context) => CounterBloc(),
          builder: (context, bloc, _) => CounterWidget(bloc.value),
        ),
      ),
    );
  }
}


7
likes
0
pub points
25%
popularity

Publisher

verified publisherswipelab.co

A neat set of tools aimed at making the state management easier.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on stated