-2

I'm trying to build an app where you could open a drawer and scroll only content below DrawerHeader(). When I have DrawerHeader as a child of ListView, naturally it scrolls with the whole list. I've tried Drawer(child:Column(children: <Widget>[DrawerHeader(), ListView()])) but seems that it crashes the app.

test drawer

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      drawer: Drawer(
        child: ListView(
          children: <Widget>[
            DrawerHeader(
              child: Text('Projects related tools'),
              decoration: BoxDecoration(color: Colors.blue),
            ),
            ExpansionTile(
              title: Text('Project 1'),
              children: <Widget>[
                Text('Property 1'),
                Text('Property 2'),
              ],
            ),
          ],
        ),
      ),
      body: SafeArea(child: ListView()),
    ));
  }
}

Adam Plk
  • 38
  • 4

1 Answers1

3

Wrap your ListView with an Expanded:

Drawer(
  child: Column(
    children: <Widget>[
      DrawerHeader(
        ...
      ),
      Expanded(
        child: ListView(
          ...
      ),
    ),
  ],
 ),
),
Try
  • 3,109
  • 3
  • 11
  • 15