-
Notifications
You must be signed in to change notification settings - Fork 7.7k
/
Copy pathmain.dart
134 lines (117 loc) · 3.1 KB
/
main.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io' show Platform;
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:window_size/window_size.dart';
import 'src/autofill.dart';
import 'src/form_widgets.dart';
import 'src/http/mock_client.dart';
import 'src/sign_in_http.dart';
import 'src/validation.dart';
void main() {
setupWindow();
runApp(const FormApp());
}
const double windowWidth = 480;
const double windowHeight = 854;
void setupWindow() {
if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
WidgetsFlutterBinding.ensureInitialized();
setWindowTitle('Form Samples');
setWindowMinSize(const Size(windowWidth, windowHeight));
setWindowMaxSize(const Size(windowWidth, windowHeight));
getCurrentScreen().then((screen) {
setWindowFrame(
Rect.fromCenter(
center: screen!.frame.center,
width: windowWidth,
height: windowHeight,
),
);
});
}
}
final demos = [
Demo(
name: 'Sign in with HTTP',
route: 'signin_http',
builder:
(context) => SignInHttpDemo(
// This sample uses a mock HTTP client.
httpClient: mockClient,
),
),
Demo(
name: 'Autofill',
route: 'autofill',
builder: (context) => const AutofillDemo(),
),
Demo(
name: 'Form widgets',
route: 'form_widgets',
builder: (context) => const FormWidgetsDemo(),
),
Demo(
name: 'Validation',
route: 'validation',
builder: (context) => const FormValidationDemo(),
),
];
final router = GoRouter(
routes: [
GoRoute(
path: '/',
builder: (context, state) => const HomePage(),
routes: [
for (final demo in demos)
GoRoute(
path: demo.route,
builder: (context, state) => demo.builder(context),
),
],
),
],
);
class FormApp extends StatelessWidget {
const FormApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Form Samples',
theme: ThemeData(colorSchemeSeed: Colors.teal),
routerConfig: router,
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Form Samples')),
body: ListView(children: [...demos.map((d) => DemoTile(demo: d))]),
);
}
}
class DemoTile extends StatelessWidget {
final Demo? demo;
const DemoTile({this.demo, super.key});
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(demo!.name),
onTap: () {
context.go('/${demo!.route}');
},
);
}
}
class Demo {
final String name;
final String route;
final WidgetBuilder builder;
const Demo({required this.name, required this.route, required this.builder});
}