Open drawer in another pages

786

Create a public drawer like this:

import 'package:flutter/widgets.dart';

class PublicDrawer extends StatefulWidget {
  PublicDrawer({Key key}) : super(key: key);

  @override
  _PublicDrawerState createState() => _PublicDrawerState();
}

class _PublicDrawerState extends State<PublicDrawer> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

and at your all other page, use scaffold to implement your drawer:

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:~~~~~~~/Widgets/drawer.dart';

class ProfilePage extends StatefulWidget {
  ProfilePage({Key key}) : super(key: key);

  @override
  _ProfilePageState createState() => _ProfilePageState();
}

class _ProfilePageState extends State<ProfilePage> {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        drawer: PublicDrawer(), <----
        body: Container(),
      ),
    );
  }
}

Share:
786
AliAzad
Author by

AliAzad

Front end and mobile app developer at Tutia Technology Services Company

Updated on December 21, 2022

Comments

  • AliAzad
    AliAzad over 1 year

    My drawer is in my main.dart file. and I want to open the drawer with another page. of course Scaffold.of(context).openDrawer(); not worked. But I have no idea.