Flutter programmatically closing the app

4925    1 year ago

how can I programmatically close a Flutter application. I've tried popping the only 'screen' but that results in a black screen.

Thanks in advance.

Answers { 2 }
1 year ago

Below worked perfectly with me in both Android and iOS, I used exit(0) from dart:io

import 'dart:io';

  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      body: new ... (...),
          floatingActionButton: new FloatingActionButton(
            onPressed: ()=> exit(0),
            tooltip: 'Close app',
            child: new Icon(Icons.close),

UPDATE Jan 2019 Preferable solution is:


As described here

1 year ago

You can do this with SystemNavigator.pop().