forked from larryaasen/upgrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-gorouter.dart
60 lines (50 loc) · 1.5 KB
/
main-gorouter.dart
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
// Copyright (c) 2023 Larry Aasen. All rights reserved.
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:upgrader/upgrader.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Only call clearSavedSettings() during testing to reset internal values.
await Upgrader.clearSavedSettings(); // REMOVE this for release builds
runApp(MyApp());
}
GoRouter routerConfig = GoRouter(
initialLocation: '/page2',
routes: [
GoRoute(
path: '/page1',
builder: (BuildContext context, GoRouterState state) =>
const HomeScreen('page1')),
GoRoute(
path: '/page2',
builder: (BuildContext context, GoRouterState state) =>
const HomeScreen('page2')),
],
);
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Upgrader GoRouter Example',
routerConfig: routerConfig,
builder: (context, child) {
return UpgradeAlert(
navigatorKey: routerConfig.routerDelegate.navigatorKey,
child: child ?? Text('child'),
);
},
);
}
}
class HomeScreen extends StatelessWidget {
const HomeScreen(this.title, {super.key});
final String title;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Upgrader GoRouter Example')),
body: Center(child: Text('Checking... $title')),
);
}
}