Skip to content

Instantly share code, notes, and snippets.

@fabiomsr
Created May 1, 2019 18:50
Show Gist options
  • Save fabiomsr/96fc7854dd57ff4203a9a732b3aa7592 to your computer and use it in GitHub Desktop.
Save fabiomsr/96fc7854dd57ff4203a9a732b3aa7592 to your computer and use it in GitHub Desktop.
Flutter Notifications and Values
class TimeNotification extends Notification {
final String time;
const TimeNotification({this.time});
}
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);
},
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("ValueListenableBuilder example"),
),
body: NotificationListener<TimeNotification>(
child: Timer(),
onNotification: (notification) {
print(notification.time);
}),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment