我试图构建一个应用程序,在这个应用程序中,你可以打开一个抽屉,只滚动DrawerHeader()下面的内容。当我把DrawerHeader作为ListView的一个子程序时,自然而然地,它就会随着整个列表滚动。我试过 Drawer(child:Column(children: <Widget>[DrawerHeader(), ListView()]))
但似乎它崩溃的应用程序。
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()),
));
}
}
用一个Expanded.Wrap你的ListView。
Drawer(
child: Column(
children: <Widget>[
DrawerHeader(
...
),
Expanded(
child: ListView(
...
),
),
],
),
),