Flutter how to programmatically exit the app

后端 未结 7 1265
死守一世寂寞
死守一世寂寞 2020-11-27 03:28

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

相关标签:
7条回答
  • 2020-11-27 04:07

    This worked for me;

    import 'dart:io';
    
    @override
    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),
          ), 
      );
    }
    
    0 讨论(0)
提交回复
热议问题