Flutter - Fix Drawer Header












1















Following this link Add a Drawer to a screen I have created a drawer.



Following is my piece of code:



// FUNCTION CONTAINING LEFT SIDE MENU ITEMS
_drawerList() {
return Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'John Doe',
),
],
),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/menu_bg.png'),
fit: BoxFit.cover,
),
),
),
ListTile(
// Some Code
),
],
),
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
// Some Code
drawer: Drawer(
child: _drawerList(),
),
// Some Code
}
}


Is there any way I can fix "DrawerHeader" so that it doesn't move with the drawer and list view.



P.S. I don't want to hold ListView. I just want to hold or fix "DrawerHeader".










share|improve this question





























    1















    Following this link Add a Drawer to a screen I have created a drawer.



    Following is my piece of code:



    // FUNCTION CONTAINING LEFT SIDE MENU ITEMS
    _drawerList() {
    return Drawer(
    child: ListView(
    padding: EdgeInsets.zero,
    children: <Widget>[
    DrawerHeader(
    child: Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: <Widget>[
    Text(
    'John Doe',
    ),
    ],
    ),
    decoration: BoxDecoration(
    image: DecorationImage(
    image: AssetImage('assets/images/menu_bg.png'),
    fit: BoxFit.cover,
    ),
    ),
    ),
    ListTile(
    // Some Code
    ),
    ],
    ),
    );
    }

    @override
    Widget build(BuildContext context) {
    return Scaffold(
    // Some Code
    drawer: Drawer(
    child: _drawerList(),
    ),
    // Some Code
    }
    }


    Is there any way I can fix "DrawerHeader" so that it doesn't move with the drawer and list view.



    P.S. I don't want to hold ListView. I just want to hold or fix "DrawerHeader".










    share|improve this question



























      1












      1








      1


      1






      Following this link Add a Drawer to a screen I have created a drawer.



      Following is my piece of code:



      // FUNCTION CONTAINING LEFT SIDE MENU ITEMS
      _drawerList() {
      return Drawer(
      child: ListView(
      padding: EdgeInsets.zero,
      children: <Widget>[
      DrawerHeader(
      child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
      Text(
      'John Doe',
      ),
      ],
      ),
      decoration: BoxDecoration(
      image: DecorationImage(
      image: AssetImage('assets/images/menu_bg.png'),
      fit: BoxFit.cover,
      ),
      ),
      ),
      ListTile(
      // Some Code
      ),
      ],
      ),
      );
      }

      @override
      Widget build(BuildContext context) {
      return Scaffold(
      // Some Code
      drawer: Drawer(
      child: _drawerList(),
      ),
      // Some Code
      }
      }


      Is there any way I can fix "DrawerHeader" so that it doesn't move with the drawer and list view.



      P.S. I don't want to hold ListView. I just want to hold or fix "DrawerHeader".










      share|improve this question
















      Following this link Add a Drawer to a screen I have created a drawer.



      Following is my piece of code:



      // FUNCTION CONTAINING LEFT SIDE MENU ITEMS
      _drawerList() {
      return Drawer(
      child: ListView(
      padding: EdgeInsets.zero,
      children: <Widget>[
      DrawerHeader(
      child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
      Text(
      'John Doe',
      ),
      ],
      ),
      decoration: BoxDecoration(
      image: DecorationImage(
      image: AssetImage('assets/images/menu_bg.png'),
      fit: BoxFit.cover,
      ),
      ),
      ),
      ListTile(
      // Some Code
      ),
      ],
      ),
      );
      }

      @override
      Widget build(BuildContext context) {
      return Scaffold(
      // Some Code
      drawer: Drawer(
      child: _drawerList(),
      ),
      // Some Code
      }
      }


      Is there any way I can fix "DrawerHeader" so that it doesn't move with the drawer and list view.



      P.S. I don't want to hold ListView. I just want to hold or fix "DrawerHeader".







      dart flutter navigation-drawer






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 7:50







      Zain SMJ

















      asked Jan 3 at 7:02









      Zain SMJZain SMJ

      308312




      308312
























          1 Answer
          1






          active

          oldest

          votes


















          2














          Yes, move it out of the ListView widget and use Column to hold both DrawerHeader and ListView.



          With items scrolling enabled



          _drawerList() {
          return Drawer(
          child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
          DrawerHeader(
          child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
          Text(
          'John Doe',
          ),
          ],
          ),
          decoration: BoxDecoration(
          image: DecorationImage(
          image: AssetImage('assets/images/menu_bg.png'),
          fit: BoxFit.cover,
          ),
          ),
          ),
          ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ],
          ),
          ],
          ),
          );
          }


          With items scrolling disabled



          _drawerList() {
          return Drawer(
          child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
          DrawerHeader(
          child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
          Text(
          'John Doe',
          ),
          ],
          ),
          decoration: BoxDecoration(
          image: DecorationImage(
          image: AssetImage('assets/images/menu_bg.png'),
          fit: BoxFit.cover,
          ),
          ),
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ],
          ),
          );
          }





          share|improve this answer


























          • I dont want to hold ListView. I just want to hold "DrawerHeader"

            – Zain SMJ
            Jan 3 at 7:48











          • Why not holding the ListView? Maybe you will have many ListTiles and they wont be visible on smaller device...

            – Spectarion
            Jan 3 at 7:54











          • Exception has occurred. FlutterError (Cannot hit test a render box with no size.

            – Zain SMJ
            Jan 3 at 10:19











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017713%2fflutter-fix-drawer-header%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          Yes, move it out of the ListView widget and use Column to hold both DrawerHeader and ListView.



          With items scrolling enabled



          _drawerList() {
          return Drawer(
          child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
          DrawerHeader(
          child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
          Text(
          'John Doe',
          ),
          ],
          ),
          decoration: BoxDecoration(
          image: DecorationImage(
          image: AssetImage('assets/images/menu_bg.png'),
          fit: BoxFit.cover,
          ),
          ),
          ),
          ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ],
          ),
          ],
          ),
          );
          }


          With items scrolling disabled



          _drawerList() {
          return Drawer(
          child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
          DrawerHeader(
          child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
          Text(
          'John Doe',
          ),
          ],
          ),
          decoration: BoxDecoration(
          image: DecorationImage(
          image: AssetImage('assets/images/menu_bg.png'),
          fit: BoxFit.cover,
          ),
          ),
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ],
          ),
          );
          }





          share|improve this answer


























          • I dont want to hold ListView. I just want to hold "DrawerHeader"

            – Zain SMJ
            Jan 3 at 7:48











          • Why not holding the ListView? Maybe you will have many ListTiles and they wont be visible on smaller device...

            – Spectarion
            Jan 3 at 7:54











          • Exception has occurred. FlutterError (Cannot hit test a render box with no size.

            – Zain SMJ
            Jan 3 at 10:19
















          2














          Yes, move it out of the ListView widget and use Column to hold both DrawerHeader and ListView.



          With items scrolling enabled



          _drawerList() {
          return Drawer(
          child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
          DrawerHeader(
          child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
          Text(
          'John Doe',
          ),
          ],
          ),
          decoration: BoxDecoration(
          image: DecorationImage(
          image: AssetImage('assets/images/menu_bg.png'),
          fit: BoxFit.cover,
          ),
          ),
          ),
          ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ],
          ),
          ],
          ),
          );
          }


          With items scrolling disabled



          _drawerList() {
          return Drawer(
          child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
          DrawerHeader(
          child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
          Text(
          'John Doe',
          ),
          ],
          ),
          decoration: BoxDecoration(
          image: DecorationImage(
          image: AssetImage('assets/images/menu_bg.png'),
          fit: BoxFit.cover,
          ),
          ),
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ],
          ),
          );
          }





          share|improve this answer


























          • I dont want to hold ListView. I just want to hold "DrawerHeader"

            – Zain SMJ
            Jan 3 at 7:48











          • Why not holding the ListView? Maybe you will have many ListTiles and they wont be visible on smaller device...

            – Spectarion
            Jan 3 at 7:54











          • Exception has occurred. FlutterError (Cannot hit test a render box with no size.

            – Zain SMJ
            Jan 3 at 10:19














          2












          2








          2







          Yes, move it out of the ListView widget and use Column to hold both DrawerHeader and ListView.



          With items scrolling enabled



          _drawerList() {
          return Drawer(
          child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
          DrawerHeader(
          child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
          Text(
          'John Doe',
          ),
          ],
          ),
          decoration: BoxDecoration(
          image: DecorationImage(
          image: AssetImage('assets/images/menu_bg.png'),
          fit: BoxFit.cover,
          ),
          ),
          ),
          ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ],
          ),
          ],
          ),
          );
          }


          With items scrolling disabled



          _drawerList() {
          return Drawer(
          child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
          DrawerHeader(
          child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
          Text(
          'John Doe',
          ),
          ],
          ),
          decoration: BoxDecoration(
          image: DecorationImage(
          image: AssetImage('assets/images/menu_bg.png'),
          fit: BoxFit.cover,
          ),
          ),
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ],
          ),
          );
          }





          share|improve this answer















          Yes, move it out of the ListView widget and use Column to hold both DrawerHeader and ListView.



          With items scrolling enabled



          _drawerList() {
          return Drawer(
          child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
          DrawerHeader(
          child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
          Text(
          'John Doe',
          ),
          ],
          ),
          decoration: BoxDecoration(
          image: DecorationImage(
          image: AssetImage('assets/images/menu_bg.png'),
          fit: BoxFit.cover,
          ),
          ),
          ),
          ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ],
          ),
          ],
          ),
          );
          }


          With items scrolling disabled



          _drawerList() {
          return Drawer(
          child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
          DrawerHeader(
          child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
          Text(
          'John Doe',
          ),
          ],
          ),
          decoration: BoxDecoration(
          image: DecorationImage(
          image: AssetImage('assets/images/menu_bg.png'),
          fit: BoxFit.cover,
          ),
          ),
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ListTile(
          // Some Code
          ),
          ],
          ),
          );
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 3 at 7:55

























          answered Jan 3 at 7:16









          SpectarionSpectarion

          1,1442619




          1,1442619













          • I dont want to hold ListView. I just want to hold "DrawerHeader"

            – Zain SMJ
            Jan 3 at 7:48











          • Why not holding the ListView? Maybe you will have many ListTiles and they wont be visible on smaller device...

            – Spectarion
            Jan 3 at 7:54











          • Exception has occurred. FlutterError (Cannot hit test a render box with no size.

            – Zain SMJ
            Jan 3 at 10:19



















          • I dont want to hold ListView. I just want to hold "DrawerHeader"

            – Zain SMJ
            Jan 3 at 7:48











          • Why not holding the ListView? Maybe you will have many ListTiles and they wont be visible on smaller device...

            – Spectarion
            Jan 3 at 7:54











          • Exception has occurred. FlutterError (Cannot hit test a render box with no size.

            – Zain SMJ
            Jan 3 at 10:19

















          I dont want to hold ListView. I just want to hold "DrawerHeader"

          – Zain SMJ
          Jan 3 at 7:48





          I dont want to hold ListView. I just want to hold "DrawerHeader"

          – Zain SMJ
          Jan 3 at 7:48













          Why not holding the ListView? Maybe you will have many ListTiles and they wont be visible on smaller device...

          – Spectarion
          Jan 3 at 7:54





          Why not holding the ListView? Maybe you will have many ListTiles and they wont be visible on smaller device...

          – Spectarion
          Jan 3 at 7:54













          Exception has occurred. FlutterError (Cannot hit test a render box with no size.

          – Zain SMJ
          Jan 3 at 10:19





          Exception has occurred. FlutterError (Cannot hit test a render box with no size.

          – Zain SMJ
          Jan 3 at 10:19




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54017713%2fflutter-fix-drawer-header%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas

          Can't read property showImagePicker of undefined in react native iOS