Skip to content
This repository was archived by the owner on Sep 14, 2024. It is now read-only.

Commit f02b8ee

Browse files
committed
redesign drawer
1 parent e41c15d commit f02b8ee

File tree

2 files changed

+54
-26
lines changed

2 files changed

+54
-26
lines changed

lib/src/widget/drawer.dart

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:nextcloud_cookbook_flutter/src/blocs/authentication/authenticati
55
import 'package:nextcloud_cookbook_flutter/src/screens/my_settings_screen.dart';
66
import 'package:nextcloud_cookbook_flutter/src/screens/recipe_import_screen.dart';
77
import 'package:nextcloud_cookbook_flutter/src/screens/timer_screen.dart';
8+
import 'package:nextcloud_cookbook_flutter/src/widget/drawer_item.dart';
89
import 'package:nextcloud_cookbook_flutter/src/widget/user_image.dart';
910

1011
class MainDrawer extends StatelessWidget {
@@ -16,21 +17,17 @@ class MainDrawer extends StatelessWidget {
1617
Widget build(BuildContext context) {
1718
return Drawer(
1819
child: ListView(
19-
// Important: Remove any padding from the ListView.
2020
padding: EdgeInsets.zero,
2121
children: <Widget>[
2222
DrawerHeader(
2323
decoration: BoxDecoration(
24-
color: Theme.of(context).primaryColor,
24+
color: Theme.of(context).colorScheme.primaryContainer,
2525
),
2626
child: const UserImage(),
2727
),
28-
ListTile(
29-
trailing: Icon(
30-
Icons.alarm_add_outlined,
31-
semanticLabel: translate('timer.title'),
32-
),
33-
title: Text(translate('timer.title')),
28+
DrawerItem(
29+
icon: Icons.alarm_add_outlined,
30+
title: translate('timer.title'),
3431
onTap: () {
3532
Navigator.pop(context);
3633
Navigator.push(
@@ -41,12 +38,9 @@ class MainDrawer extends StatelessWidget {
4138
);
4239
},
4340
),
44-
ListTile(
45-
trailing: Icon(
46-
Icons.cloud_download_outlined,
47-
semanticLabel: translate('categories.drawer.import'),
48-
),
49-
title: Text(translate('categories.drawer.import')),
41+
DrawerItem(
42+
icon: Icons.cloud_download_outlined,
43+
title: translate('categories.drawer.import'),
5044
onTap: () {
5145
Navigator.pop(context);
5246
Navigator.push(
@@ -57,12 +51,9 @@ class MainDrawer extends StatelessWidget {
5751
);
5852
},
5953
),
60-
ListTile(
61-
trailing: Icon(
62-
Icons.settings_outlined,
63-
semanticLabel: translate('categories.drawer.settings'),
64-
),
65-
title: Text(translate('categories.drawer.settings')),
54+
DrawerItem(
55+
icon: Icons.settings_outlined,
56+
title: translate('categories.drawer.settings'),
6657
onTap: () async {
6758
await Navigator.push(
6859
context,
@@ -72,12 +63,9 @@ class MainDrawer extends StatelessWidget {
7263
);
7364
},
7465
),
75-
ListTile(
76-
trailing: Icon(
77-
Icons.exit_to_app_outlined,
78-
semanticLabel: translate('app_bar.logout'),
79-
),
80-
title: Text(translate('app_bar.logout')),
66+
DrawerItem(
67+
icon: Icons.exit_to_app_outlined,
68+
title: translate('app_bar.logout'),
8169
onTap: () {
8270
BlocProvider.of<AuthenticationBloc>(context)
8371
.add(const LoggedOut());

lib/src/widget/drawer_item.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import 'package:flutter/material.dart';
2+
3+
class DrawerItem extends StatelessWidget {
4+
const DrawerItem({
5+
required this.title,
6+
this.icon,
7+
this.onTap,
8+
super.key,
9+
});
10+
11+
final String title;
12+
final IconData? icon;
13+
final GestureTapCallback? onTap;
14+
15+
@override
16+
Widget build(BuildContext context) {
17+
final leading = icon != null
18+
? Icon(
19+
icon,
20+
semanticLabel: title,
21+
)
22+
: null;
23+
24+
return SizedBox(
25+
height: 56,
26+
child: ListTile(
27+
style: ListTileStyle.drawer,
28+
shape: const RoundedRectangleBorder(
29+
borderRadius: BorderRadius.all(
30+
Radius.circular(28),
31+
),
32+
),
33+
splashColor: Theme.of(context).colorScheme.secondaryContainer,
34+
leading: leading,
35+
title: Text(title),
36+
onTap: onTap,
37+
),
38+
);
39+
}
40+
}

0 commit comments

Comments
 (0)