File tree 1 file changed +3
-5
lines changed
1 file changed +3
-5
lines changed Original file line number Diff line number Diff line change @@ -46,18 +46,15 @@ class _MyHomePageState extends State<MyHomePage> {
46
46
static const message = BasicMessageChannel <dynamic >('com.example.counter.basic' , JSONMessageCodec ());
47
47
static const platform = MethodChannel ('com.example.counter.toggle' );
48
48
static const stream = EventChannel ('com.example.counter.events' );
49
- bool counterEnabled = true ;
50
- late StreamSubscription _streamSubscription ;
49
+
50
+ bool counterEnabled = false ;
51
51
52
52
static Stream <int > get getCounterStream {
53
53
return stream.receiveBroadcastStream ().cast ();
54
54
}
55
55
56
56
toggleCounter () async {
57
57
final dynamic reply = await message.send ('Hello, world' );
58
- setState (() {
59
- counterEnabled = ! counterEnabled;
60
- });
61
58
try {
62
59
await platform.invokeMethod ('toggle' , reply);
63
60
} on PlatformException catch (e) {
@@ -77,6 +74,7 @@ class _MyHomePageState extends State<MyHomePage> {
77
74
StreamBuilder <int >(
78
75
stream: getCounterStream,
79
76
builder: (BuildContext context, AsyncSnapshot <int > snapshot) {
77
+ counterEnabled = snapshot.hasData;
80
78
if (snapshot.hasData) {
81
79
return Text ("Current counter: ${snapshot .data }" );
82
80
} else {
You can’t perform that action at this time.
0 commit comments