mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Add go_router to form_app (#1522)
* Add go_router to form_app * format * add trailing comas
This commit is contained in:
@@ -6,6 +6,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:window_size/window_size.dart';
|
||||
|
||||
import 'src/autofill.dart';
|
||||
@@ -41,7 +42,7 @@ void setupWindow() {
|
||||
final demos = [
|
||||
Demo(
|
||||
name: 'Sign in with HTTP',
|
||||
route: '/signin_http',
|
||||
route: 'signin_http',
|
||||
builder: (context) => SignInHttpDemo(
|
||||
// This sample uses a mock HTTP client.
|
||||
httpClient: mockClient,
|
||||
@@ -49,37 +50,53 @@ final demos = [
|
||||
),
|
||||
Demo(
|
||||
name: 'Autofill',
|
||||
route: '/autofill',
|
||||
route: 'autofill',
|
||||
builder: (context) => const AutofillDemo(),
|
||||
),
|
||||
Demo(
|
||||
name: 'Form widgets',
|
||||
route: '/form_widgets',
|
||||
route: 'form_widgets',
|
||||
builder: (context) => const FormWidgetsDemo(),
|
||||
),
|
||||
Demo(
|
||||
name: 'Validation',
|
||||
route: '/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(
|
||||
return MaterialApp.router(
|
||||
title: 'Form Samples',
|
||||
theme: ThemeData(primarySwatch: Colors.teal),
|
||||
routes: Map.fromEntries(demos.map((d) => MapEntry(d.route, d.builder))),
|
||||
home: const HomePage(),
|
||||
routerConfig: router,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class HomePage extends StatelessWidget {
|
||||
const HomePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -103,7 +120,7 @@ class DemoTile extends StatelessWidget {
|
||||
return ListTile(
|
||||
title: Text(demo!.name),
|
||||
onTap: () {
|
||||
Navigator.pushNamed(context, demo!.route);
|
||||
context.go('/${demo!.route}');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ dependencies:
|
||||
git:
|
||||
url: https://github.com/google/flutter-desktop-embedding.git
|
||||
path: plugins/window_size
|
||||
go_router: ^5.2.4
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user