1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 22:09:06 +00:00
Files
samples/form_app/lib/main.dart
Miguel Beltran 93db48966c Explicit import for Platform and kIsWeb (#1898)
Following the ideas in flutter/website#7798 I have changed the imports
needed for Platform and kIsWeb to be explicitly named.

## Pre-launch Checklist

- [ ] I read the [Flutter Style Guide] _recently_, and have followed its
advice.
- [ ] I signed the [CLA].
- [ ] I read the [Contributors Guide].
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-devrel
channel on [Discord].

<!-- Links -->
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[CLA]: https://cla.developers.google.com/
[Discord]: https://github.com/flutter/flutter/wiki/Chat
[Contributors Guide]:
https://github.com/flutter/samples/blob/main/CONTRIBUTING.md
2023-06-23 13:24:11 +10:00

139 lines
3.1 KiB
Dart

// 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,
useMaterial3: true,
),
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});
}