new RaisedButton( textColor: Colors.black, child: new Center( child: new Text('点击传递随机数给上层Widget'), ), onPressed: () { new TestNotification(count: new Random().nextInt(100)).dispatch(key.currentContext); }, )
3.父节点使用NotificationListener进行监听子节点发出的通知,并作出响应
1 2 3 4 5 6 7 8 9
new NotificationListener( onNotification: (TestNotification n) { scaffoldStateKey.currentState.showSnackBar(new SnackBar(content: new Text('随机数:${n.count}'))); returntrue; }, child: new TestAPage( key: key, ), )