In this example, we are going to show you how to disable the drawer hamburger icon button which appears on AppBar whenever you add a drawer to the scaffold in Flutter. Hamburger icon is appeared automatically after adding drawer to scaffold.
AppBar(
automaticallyImplyLeading: false,
)
See this also: How to Change Drawer Icon in Flutter
You have to make automaticallyImplyLeading to false to disable the automatic icon on the leading of AppBar. The automatic icons like drwaer icons, back button will be disabled using this code.
After, disabling the drawer hamburger icon button, you may need to open or close the drawer programmatically, see the example below to learn how to do it.
See: How to Open or Close Drawer Programmatically in Flutter
import 'package:flutter/material.dart';
void main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget{
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Home(),
);
}
}
class Home extends StatefulWidget{
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
final scaffoldKey = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return Scaffold(
key: scaffoldKey,
appBar: AppBar(
title: Text("My AppBar"),
automaticallyImplyLeading: false,
),
drawer: Drawer(),
body: Container(
child: ElevatedButton(
onPressed: (){
//open or close drawer manually
if(scaffoldKey.currentState!.isDrawerOpen){
scaffoldKey.currentState!.closeDrawer();
//close drawer, if drawer is open
}else{
scaffoldKey.currentState!.openDrawer();
//open drawer, if drawer is closed
}
},
child: Text("Open/Close Drawer"),
)
)
);
}
}
In this way, you can disable the drawer hamburger icon button in Flutter.
Please Wait...
No any Comments on this Article