Skip to content

Instantly share code, notes, and snippets.

Fabio Santana fabiomsr

Block or report user

Report or block fabiomsr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View values.dart
class MyHomePage extends StatelessWidget {
final _counter = new ValueNotifier(0);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("ValueListenableBuilder example"),
),
body: CounterListenableProvider(
View values.dart
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());
});
}
View values.dart
static ValueListenable<int> of(BuildContext context) {
return (context.inheritFromWidgetOfExactType(CounterListenableProvider)
as CounterListenableProvider)
.counter;
}
View values.dart
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;
}
View values.dart
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("ValueListenableBuilder example"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
View values.dart
class MyHomePage extends StatelessWidget {
final _counter = new ValueNotifier<int>(0);
}
View values.dart
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) {
View notifications.dart
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("NotificationListener example"),
),
body: NotificationListener<TimeNotification>(
child: Timer(),
onNotification: (notification) {
View notifications.dart
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);
},
);
View notifications.dart
class TimeNotification extends Notification {
final String time;
const TimeNotification({this.time});
}
You can’t perform that action at this time.