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
class MyHomePage extends StatelessWidget { | |
final _counter = new ValueNotifier(0); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("ValueListenableBuilder example"), | |
), | |
body: CounterListenableProvider( |
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
class CounterText extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return ValueListenableBuilder<int>( | |
valueListenable: CounterListenableProvider.of(context), | |
builder: (context, value, child) { | |
return new Text(value.toString()); | |
}); | |
} |
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
static ValueListenable<int> of(BuildContext context) { | |
return (context.inheritFromWidgetOfExactType(CounterListenableProvider) | |
as CounterListenableProvider) | |
.counter; | |
} |
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
class CounterListenableProvider extends InheritedWidget { | |
final ValueListenable<int> counter; | |
CounterListenableProvider({Key key, @required this.counter, Widget child}) | |
: super(key: key, child: child); | |
@override | |
bool updateShouldNotify(InheritedWidget oldWidget) { | |
return true; | |
} |
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
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("ValueListenableBuilder example"), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ |
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
class MyHomePage extends StatelessWidget { | |
final _counter = new ValueNotifier<int>(0); | |
} |
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
class CounterText extends StatelessWidget { | |
final ValueListenable<int> _counter; | |
CounterText(this._counter); | |
@override | |
Widget build(BuildContext context) { | |
return ValueListenableBuilder<int>( | |
valueListenable: _counter, | |
builder: (context, value, child) { |
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
class MyHomePage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("NotificationListener example"), | |
), | |
body: NotificationListener<TimeNotification>( | |
child: Timer(), | |
onNotification: (notification) { |
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
class Timer extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return FlatButton( | |
child: Text("Get time!"), | |
onPressed: () { | |
final time = DateTime.now().toIso8601String(); | |
TimeNotification(time: time)..dispatch(context); | |
}, | |
); |
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
class TimeNotification extends Notification { | |
final String time; | |
const TimeNotification({this.time}); | |
} |