【问题标题】:If i click on device back button it should redirect to the previous page but it directly goes to the homepage of the application如果我单击设备后退按钮,它应该重定向到上一页,但它直接转到应用程序的主页
【发布时间】:2020-08-28 07:47:37
【问题描述】:

通过设备后退按钮导航时页面跳过。

import 'package:flutter/material.dart';
import 'package:modal_progress_hud/modal_progress_hud.dart';

class Attendance extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return AttendanceCalendar();
  }
}

class AttendanceCalendar extends State<Attendance> {
  bool isAsync = false;

  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: _onBackButtonPressed,
      child: ModalProgressHUD(
        inAsyncCall: isAsync,
        child: Scaffold(
          appBar: AppBar(
              title: Text("Attendance");
          ),
          body: Container(),
        ),
      ),
    );
  }

  void _onBackButtonPressed() {
    Navigator.pop(context);
  }
}

【问题讨论】:

    标签: flutter flutter-layout flutter-navigation


    【解决方案1】:

    如果您使用 MaterialApp() 作为此页面以及之前页面的根小部件,则页面会在相同的 Material App Space 中加载。然后后退按钮按下导航在相同的材料应用程序之间跳过。所以建议你使用 Scaffold() 作为根部件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-16
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多