Skip to content

Commit e950006

Browse files
committed
set counterEnabled to snapshot.hasData
1 parent c037347 commit e950006

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Examples/counter/lib/main.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,15 @@ class _MyHomePageState extends State<MyHomePage> {
4646
static const message = BasicMessageChannel<dynamic>('com.example.counter.basic', JSONMessageCodec());
4747
static const platform = MethodChannel('com.example.counter.toggle');
4848
static const stream = EventChannel('com.example.counter.events');
49-
bool counterEnabled = true;
50-
late StreamSubscription _streamSubscription;
49+
50+
bool counterEnabled = false;
5151

5252
static Stream<int> get getCounterStream {
5353
return stream.receiveBroadcastStream().cast();
5454
}
5555

5656
toggleCounter() async {
5757
final dynamic reply = await message.send('Hello, world');
58-
setState(() {
59-
counterEnabled = !counterEnabled;
60-
});
6158
try {
6259
await platform.invokeMethod('toggle', reply);
6360
} on PlatformException catch (e) {
@@ -77,6 +74,7 @@ class _MyHomePageState extends State<MyHomePage> {
7774
StreamBuilder<int>(
7875
stream: getCounterStream,
7976
builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
77+
counterEnabled = snapshot.hasData;
8078
if(snapshot.hasData) {
8179
return Text("Current counter: ${snapshot.data}");
8280
} else {

0 commit comments

Comments
 (0)