Add go_router to form_app (#1522)

* Add go_router to form_app

* format

* add trailing comas
pull/1523/head
Miguel Beltran 2 years ago committed by GitHub
parent 8ae4a52fa7
commit 0f6a83258c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,6 +6,7 @@ import 'dart:io';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:window_size/window_size.dart'; import 'package:window_size/window_size.dart';
import 'src/autofill.dart'; import 'src/autofill.dart';
@ -41,7 +42,7 @@ void setupWindow() {
final demos = [ final demos = [
Demo( Demo(
name: 'Sign in with HTTP', name: 'Sign in with HTTP',
route: '/signin_http', route: 'signin_http',
builder: (context) => SignInHttpDemo( builder: (context) => SignInHttpDemo(
// This sample uses a mock HTTP client. // This sample uses a mock HTTP client.
httpClient: mockClient, httpClient: mockClient,
@ -49,37 +50,53 @@ final demos = [
), ),
Demo( Demo(
name: 'Autofill', name: 'Autofill',
route: '/autofill', route: 'autofill',
builder: (context) => const AutofillDemo(), builder: (context) => const AutofillDemo(),
), ),
Demo( Demo(
name: 'Form widgets', name: 'Form widgets',
route: '/form_widgets', route: 'form_widgets',
builder: (context) => const FormWidgetsDemo(), builder: (context) => const FormWidgetsDemo(),
), ),
Demo( Demo(
name: 'Validation', name: 'Validation',
route: '/validation', route: 'validation',
builder: (context) => const FormValidationDemo(), 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 { class FormApp extends StatelessWidget {
const FormApp({super.key}); const FormApp({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp.router(
title: 'Form Samples', title: 'Form Samples',
theme: ThemeData(primarySwatch: Colors.teal), theme: ThemeData(primarySwatch: Colors.teal),
routes: Map.fromEntries(demos.map((d) => MapEntry(d.route, d.builder))), routerConfig: router,
home: const HomePage(),
); );
} }
} }
class HomePage extends StatelessWidget { class HomePage extends StatelessWidget {
const HomePage({super.key}); const HomePage({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -103,7 +120,7 @@ class DemoTile extends StatelessWidget {
return ListTile( return ListTile(
title: Text(demo!.name), title: Text(demo!.name),
onTap: () { onTap: () {
Navigator.pushNamed(context, demo!.route); context.go('/${demo!.route}');
}, },
); );
} }

@ -18,6 +18,7 @@ dependencies:
git: git:
url: https://github.com/google/flutter-desktop-embedding.git url: https://github.com/google/flutter-desktop-embedding.git
path: plugins/window_size path: plugins/window_size
go_router: ^5.2.4
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

Loading…
Cancel
Save