Skip to content

Commit 7402dd7

Browse files
committed
move out EndDrawer to improve performance
1 parent 2efaf5d commit 7402dd7

File tree

4 files changed

+115
-102
lines changed

4 files changed

+115
-102
lines changed

apps/librarian/lib/dashboard/pages/dashboard_page.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
44
import 'package:librarian_app/dashboard/providers/create_loan_controller.dart';
55
import 'package:librarian_app/dashboard/providers/invalidate_module.dart';
66
import 'package:librarian_app/dashboard/providers/workspace.dart';
7+
import 'package:librarian_app/dashboard/widgets/end_drawer.dart';
78
import 'package:librarian_app/modules/authentication/providers/auth_service_provider.dart';
89
import 'package:librarian_app/modules/authentication/providers/user_tray.dart';
910
import 'package:librarian_app/modules/members/details/needs_attention_page.dart';
1011
import 'package:librarian_app/dashboard/layouts/members_desktop_layout.dart';
1112
import 'package:librarian_app/modules/members/list/searchable_members_list.dart';
12-
import 'package:librarian_app/dashboard/providers/end_drawer_provider.dart';
1313
import 'package:librarian_app/dashboard/widgets/create_menu_item.dart';
1414
import 'package:librarian_app/dashboard/layouts/inventory_desktop_layout.dart';
1515
import 'package:librarian_app/modules/things/maintenance/view.dart';
@@ -232,7 +232,7 @@ class _DashboardPageState extends ConsumerState<DashboardPage> {
232232
],
233233
)
234234
: null,
235-
endDrawer: ref.watch(endDrawerProvider).drawer,
235+
endDrawer: const EndDrawer(),
236236
floatingActionButton: mobile ? menuAnchor : null,
237237
);
238238
},

apps/librarian/lib/dashboard/providers/end_drawer_provider.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ class EndDrawerController {
55
EndDrawerController(this.ref);
66

77
final Ref ref;
8-
Widget? drawer;
8+
Widget child = const SizedBox.expand();
99

10-
openEndDrawer(BuildContext context, Widget drawer) {
11-
this.drawer = drawer;
10+
openEndDrawer(BuildContext context, Widget child) {
11+
this.child = child;
1212
ref.notifyListeners();
13-
Future.delayed(const Duration(milliseconds: 500), () {
13+
Future.delayed(const Duration(milliseconds: 750), () {
1414
Scaffold.of(context).openEndDrawer();
1515
});
1616
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_riverpod/flutter_riverpod.dart';
3+
4+
import '../providers/end_drawer_provider.dart';
5+
6+
class EndDrawer extends ConsumerWidget {
7+
const EndDrawer({super.key});
8+
9+
@override
10+
Widget build(BuildContext context, WidgetRef ref) {
11+
return Drawer(
12+
width: 500,
13+
child: ref.watch(endDrawerProvider).child,
14+
);
15+
}
16+
}

apps/librarian/lib/modules/things/details/inventory/item_details/drawer.dart

Lines changed: 93 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -30,114 +30,111 @@ class _ItemDetailsDrawerState extends State<ItemDetailsDrawer> {
3030

3131
@override
3232
Widget build(BuildContext context) {
33-
return Drawer(
34-
width: 500,
35-
child: Stack(
36-
children: [
37-
Column(
38-
children: [
39-
Padding(
40-
padding: const EdgeInsets.all(16),
41-
child: Row(
42-
children: [
43-
ListenableBuilder(
44-
listenable: widget.controller,
45-
builder: (context, child) {
46-
return getIcon(widget.controller.item!);
47-
},
48-
),
49-
const SizedBox(width: 8.0),
50-
Expanded(
51-
child: Text(
52-
'#${widget.controller.item!.number}',
53-
style: Theme.of(context).textTheme.titleLarge,
54-
),
33+
return Stack(
34+
children: [
35+
Column(
36+
children: [
37+
Padding(
38+
padding: const EdgeInsets.all(16),
39+
child: Row(
40+
children: [
41+
ListenableBuilder(
42+
listenable: widget.controller,
43+
builder: (context, child) {
44+
return getIcon(widget.controller.item!);
45+
},
46+
),
47+
const SizedBox(width: 8.0),
48+
Expanded(
49+
child: Text(
50+
'#${widget.controller.item!.number}',
51+
style: Theme.of(context).textTheme.titleLarge,
5552
),
56-
MenuAnchor(
57-
controller: menuController,
58-
menuChildren: [
59-
MenuItemButton(
60-
onPressed: convert,
61-
leadingIcon: const Icon(Icons.transform),
62-
child: const Text('Convert'),
63-
),
64-
],
65-
child: IconButton.filled(
66-
onPressed: () => menuController.open(),
67-
icon: const Icon(Icons.more_vert),
53+
),
54+
MenuAnchor(
55+
controller: menuController,
56+
menuChildren: [
57+
MenuItemButton(
58+
onPressed: convert,
59+
leadingIcon: const Icon(Icons.transform),
60+
child: const Text('Convert'),
6861
),
62+
],
63+
child: IconButton.filled(
64+
onPressed: () => menuController.open(),
65+
icon: const Icon(Icons.more_vert),
6966
),
70-
],
71-
),
67+
),
68+
],
7269
),
73-
const Divider(height: 1),
74-
Expanded(
75-
child: SingleChildScrollView(
76-
child: Padding(
77-
padding: const EdgeInsets.all(16),
78-
child: Column(
79-
children: [
80-
ItemDetails(
81-
controller: widget.controller,
82-
item: widget.controller.item!,
83-
isThingHidden: widget.isHiddenLocked,
84-
),
85-
const SizedBox(height: 80),
86-
],
87-
),
70+
),
71+
const Divider(height: 1),
72+
Expanded(
73+
child: SingleChildScrollView(
74+
child: Padding(
75+
padding: const EdgeInsets.all(16),
76+
child: Column(
77+
children: [
78+
ItemDetails(
79+
controller: widget.controller,
80+
item: widget.controller.item!,
81+
isThingHidden: widget.isHiddenLocked,
82+
),
83+
const SizedBox(height: 80),
84+
],
8885
),
8986
),
9087
),
91-
],
92-
),
93-
Positioned(
94-
bottom: 0,
95-
left: 0,
96-
right: 0,
97-
child: Container(
98-
color: Theme.of(context).colorScheme.surface.withAlpha(180),
99-
child: Padding(
100-
padding: const EdgeInsets.all(16),
101-
child: Row(
102-
mainAxisAlignment: MainAxisAlignment.end,
103-
children: [
104-
ListenableBuilder(
105-
listenable: widget.controller,
106-
builder: (context, child) {
107-
if (!widget.controller.hasUnsavedChanges) {
108-
return child!;
109-
}
88+
),
89+
],
90+
),
91+
Positioned(
92+
bottom: 0,
93+
left: 0,
94+
right: 0,
95+
child: Container(
96+
color: Theme.of(context).colorScheme.surface.withAlpha(180),
97+
child: Padding(
98+
padding: const EdgeInsets.all(16),
99+
child: Row(
100+
mainAxisAlignment: MainAxisAlignment.end,
101+
children: [
102+
ListenableBuilder(
103+
listenable: widget.controller,
104+
builder: (context, child) {
105+
if (!widget.controller.hasUnsavedChanges) {
106+
return child!;
107+
}
110108

111-
return OutlinedButton(
112-
onPressed: () {
113-
widget.controller.discardChanges();
114-
},
115-
child: const Text('Discard'),
116-
);
117-
},
118-
child: OutlinedButton(
119-
onPressed: () => Navigator.of(context).pop(),
120-
child: const Text('Cancel'),
121-
),
109+
return OutlinedButton(
110+
onPressed: () {
111+
widget.controller.discardChanges();
112+
},
113+
child: const Text('Discard'),
114+
);
115+
},
116+
child: OutlinedButton(
117+
onPressed: () => Navigator.of(context).pop(),
118+
child: const Text('Cancel'),
122119
),
123-
const SizedBox(width: 8),
124-
ListenableBuilder(
125-
listenable: widget.controller,
126-
builder: (_, __) {
127-
return FilledProgressButton(
128-
onPressed: widget.controller.saveChanges,
129-
isLoading: isLoading,
130-
child: const Text('Save'),
131-
);
132-
},
133-
),
134-
],
135-
),
120+
),
121+
const SizedBox(width: 8),
122+
ListenableBuilder(
123+
listenable: widget.controller,
124+
builder: (_, __) {
125+
return FilledProgressButton(
126+
onPressed: widget.controller.saveChanges,
127+
isLoading: isLoading,
128+
child: const Text('Save'),
129+
);
130+
},
131+
),
132+
],
136133
),
137134
),
138135
),
139-
],
140-
),
136+
),
137+
],
141138
);
142139
}
143140
}

0 commit comments

Comments
 (0)