Flutter Drawer:是否可以只滚动抽屉的一部分?
Flutter Drawer: Is it possible to scroll only part of the drawer?
我正在尝试构建一个应用程序,您可以在其中打开抽屉并仅滚动 DrawerHeader() 下方的内容。当我将 DrawerHeader 作为 ListView 的子项时,它自然会与整个列表一起滚动。我试过了
Drawer(child:Column(children: <Widget>[DrawerHeader(), ListView()]))
但似乎它使应用程序崩溃了。
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()),
));
}
}
用 Expanded 包装您的 ListView:
Drawer(
child: Column(
children: <Widget>[
DrawerHeader(
...
),
Expanded(
child: ListView(
...
),
),
],
),
),
我正在尝试构建一个应用程序,您可以在其中打开抽屉并仅滚动 DrawerHeader() 下方的内容。当我将 DrawerHeader 作为 ListView 的子项时,它自然会与整个列表一起滚动。我试过了
Drawer(child:Column(children: <Widget>[DrawerHeader(), ListView()]))
但似乎它使应用程序崩溃了。
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()),
));
}
}
用 Expanded 包装您的 ListView:
Drawer(
child: Column(
children: <Widget>[
DrawerHeader(
...
),
Expanded(
child: ListView(
...
),
),
],
),
),