How To Disable Or Override Back Button Using Flutter App

admin_img Posted By Bajarangi soft , Posted On 30-10-2020

Flutter - Disable/Override Back Button with WillPopScope, By default, when the user presses back either using the device's physical or soft key or using the back button on the AppBar , the application will How to hide the back arrow in the Flutter application bar and use the close button? Difficulty: Beginner This simple code removes the “back” arrow (left side of the AppBar) and sets a “close” button (right side of the AppBar).

How To Disable Or Override Back Button Using Flutter App

Disable Or Override Back Button
Complete Code For In Disable Or Override Back Button Flutter
main.dart

import 'package:flutter/material.dart';

void main(){
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.lightGreen,
        title: Text('No Back Button'),
      ),
      body: WillPopScope(
        onWillPop: () async {
          Future.value(
              false);
        },
        child: Center(
          child: Text('Back Button dont work on this Screen'),
        ),
      ),
    );
  }
}

Related Post