1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| class _MyHomePageState extends State<MyHomePage> {
static const netPlatform = const EventChannel('samples.flutter.io/netChanged');
var netState = true;
@override void initState() { super.initState(); netPlatform.receiveBroadcastStream().listen(_onEvent, onError: _onError); }
void _onEvent(Object event) { setState(() { netState = event; }); }
void _onError(Object error) { setState(() { netState = false; }); }
@override Widget build(BuildContext context) { return new Material( child: new Center( child: new Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ new Text('netState=' + netState.toString()), ], ), ), ); } }
|