state_bloc 0.0.4 copy "state_bloc: ^0.0.4" to clipboard
state_bloc: ^0.0.4 copied to clipboard

outdated

StateBloc help the Widget tree to rebuild again with the help of streams. You do no need to create any bloc class for managing state, just need to instantiating the **StateBloc** class with an initial value.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Center(
        child: Container(
          child: Counter(),
        ),
      ),
    );
  }
}

class Counter extends StatefulWidget {
  _CounterState createState() => _CounterState();
}

class _CounterState extends State<Counter> {
  StateBloc<int> stateBloc = StateBloc<int>(0);

  void initState() {
    stateBloc.listenToValue(listenToValue: (int value) {
      //listen to the value when changed
    });
    super.initState();
  }

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: Column(
          children: <Widget>[
            Padding(
                padding: const EdgeInsets.all(8.0),
                child: Center(
                  child: BlocBuilder<int>(
                    stateBloc: stateBloc,
                    widget: (int value) {
                      return Text("$value");
                    },
                  ),
                )),
            MaterialButton(
              color: Theme.of(context).primaryColor,
              child: Text(
                'Add',
                style: TextStyle(color: Colors.white),
              ),
              onPressed: () => stateBloc.changeState(state: (int value) {
                ++value;
                return value;
              }),
            ),
          ],
        ),
      ),
    );
  }
}
2
likes
0
pub points
0%
popularity

Publisher

verified publisherashishrawat.dev

StateBloc help the Widget tree to rebuild again with the help of streams. You do no need to create any bloc class for managing state, just need to instantiating the **StateBloc** class with an initial value.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on state_bloc