Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explain how to open a drawer in the 'Add a drawer to a screen' page #10514

Open
1 task done
sudot opened this issue May 6, 2024 · 1 comment
Open
1 task done

Explain how to open a drawer in the 'Add a drawer to a screen' page #10514

sudot opened this issue May 6, 2024 · 1 comment
Labels
e2-days Effort: < 5 days from.page-issue Reported in a reader-filed concern t.ui.interactivity Relates to interactive Flutter apps

Comments

@sudot
Copy link
Contributor

sudot commented May 6, 2024

Page URL

https://docs.flutter.dev/cookbook/design/drawer/

Page source

https://github.com/flutter/website/tree/main/src/content/cookbook/design/drawer.md

Describe the problem

没有打开 drawer 的相关说明和代码。

Expected fix

请添加打开 drawer 相关的代码和说明。

例如:

通过编程打开 drawer

打开 drawer 有两种常用的操作方式。

第一种方式,在 Builder 中子组件的点击事件中打开 drawer

Scaffold(
  appBar: AppBar(
    leading: Builder(
      builder: (context) {
        return IconButton(
          icon: const Icon(Icons.menu),
          onPressed: () {
            Scaffold.of(context).openDrawer();
          },
        );
      },
    ),
  ),
  drawer: Drawer(),
)

第二种方式,给定一个 GlobalKey<ScaffoldState>,然后你可以使用他来打开 drawer

final GlobalKey<ScaffoldState> scaffoldStateKey = GlobalKey<ScaffoldState>();
Scaffold(
  key: scaffoldStateKey,
  appBar: AppBar(
    leading: IconButton(
      icon: const Icon(Icons.menu),
      onPressed: () {
        scaffoldStateKey.currentState?.openDrawer();
      },
    ),
  ),
  drawer: Drawer(),
)

Additional context

No response

I would like to fix this problem.

  • I will try and fix this problem on docs.flutter.dev.
@sudot sudot added the from.page-issue Reported in a reader-filed concern label May 6, 2024
@atsansone
Copy link
Contributor

Rough translation

Describe the problem

There are no instructions or codes for opening the drawer.

Expected fix

Please add the code and instructions related to opening the drawer.

For example: Open drawer programmatically.
There are two common operations for opening the drawer.

The first way is to open the drawer in the click event of the subcomponent in the Builder.

The second way, given a GlobalKey<ScaffoldState>, then you can use it to open the drawer.

@atsansone atsansone added p2-medium Necessary but not urgent concern. Resolve when possible. e2-days Effort: < 5 days t.ui.interactivity Relates to interactive Flutter apps labels May 6, 2024
@atsansone atsansone changed the title [PAGE ISSUE]: 'Add a drawer to a screen' Explain how to open a drawer in the 'Add a drawer to a screen' page May 6, 2024
@sfshaza2 sfshaza2 removed the p2-medium Necessary but not urgent concern. Resolve when possible. label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2-days Effort: < 5 days from.page-issue Reported in a reader-filed concern t.ui.interactivity Relates to interactive Flutter apps
Projects
None yet
Development

No branches or pull requests

3 participants