Skip to content

Commit 2c9066f

Browse files
authored
Merge pull request ryanheise#77 from rohansohonee/master
fix for memory leak
2 parents d2ba180 + a277c89 commit 2c9066f

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

example/lib/main.dart

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -69,38 +69,44 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
6969
@override
7070
Widget build(BuildContext context) {
7171
return new MaterialApp(
72-
home: new Scaffold(
73-
appBar: new AppBar(
74-
title: const Text('Audio Service Demo'),
75-
),
76-
body: new Center(
77-
child: StreamBuilder(
78-
stream: AudioService.playbackStateStream,
79-
builder: (context, snapshot) {
80-
PlaybackState state = snapshot.data;
81-
return Row(
82-
mainAxisAlignment: MainAxisAlignment.center,
83-
children: [
84-
if (state?.basicState == BasicPlaybackState.connecting) ...[
85-
stopButton(),
86-
Text("Connecting..."),
87-
] else
88-
if (state?.basicState == BasicPlaybackState.playing) ...[
72+
home: WillPopScope(
73+
onWillPop: () {
74+
disconnect();
75+
return Future.value(true);
76+
},
77+
child: new Scaffold(
78+
appBar: new AppBar(
79+
title: const Text('Audio Service Demo'),
80+
),
81+
body: new Center(
82+
child: StreamBuilder(
83+
stream: AudioService.playbackStateStream,
84+
builder: (context, snapshot) {
85+
PlaybackState state = snapshot.data;
86+
return Row(
87+
mainAxisAlignment: MainAxisAlignment.center,
88+
children: [
89+
if (state?.basicState == BasicPlaybackState.connecting) ...[
90+
stopButton(),
91+
Text("Connecting..."),
92+
] else if (state?.basicState ==
93+
BasicPlaybackState.playing) ...[
8994
pauseButton(),
9095
stopButton(),
9196
positionIndicator(state),
92-
] else
93-
if (state?.basicState == BasicPlaybackState.paused) ...[
94-
playButton(),
95-
stopButton(),
96-
positionIndicator(state),
97-
] else ...[
98-
audioPlayerButton(),
99-
textToSpeechButton(),
100-
],
101-
],
102-
);
103-
},
97+
] else if (state?.basicState ==
98+
BasicPlaybackState.paused) ...[
99+
playButton(),
100+
stopButton(),
101+
positionIndicator(state),
102+
] else ...[
103+
audioPlayerButton(),
104+
textToSpeechButton(),
105+
],
106+
],
107+
);
108+
},
109+
),
104110
),
105111
),
106112
),

0 commit comments

Comments
 (0)