Skip to content

Commit 606f562

Browse files
author
Hans Muller
authored
Eliminated DrawerItem, use ListTile instead (flutter#8992)
1 parent 51ea62c commit 606f562

File tree

21 files changed

+774
-653
lines changed

21 files changed

+774
-653
lines changed

dev/benchmarks/complex_layout/lib/main.dart

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -577,53 +577,41 @@ class GalleryDrawer extends StatelessWidget {
577577
child: new ListView(
578578
children: <Widget>[
579579
new FancyDrawerHeader(),
580-
new DrawerItem(
581-
icon: new Icon(Icons.brightness_5),
582-
onPressed: () { _changeTheme(context, true); },
580+
new ListTile(
581+
leading: new Icon(Icons.brightness_5),
582+
title: new Text('Light'),
583+
onTap: () { _changeTheme(context, true); },
583584
selected: ComplexLayoutApp.of(context).lightTheme,
584-
child: new Row(
585-
children: <Widget>[
586-
new Expanded(child: new Text('Light')),
587-
new Radio<bool>(
588-
value: true,
589-
groupValue: ComplexLayoutApp.of(context).lightTheme,
590-
onChanged: (bool value) { _changeTheme(context, value); }
591-
)
592-
]
593-
)
585+
trailing: new Radio<bool>(
586+
value: true,
587+
groupValue: ComplexLayoutApp.of(context).lightTheme,
588+
onChanged: (bool value) { _changeTheme(context, value); }
589+
),
594590
),
595-
new DrawerItem(
596-
icon: new Icon(Icons.brightness_7),
597-
onPressed: () { _changeTheme(context, false); },
591+
new ListTile(
592+
leading: new Icon(Icons.brightness_7),
593+
title: new Text('Dark'),
594+
onTap: () { _changeTheme(context, false); },
598595
selected: !ComplexLayoutApp.of(context).lightTheme,
599-
child: new Row(
600-
children: <Widget>[
601-
new Expanded(child: new Text('Dark')),
602-
new Radio<bool>(
603-
value: false,
604-
groupValue: ComplexLayoutApp.of(context).lightTheme,
605-
onChanged: (bool value) { _changeTheme(context, value); }
606-
)
607-
]
608-
)
596+
trailing: new Radio<bool>(
597+
value: false,
598+
groupValue: ComplexLayoutApp.of(context).lightTheme,
599+
onChanged: (bool value) { _changeTheme(context, value); },
600+
),
609601
),
610602
new Divider(),
611-
new DrawerItem(
612-
icon: new Icon(Icons.hourglass_empty),
603+
new ListTile(
604+
leading: new Icon(Icons.hourglass_empty),
605+
title: new Text('Animate Slowly'),
613606
selected: timeDilation != 1.0,
614-
onPressed: () { ComplexLayoutApp.of(context).toggleAnimationSpeed(); },
615-
child: new Row(
616-
children: <Widget>[
617-
new Expanded(child: new Text('Animate Slowly')),
618-
new Checkbox(
619-
value: timeDilation != 1.0,
620-
onChanged: (bool value) { ComplexLayoutApp.of(context).toggleAnimationSpeed(); }
621-
)
622-
]
623-
)
624-
)
625-
]
626-
)
607+
onTap: () { ComplexLayoutApp.of(context).toggleAnimationSpeed(); },
608+
trailing: new Checkbox(
609+
value: timeDilation != 1.0,
610+
onChanged: (bool value) { ComplexLayoutApp.of(context).toggleAnimationSpeed(); }
611+
),
612+
),
613+
],
614+
),
627615
);
628616
}
629617
}

dev/manual_tests/card_collection.dart

Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ class CardCollectionState extends State<CardCollection> {
107107
buildFontRadioItem("Center-align text", TextAlign.center, _textAlign, _changeTextAlign, icon: Icons.format_align_center, enabled: !_editable),
108108
buildFontRadioItem("Right-align text", TextAlign.right, _textAlign, _changeTextAlign, icon: Icons.format_align_right, enabled: !_editable),
109109
new Divider(),
110-
new DrawerItem(
111-
icon: new Icon(Icons.dvr),
112-
onPressed: () { debugDumpApp(); debugDumpRenderTree(); },
113-
child: new Text('Dump App to Console'),
110+
new ListTile(
111+
leading: new Icon(Icons.dvr),
112+
onTap: () { debugDumpApp(); debugDumpRenderTree(); },
113+
title: new Text('Dump App to Console'),
114114
),
115115
],
116116
),
@@ -167,67 +167,51 @@ class CardCollectionState extends State<CardCollection> {
167167
}
168168

169169
Widget buildDrawerCheckbox(String label, bool value, void callback(), { bool enabled: true }) {
170-
return new DrawerItem(
171-
onPressed: enabled ? callback : null,
172-
child: new Row(
173-
children: <Widget>[
174-
new Expanded(child: new Text(label)),
175-
new Checkbox(
176-
value: value,
177-
onChanged: enabled ? (_) { callback(); } : null,
178-
),
179-
],
170+
return new ListTile(
171+
onTap: enabled ? callback : null,
172+
title: new Text(label),
173+
trailing: new Checkbox(
174+
value: value,
175+
onChanged: enabled ? (_) { callback(); } : null,
180176
),
181177
);
182178
}
183179

184180
Widget buildDrawerColorRadioItem(String label, MaterialColor itemValue, MaterialColor currentValue, ValueChanged<MaterialColor> onChanged, { IconData icon, bool enabled: true }) {
185-
return new DrawerItem(
186-
icon: new Icon(icon),
187-
onPressed: enabled ? () { onChanged(itemValue); } : null,
188-
child: new Row(
189-
children: <Widget>[
190-
new Expanded(child: new Text(label)),
191-
new Radio<MaterialColor>(
192-
value: itemValue,
193-
groupValue: currentValue,
194-
onChanged: enabled ? onChanged : null,
195-
),
196-
],
181+
return new ListTile(
182+
leading: new Icon(icon),
183+
title: new Text(label),
184+
onTap: enabled ? () { onChanged(itemValue); } : null,
185+
trailing: new Radio<MaterialColor>(
186+
value: itemValue,
187+
groupValue: currentValue,
188+
onChanged: enabled ? onChanged : null,
197189
),
198190
);
199191
}
200192

201193
Widget buildDrawerDirectionRadioItem(String label, DismissDirection itemValue, DismissDirection currentValue, ValueChanged<DismissDirection> onChanged, { IconData icon, bool enabled: true }) {
202-
return new DrawerItem(
203-
icon: new Icon(icon),
204-
onPressed: enabled ? () { onChanged(itemValue); } : null,
205-
child: new Row(
206-
children: <Widget>[
207-
new Expanded(child: new Text(label)),
208-
new Radio<DismissDirection>(
209-
value: itemValue,
210-
groupValue: currentValue,
211-
onChanged: enabled ? onChanged : null,
212-
),
213-
],
194+
return new ListTile(
195+
leading: new Icon(icon),
196+
title: new Text(label),
197+
onTap: enabled ? () { onChanged(itemValue); } : null,
198+
trailing: new Radio<DismissDirection>(
199+
value: itemValue,
200+
groupValue: currentValue,
201+
onChanged: enabled ? onChanged : null,
214202
),
215203
);
216204
}
217205

218206
Widget buildFontRadioItem(String label, TextAlign itemValue, TextAlign currentValue, ValueChanged<TextAlign> onChanged, { IconData icon, bool enabled: true }) {
219-
return new DrawerItem(
220-
icon: new Icon(icon),
221-
onPressed: enabled ? () { onChanged(itemValue); } : null,
222-
child: new Row(
223-
children: <Widget>[
224-
new Expanded(child: new Text(label)),
225-
new Radio<TextAlign>(
226-
value: itemValue,
227-
groupValue: currentValue,
228-
onChanged: enabled ? onChanged : null,
229-
),
230-
],
207+
return new ListTile(
208+
leading: new Icon(icon),
209+
title: new Text(label),
210+
onTap: enabled ? () { onChanged(itemValue); } : null,
211+
trailing: new Radio<TextAlign>(
212+
value: itemValue,
213+
groupValue: currentValue,
214+
onChanged: enabled ? onChanged : null,
231215
),
232216
);
233217
}

dev/manual_tests/page_view.dart

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,23 @@ class PageViewAppState extends State<PageViewApp> {
8585
child: new ListView(
8686
children: <Widget>[
8787
new DrawerHeader(child: new Center(child: new Text('Options'))),
88-
new DrawerItem(
89-
icon: new Icon(Icons.more_horiz),
88+
new ListTile(
89+
leading: new Icon(Icons.more_horiz),
9090
selected: scrollDirection == Axis.horizontal,
91-
child: new Text('Horizontal Layout'),
92-
onPressed: switchScrollDirection,
91+
trailing: new Text('Horizontal Layout'),
92+
onTap: switchScrollDirection,
9393
),
94-
new DrawerItem(
95-
icon: new Icon(Icons.more_vert),
94+
new ListTile(
95+
leading: new Icon(Icons.more_vert),
9696
selected: scrollDirection == Axis.vertical,
97-
child: new Text('Vertical Layout'),
98-
onPressed: switchScrollDirection,
97+
trailing: new Text('Vertical Layout'),
98+
onTap: switchScrollDirection,
9999
),
100-
new DrawerItem(
101-
onPressed: toggleItemsWrap,
102-
child: new Row(
103-
children: <Widget>[
104-
new Expanded(child: new Text('Scrolling wraps around')),
105-
// TODO(abarth): Actually make this checkbox change this value.
106-
new Checkbox(value: itemsWrap, onChanged: null),
107-
],
108-
),
100+
new ListTile(
101+
onTap: toggleItemsWrap,
102+
title: new Text('Scrolling wraps around'),
103+
// TODO(abarth): Actually make this checkbox change this value.
104+
trailing: new Checkbox(value: itemsWrap, onChanged: null),
109105
),
110106
],
111107
),

examples/flutter_gallery/lib/demo/material/drawer_demo.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
116116
mainAxisSize: MainAxisSize.min,
117117
crossAxisAlignment: CrossAxisAlignment.stretch,
118118
children: _drawerContents.map((String id) {
119-
return new DrawerItem(
120-
icon: new CircleAvatar(child: new Text(id)),
121-
child: new Text('Drawer item $id'),
122-
onPressed: _showNotImplementedMessage,
119+
return new ListTile(
120+
leading: new CircleAvatar(child: new Text(id)),
121+
title: new Text('Drawer item $id'),
122+
onTap: _showNotImplementedMessage,
123123
);
124124
}).toList(),
125125
),
@@ -133,15 +133,15 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
133133
mainAxisSize: MainAxisSize.min,
134134
crossAxisAlignment: CrossAxisAlignment.stretch,
135135
children: <Widget>[
136-
new DrawerItem(
137-
icon: new Icon(Icons.add),
138-
child: new Text('Add account'),
139-
onPressed: _showNotImplementedMessage,
136+
new ListTile(
137+
leading: new Icon(Icons.add),
138+
title: new Text('Add account'),
139+
onTap: _showNotImplementedMessage,
140140
),
141-
new DrawerItem(
142-
icon: new Icon(Icons.settings),
143-
child: new Text('Manage accounts'),
144-
onPressed: _showNotImplementedMessage,
141+
new ListTile(
142+
leading: new Icon(Icons.settings),
143+
title: new Text('Manage accounts'),
144+
onTap: _showNotImplementedMessage,
145145
),
146146
],
147147
),

0 commit comments

Comments
 (0)