Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make the Navigation Drawer of my Flutter app transparent?

I have built a native Android App which has a transparent navigation drawer. I have been asked to build the same app using Flutter and I have gotten to the point where I would like to implement a transparent navigation drawer. How do I make the Navigation Drawer of my Flutter app transparent because I have been struggling on that end ? I have already tried

drawer: Drawer(
          child: Container(
            color: Colors.transparent,)),

The navigation drawer just remains white. I have been searching for a solution to this and cant find one. Any help would be appreciated. I have attached images of the Native App with a transparent drawer and the Flutter version with a white Navigation drawer

Native

Flutter

like image 735
Lebogang Nkosi Avatar asked Sep 28 '18 19:09

Lebogang Nkosi


People also ask

How do I make the app drawer transparent in Flutter?

The steps are as follows: Add a TextField Widget to AppBar's title property. Make a translucent appbar and let the body Widget can go behind the appbar and be visible. Style the TextField.

How do you make the navigation bar transparent in Flutter?

You can make UINavigationBar (aka AppBar in Flutter) transparent by changing two AppBar's properties, backgroundColor and elevation . The default AppBar's appearance will show solid background color with drop shadow.

How do you make a widget Flutter transparent?

You need to wrap widget with Opacity() widget and set opacity paramater with transparent value.


2 Answers

I think there's a better way of doing this without messing up the entire canvases on the app. Since you want it specifically for the drawer, try this approach.

Scaffold(
   drawer: Theme(
      data: Theme.of(context).copyWith(
       // Set the transparency here
       canvasColor: Colors.transparent, //or any other color you want. e.g Colors.blue.withOpacity(0.5)
      ),
      child: Drawer(
          // All other codes goes here. 
       )
    )
 );
like image 200
iRedia Ebikade Avatar answered Nov 08 '22 15:11

iRedia Ebikade


use the transparent color like you are currently doing but also in the drawer widget use a stack and inside it make the first widget a backdropfilter, you will need to import dart:ui. here is an example

//import this library to use the gaussian blur background
import 'dart:ui';


Scaffold(
    appBar: AppBar(
        title: Text('Title'),
    ),
    drawer: Theme(
        data: Theme.of(context).copyWith(canvasColor: Colors.transparent),
        child: sideNav()),
        body: Text('Hello Body'),
),


Drawer sideNav(){
    return Drawer(
        child: Stack(
            children: <Widget> [
                //first child be the blur background
                BackdropFilter(
                    filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0), //this is dependent on the import statment above
                    child: Container(
                        decoration: BoxDecoration(color: Color.grey.withOpacity(0.5))
                    )
                ),
                ListView(
                    padding: EdgeInsets.zero,
                    children: <Widget>[
                        DrawerHeader(
                            child: Text('Hello Drawer Title')
                        ),
                        ListTitle(
                            leading: Icon(Icons.dashboard, color: Colors.white)
                            title: "Dashboard"
                            onTap: (){

                            }
                        )
                    ]
                )
            ]
        )
    );
}
like image 38
Sanjeet Chand Avatar answered Nov 08 '22 14:11

Sanjeet Chand