Below worked perfectly with me in both Android
and iOS
, I used exit(0)
from dart:io
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),
),
);
}
UPDATE Jan 2019
Preferable solution is:
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
As described here
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…