Flutter - 退出App

Flutter退出App的方法一般有两种

①SystemNavigator.pop 推荐

 

onTap: () async {
              await pop();
            },
static Future<void> pop() async {
    await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
  }

 

别忘了引用

import 'package:flutter/services.dart';

 

原文参考: https://docs.flutter.io/flutter/services/SystemNavigator/pop.html

 

 

 

②exit(0)

 

onPressed: ()=> exit(0),

 

原文参考: https://docs.flutter.io/flutter/dart-io/exit.html

 

    原文作者:星期八再娶你
    原文地址: https://www.cnblogs.com/hupo376787/p/10283000.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞