-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.dart
More file actions
63 lines (53 loc) · 1.5 KB
/
Copy pathmain.dart
File metadata and controls
63 lines (53 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import 'package:flutter/material.dart';
import 'package:working_router/working_router.dart';
import 'route_nodes.dart';
import 'responsive.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return Responsive(
builder: (context, size) {
return _DependentMaterialApp(screenSize: size);
},
);
}
}
class _DependentMaterialApp extends StatefulWidget {
final ScreenSize screenSize;
const _DependentMaterialApp({
required this.screenSize,
});
@override
State<_DependentMaterialApp> createState() => _DependentMaterialAppState();
}
class _DependentMaterialAppState extends State<_DependentMaterialApp> {
late final WorkingRouter router = WorkingRouter(
noContentWidget: const Center(child: Text('No matching route.')),
buildRouteNodes: (rootRouterKey) => buildRouteNodes(
screenSize: widget.screenSize,
rootRouterKey: rootRouterKey,
),
);
@override
void didUpdateWidget(covariant _DependentMaterialApp oldWidget) {
if (oldWidget.screenSize != widget.screenSize) {
debugPrint(
'Refreshing router for screen size change: '
'${oldWidget.screenSize} -> ${widget.screenSize}',
);
router.refresh();
}
super.didUpdateWidget(oldWidget);
}
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'working_router example',
routerConfig: router,
);
}
}