Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Scaffold, Actions and End Drawer together?

Tags:

flutter

In Scaffold if 'actions' parameter is used it hides the 'endDrawer'. Is it possible to display both?

var tmp = new Scaffold(
  /// end drawer
    endDrawer: Container(color: Colors.red,
        child: Text('END DRAWER')),
    appBar: new AppBar(
        title: Text('Title'),
    actions: <Widget>[

      /// Cancel, Save
      Padding(
        padding: const EdgeInsets.symmetric(horizontal: 8.0),
        child: IconButton(
          icon: Icon(Icons.clear,size: 24.0,),
          onPressed: () => Navigator.pop(context), //cancelButton,
        ),
      ),
      Padding(
        padding: const EdgeInsets.symmetric(horizontal: 8.0),
        child: IconButton(
          icon: Icon(Icons.check_circle,size: 30.0,),
          onPressed: () => Navigator.pop(context),
        ),)
    ],
),
    body: new Container(color: Colors.amber,);
like image 942
Ant D Avatar asked Oct 16 '22 07:10

Ant D


1 Answers

I faced the same problem. I only used a tricky solution to solve this do the following:

1.

class _MainPageState extends State<MainPage> {
  
  final _scaffoldKey = GlobalKey<ScaffoldState>(); `

here we add (final _scaffoldKey). inside the class.

2.

return Scaffold(
  key: _scaffoldKey

here inside the scaffold assign the variable to the key

3. Add the first icon button to be icon.menu, when the icon pressed it will show the end drawer as shown bellow:

IconButton(
          icon: new Icon(Icons.menu,color: Colors.white),
          onPressed: () {
            _scaffoldKey.currentState.openEndDrawer();
          },
        ),

AND

  class _MainPageState extends State<MainPage> {
  
    final _scaffoldKey = GlobalKey<ScaffoldState>();

    @override
    Widget build(BuildContext context) {
      return Scaffold(
        key: _scaffoldKey,
        appBar: AppBar(
          actions: [
            return IconButton(
              icon: new Icon(Icons.menu, color: Colors.white),
            onPressed: () {
              _scaffoldKey.currentState.openEndDrawer();
            });
          ]
        ),
      );
    }
like image 64
Malek Tubaisaht Avatar answered Oct 21 '22 00:10

Malek Tubaisaht