jyoti pawar
jyoti pawar

Reputation: 21

If i click on device back button it should redirect to the previous page but it directly goes to the homepage of the application

Page skips while navigating through device back button.

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);
  }
}

Upvotes: 2

Views: 1194

Answers (1)

Nazmul81
Nazmul81

Reputation: 190

If you use MaterialApp() as root widget on this page as well as previous pages so pages were loading in the same Material App Space. Then back button press navigating skips between the same material apps. So recommend you to use Scaffold() as a root widget.

Upvotes: 1

Related Questions