小编典典

如何禁用手机后退功能

flutter

我是Flutter开发的新手。谁能和我分享如何禁用后按功能flutter

在Android中,我们可以使用onbackpressed方法。

@Override
public void onBackPressed() {
  // super.onBackPressed(); commented this line in order to disable back press
  //Write your code here
  Toast.makeText(getApplicationContext(), "Back press disabled!", Toast.LENGTH_SHORT).show();
}

flutter怎么可能呢?


阅读 341

收藏
2020-08-13

共1个答案

小编典典

将小部件包装在其中,WillPopScopeFutureonWillPop属性中返回false

    @override
    Widget build(BuildContext context) {
      return WillPopScope(
        onWillPop: () => Future.value(false),
        child: Scaffold(
          appBar: AppBar(
            title: const Text("Home Page"),
          ),
          body: Center(
            child: const Text("Home Page"),
          ),
        ),
      );
    }

请参阅此文档:https : //api.flutter.dev/flutter/widgets/WillPopScope-
class.html

2020-08-13