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

request getters for _drawerOpened and _endDrawerOpened in Scaffold #23630

Closed
morphiak opened this issue Oct 27, 2018 · 6 comments
Closed

request getters for _drawerOpened and _endDrawerOpened in Scaffold #23630

morphiak opened this issue Oct 27, 2018 · 6 comments

Comments

@morphiak
Copy link

morphiak commented Oct 27, 2018

So I have a use case for knowing when a drawer is open, and there are private scaffold variables that do what I need, seems a no brainer to add

  bool isDrawerOpen(){
    return _drawerOpened;
  }
  bool isEndDrawerOpen(){
    return _endDrawerOpened;
  }

or getters or whatever format is preferred.
Seems like it should be harmless and add value, but maintainer knows best.
Please consider.

@zoechi
Copy link
Contributor

zoechi commented Oct 28, 2018

Using a custom DrawerController should allow you to do that.
See for example #21272 (comment)

@zoechi zoechi added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 28, 2018
@morphiak
Copy link
Author

morphiak commented Oct 29, 2018

Thanks for that, (I also bookmarked https://flutter.io/support/)

When I put

  bool drawerOpen;

  void setDrawerOpened(bool isOpen) {
    drawerOpen = isOpen;
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      drawer: DrawerController(
          child: Drawer(
            child: Text("SS"),
          ),
          drawerCallback: setDrawerOpened,
          alignment: DrawerAlignment.start),

I get the same undesired tint screen, then drawer behavior as described above, hitting setDrawerOpen on the second swipe. (perhaps there are now two DrawerControllers?)
After a quick look at the scaffold.dart usage (line 1458), I tried

    return new Scaffold(
//      drawer: 
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: DrawerController(
          child: Drawer(
            child: Text("SS"),
          ),
          drawerCallback: setDrawerOpened,
          alignment: DrawerAlignment.start),

which has the expected drawer behavior, and hits the callback,but you can't put anything on the screen :(
Put it inside a column widget and the drawer doesn't work.
Unless I'm missing some pattern for adding controllers to widget trees, this seems broken to me.
The normal pattern would be to have the controller as a named parameter to Drawer would it not ? Not to mention simple and intuitive (as too are getters ;).

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 29, 2018
@zoechi
Copy link
Contributor

zoechi commented Oct 29, 2018

Sorry to hear.
I'm merging with #21272 then.
Make sure you upvote to raise it's priority.

@zoechi zoechi closed this as completed Oct 29, 2018
@rhymelph
Copy link

rhymelph commented Nov 8, 2018

Hi,I want to you can try this.

  bool drawerOpen;

  void setDrawerOpened(bool isOpen) {
    drawerOpen = isOpen;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      drawer: new DrawerWidget(
        callback: setDrawerOpened,
      ),
    );
  }


class DrawerWidget extends StatefulWidget {
  DrawerCallback callback;

  DrawerWidget({this.callback});

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


class _DrawerWidgetState extends State<DrawerWidget> {

  @override
  void initState() {
    widget.callback(true);
    super.initState();
  }

  @override
  void dispose() {
    widget.callback(false);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: Text("SS"),
    );
  }
}

@morphiak
Copy link
Author

For those googling in, there's now (v0.11.3) getters for isDrawerOpen and isEndDrawerOpen in scaffold.dart.
Thank you kindly :)

@github-actions
Copy link

github-actions bot commented Sep 1, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants