shiburagi / Drawer-Behavior-Flutter

Drawer behavior is a library that provide an extra behavior on drawer, such as, move view or scaling view's height while drawer on slide.
MIT License
209 stars 36 forks source link

Initial page with menu and page sharing the screen #21

Closed RickZzDev closed 3 years ago

RickZzDev commented 4 years ago

Hello, i am trying to use this beautiful layout, but when i open the app, it comes with the drawer opened can u please help me

Here is the code

class _DrawerScaleIconState extends State { int selectedMenuItemId; final GlobalKey _scaffoldKey = new GlobalKey(); DrawerScaffoldController controller = DrawerScaffoldController(open: Direction.left);

@override void initState() { selectedMenuItemId = menuWithIcon.items[0].id; // controller.toggle(); super.initState(); }

@override Widget build(BuildContext context) { Home homeScreen = Home(context); Profile profileScreen = Profile(context); Help helpScreen = Help(context);

List<Widget> widgets = [
  homeScreen,
  profileScreen,
  Container(color: Colors.blue),
  Container(color: Colors.yellow),
  helpScreen
];

DrawerScaffoldController controller =
    DrawerScaffoldController(open: Direction.left);
return DrawerScaffold(
  controller: controller,
  appBar: AppBar(
    centerTitle: true,
    title: Column(
      children: <Widget>[
        SizedBox(
          height: 12,
        ),
        Container(
          width: 150.0,
          height: 150.0,
          decoration: BoxDecoration(
            shape: BoxShape.rectangle,
            image: DecorationImage(
                fit: BoxFit.contain,
                image:
                    CachedNetworkImageProvider(Singleton().teamImageURL)),
          ),
        ),
        SizedBox(
          height: 8,
        )
      ],
    ),
    elevation: 0,
    automaticallyImplyLeading: false,
    leading: IconButton(
      icon: SizedBox(
        height: 24,
        width: 24,
        child: Image.asset(
          'assets/icon_menu.png',
          fit: BoxFit.fill,
        ),
      ), // set your color here
      onPressed: () {
        controller.openDrawer();
      },
    ),
    backgroundColor: Colors.white,
    actions: null,
  ),
  drawers: [
    SideDrawer(
      percentage: 0.9,
      degree: 0.8,
      selectorColor: Colors.white,
      padding: EdgeInsets.fromLTRB(24, 15, 12, 15),
      textStyle: TextStyle(
          color: Colors.white70, fontWeight: FontWeight.bold, fontSize: 16),
      menu: menuWithIcon,
      animation: true,
      color: Singleton().secondaryColor,
      selectedItemId: selectedMenuItemId,
      onMenuItemSelected: (itemId) {
        setState(() {
          selectedMenuItemId = itemId;
        });
      },
    )
  ],
  key: _scaffoldKey,
  builder: (context, id) => IndexedStack(
    index: id,
    children: menu.items.map((e) => widgets[selectedMenuItemId]).toList(),
  ),
);
shiburagi commented 4 years ago

replace

DrawerScaffoldController controller =
    DrawerScaffoldController(open: Direction.left);

to

DrawerScaffoldController controller =
    DrawerScaffoldController();