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

StateBloc helps the Widget tree to rebuild again with the help of streams.

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: StateBlocBuilder<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
40
pub points
0%
popularity

Publisher

verified publisherashishrawat.dev

StateBloc helps the Widget tree to rebuild again with the help of streams.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on state_bloc