Skip to content

Leading in AppBar won't open drawer after I change Leading to an image #21238

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

Closed
nihao123 opened this issue Aug 30, 2018 · 7 comments
Closed

Comments

@nihao123
Copy link

nihao123 commented Aug 30, 2018

I want to change leading icon in AppBar to an image (user profile image). But after I change it, this leading image counldn't open drawer.

Here is my code:

    leading: new Container(
      child: new Image.asset("assets/img/head.png"),
      padding: new EdgeInsets.all(7.0),
    ),

I have no idea how to solve this problem.

So please help me.

@nihao123 nihao123 changed the title Leading in AppBar won't drawer after I change Leading to an image Leading in AppBar won't open drawer after I change Leading to an image Aug 30, 2018
@zoechi
Copy link
Contributor

zoechi commented Aug 31, 2018

Please consider asking support questions in one of the channels http://flutter.io/support .

@zoechi
Copy link
Contributor

zoechi commented Aug 31, 2018

Can you provide a reduced reproduction (content of main.dart as a running example with everything not required to reduce the problem removed)?

@zoechi zoechi added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Aug 31, 2018
@sir-boformer
Copy link
Contributor

Well the leading widget does not automatically open the drawer. You have to create some kind of button or InkWell with a tap listener:

leading: Builder(builder: (BuildContext context) {
  return IconButton(
    icon: Icon(Icons.android),
    onPressed: () {
      Scaffold.of(context).openDrawer();
    },
  );
}),

@nihao123
Copy link
Author

nihao123 commented Aug 31, 2018

@sir-boformer Thanks, it does help. My final code works and it looks this:

leading: Builder(builder: (BuildContext context) {
      return new GestureDetector(
        onTap: (){
          Scaffold.of(context).openDrawer();
        },
        child: new Container(`
          child: new Image.asset("assets/img/head.png"),
          padding: new EdgeInsets.all(7.0),
        ),
      );
    }),

@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 Aug 31, 2018
@Allan-Nava
Copy link

@sir-boformer Thanks, it does help. My final code works and it looks this:

leading: Builder(builder: (BuildContext context) {
      return new GestureDetector(
        onTap: (){
          Scaffold.of(context).openDrawer();
        },
        child: new Container(`
          child: new Image.asset("assets/img/head.png"),
          padding: new EdgeInsets.all(7.0),
        ),
      );
    }),

Thanks, it works!

@okareshaba
Copy link

leading: Builder(builder: (context){ return InkWell(child: Image.asset("images/menu.png"), onTap: (){ Scaffold.of(context).openDrawer(); },); }), elevation: defaultTargetPlatform == TargetPlatform.android ? 5.0 : 0.0,

@github-actions
Copy link

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 Aug 22, 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

5 participants