Created
June 9, 2019 21:13
-
-
Save Abion47/7420032eb1715af1485872c8cbe0941f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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