Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep hamburger icon without visible appBar flutter

I recently tried keeping a Hamburger icon for my menu slider without an AppBar or at least completely invisible. The first attempt was with a SafeArea but that emptied Scaffold. Then I tried setting the Opacity to 0.0 like shown on the code below. But it gives out the same result as SafeArea with nothing on Scaffold. Please can anyone help?

    import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => MyAppState();
}

class MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      theme: ThemeData(
        // Define the default Brightness and Colors
        brightness: Brightness.dark,
        primaryColor: Colors.lightBlue[800],
        accentColor: Colors.cyan[600],
      ),
      home: Scaffold(
          Opacity(
            opacity: 0.0,
            appBar: AppBar(),
          ),
          drawer: new Drawer(
            child: new ListView(),
          ),
          body: new Center(
              child: new Column(
            children: <Widget>[],
          ))),
    );
  }
}
like image 389
Camille Basbous Avatar asked Jan 19 '19 19:01

Camille Basbous


3 Answers

If I have understood you well, you want to display a menu button to show the Drawer without displaying any AppBar.

One option is to use a Stack for the body of the Scaffold.

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => MyAppState();
}

class MyAppState extends State<MyApp> {
  var scaffoldKey = GlobalKey<ScaffoldState>();

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      theme: ThemeData(
        // Define the default Brightness and Colors
        brightness: Brightness.dark,
        primaryColor: Colors.lightBlue[800],
        accentColor: Colors.cyan[600],
      ),
      home: Scaffold(
        key: scaffoldKey,
        drawer: new Drawer(
          child: new ListView(),
        ),
        body: Stack(
          children: <Widget>[
            new Center(
                child: new Column(
              children: <Widget>[],
            )),
            Positioned(
              left: 10,
              top: 20,
              child: IconButton(
                icon: Icon(Icons.menu),
                onPressed: () => scaffoldKey.currentState.openDrawer(),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
like image 62
chemamolins Avatar answered Oct 12 '22 00:10

chemamolins


You can make AppBar completely invisible by setting the same color and elevation = 0 screenshot here

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

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

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xFF198BAA),
      appBar: AppBar(
        backgroundColor: Color(0xFF198BAA),
        elevation: 0.0,
      ),
      drawer: Drawer(
        child: SafeArea(
          child: Padding(
            padding: const EdgeInsets.all(18.0),
            child: ListView(
              children: <Widget>[
                ListTile(
                  title: Text('Item1'),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}
like image 6
Ox. S Avatar answered Oct 12 '22 01:10

Ox. S


If I have understood your question well.

You have your own custom Menu button to open/close drawer. You don't want to use AppBar as well.

In that case you can use GlobalKey<ScaffoldState>() object to open Drawer.

import 'package:flutter/material.dart';

GlobalKey<ScaffoldState> _scaffoldState = GlobalKey<ScaffoldState>();

return Scaffold(
  key: _scaffoldState,
  drawer: DrawerView(),
  body: ThemeScreen(
    header: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        IconButton(
          icon: Icon(Icons.menu,
              color: Colors.white,
              size: 15),
          onPressed: (){
            _scaffoldState.currentState.openDrawer();
          },
        ),
      ],
    ),
  ),
);
like image 6
Rashesh Bosamiya Avatar answered Oct 12 '22 02:10

Rashesh Bosamiya