This repository has been archived by the owner on Feb 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathwidgets_app.dart
112 lines (99 loc) · 2.79 KB
/
widgets_app.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
void main() => runApp(App());
const blue = Color(0xFF2196F3);
const white = Color(0xFFFFFFFF);
class App extends StatelessWidget {
App({Key? key}) : super(key: key);
static const title = 'GoRouter Example: WidgetsApp';
@override
Widget build(BuildContext context) => WidgetsApp.router(
routeInformationParser: _router.routeInformationParser,
routerDelegate: _router.routerDelegate,
title: title,
color: blue,
textStyle: const TextStyle(color: blue),
);
final _router = GoRouter(
debugLogDiagnostics: true,
routes: [
GoRoute(
path: '/',
builder: (context, state) => const Page1Screen(),
),
GoRoute(
path: '/page2',
builder: (context, state) => const Page2Screen(),
),
],
);
}
class Page1Screen extends StatelessWidget {
const Page1Screen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
App.title,
style: TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(height: 16),
Button(
onPressed: () => context.go('/page2'),
child: const Text(
'Go to page 2',
style: TextStyle(color: white),
),
),
],
),
),
);
}
class Page2Screen extends StatelessWidget {
const Page2Screen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
App.title,
style: TextStyle(fontWeight: FontWeight.bold),
),
const SizedBox(height: 16),
Button(
onPressed: () => context.go('/'),
child: const Text(
'Go to home page',
style: TextStyle(color: white),
),
),
],
),
),
);
}
class Button extends StatelessWidget {
const Button({
required this.onPressed,
required this.child,
Key? key,
}) : super(key: key);
final VoidCallback onPressed;
final Widget child;
@override
Widget build(BuildContext context) => GestureDetector(
onTap: onPressed,
child: Container(
padding: const EdgeInsets.all(8),
color: blue,
child: child,
),
);
}