Skip to content

Instantly share code, notes, and snippets.

@Abion47
Created June 9, 2019 21:13
Show Gist options
  • Save Abion47/7420032eb1715af1485872c8cbe0941f to your computer and use it in GitHub Desktop.
Save Abion47/7420032eb1715af1485872c8cbe0941f to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:bloc_lite/bloc_lite.dart';
import 'package:bloc_lite_flutter/bloc_lite_flutter.dart';
class ReactiveWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() => ReactiveWidgetState();
}
class ReactiveWidgetState extends State<ReactiveWidget> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return InheritedBloc(
bloc: BlocState(),
child: ReactiveWidgetChild(),
);
}
}
class ReactiveWidgetChild extends StatelessWidget {
@override
Widget build(BuildContext context) {
return BlocWidget<BlocState>.inherited(
context: context,
builder: (_, state) {
return Center(
child: Text(state.value.toString()),
);
}
);
}
}
class BlocState extends BlocController {
int _value;
BlocState() : _value = 0;
int get value => _value;
set value(int v) {
_value = v;
publishUpdate();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment