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

outdated

final state

stated #

final state

example #


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

    final VoidCallback increment;
    final int counter;
}

/// Counter logic
class CounterBloc extends Bloc<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) => 
        GestureDetecture(
            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: BlocBuilder<CounterState>(
                    create: (context) => CounterBloc(),
                    builder: (context, state, _) => CounterWidget(state),
                )
            )
        )
    }
}