title: How can I stop radio stream when navigating in Flutter?
body: <p>I'm working on this flutter radio streaming app that currently works.I'm using <code>AnimatedIcons.play_pause</code> to start and stop the radio stream. Currently if I navigate to another page, the stream will keep playing. I'd like to stop the streaming (without using the pause button) when I navigate to another page. The reason is when you return back to the streaming page ... the page has reset back to the play button<code>bool isPlaying = false;</code>
   but the stream is still on and so pressing the play button will result in 2 streams playing.</p>
  
  <p>Here's the full code below:</p>
  
  <pre><code>import 'dart:async';
  import 'package:flutter_radio/flutter_radio.dart';
  
  void main() =&gt; runApp(HarvestRadio());
  
  class HarvestRadio extends StatefulWidget {
    @override
    _MyAppState createState() =&gt; _MyAppState();
  }
  
  class _MyAppState extends State&lt;HarvestRadio&gt;
      with SingleTickerProviderStateMixin {
    String url = "https://fm898.online/mystream.mp3";
  
    AnimationController _animationController;
  
    bool isPlaying = false;
  
    @override
    void initState() {
      super.initState();
      audioStart();
      _animationController =
          AnimationController(vsync: this, duration: Duration(milliseconds: 300));
    }
  
    @override
    void dispose() {
      super.dispose();
      _animationController.dispose();
    }
  
    Future&lt;void&gt; audioStart() async {
      await FlutterRadio.audioStart();
      print('Audio Start OK');
    }
  
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
          title: 'Harvest Radio Online',
          debugShowCheckedModeBanner: false,
          home: Scaffold(
            appBar: AppBar(
              title: const Text('Harvest Radio Online '),
              backgroundColor: Colors.blue,
              centerTitle: true,
            ),
            body: Container(
              color: Colors.blueGrey.shade900,
              child: Column(
                children: &lt;Widget&gt;[
                  Expanded(
                    flex: 7,
                    child: Icon(
                      Icons.radio, size: 250,
                      color: Colors.lightBlue,
                    ),
                  ),
                  Material(
                    color: Colors.blueGrey.shade900,
                    child: Center(
                      child: Ink(
                        decoration: const ShapeDecoration(
                          color: Colors.lightBlue,
                          shape: CircleBorder(),
                        ),
                        child: IconButton(
                          color: Colors.blueGrey.shade900,
                          iconSize: 67,
                          icon: AnimatedIcon(
                            icon: AnimatedIcons.play_pause,
                            progress: _animationController,
                          ),
                          onPressed: () =&gt; _handleOnPressed(),
                        ),
                      ),
                    ),
                  ),
                  SizedBox(height: 50,)
  
                ],
              ),
            ),
          ));
    }
  
    void _handleOnPressed() {
      setState(() {
        FlutterRadio.play(url: url);
        isPlaying = !isPlaying;
        isPlaying
            ? _animationController.forward()
            : _animationController.reverse();
      });
    }
  }
  </code></pre>
  
  <p>Any help is much appreciated ... Thank you!</p>