mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

This does a cleanup of the examples, removing all of the "section" markers and extra comments that we don't need anymore now that the samples are no longer in the source code. It also removes the --template arguments from the {@tool dartpad} and {@tool sample} directives, since those are no longer used. It converts two examples that I discovered were still embedded into linked examples in the examples folder. I didn't delete the templates from the snippets config folder yet, because there are still embedded samples in the dart:ui package from the engine that use them. Once dart:ui no longer uses the templates, they can be removed. I bumped the version of the snippets package to pick up a change that allows removal of the --template argument.
131 lines
4.0 KiB
Dart
131 lines
4.0 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// Flutter code sample for Navigator
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
void main() => runApp(const MyApp());
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Flutter Code Sample for Navigator',
|
|
// MaterialApp contains our top-level Navigator
|
|
initialRoute: '/',
|
|
routes: <String, WidgetBuilder>{
|
|
'/': (BuildContext context) => const HomePage(),
|
|
'/signup': (BuildContext context) => const SignUpPage(),
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class HomePage extends StatelessWidget {
|
|
const HomePage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return DefaultTextStyle(
|
|
style: Theme.of(context).textTheme.headline4!,
|
|
child: Container(
|
|
color: Colors.white,
|
|
alignment: Alignment.center,
|
|
child: const Text('Home Page'),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class CollectPersonalInfoPage extends StatelessWidget {
|
|
const CollectPersonalInfoPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return DefaultTextStyle(
|
|
style: Theme.of(context).textTheme.headline4!,
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
// This moves from the personal info page to the credentials page,
|
|
// replacing this page with that one.
|
|
Navigator.of(context)
|
|
.pushReplacementNamed('signup/choose_credentials');
|
|
},
|
|
child: Container(
|
|
color: Colors.lightBlue,
|
|
alignment: Alignment.center,
|
|
child: const Text('Collect Personal Info Page'),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class ChooseCredentialsPage extends StatelessWidget {
|
|
const ChooseCredentialsPage({
|
|
Key? key,
|
|
required this.onSignupComplete,
|
|
}) : super(key: key);
|
|
|
|
final VoidCallback onSignupComplete;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: onSignupComplete,
|
|
child: DefaultTextStyle(
|
|
style: Theme.of(context).textTheme.headline4!,
|
|
child: Container(
|
|
color: Colors.pinkAccent,
|
|
alignment: Alignment.center,
|
|
child: const Text('Choose Credentials Page'),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class SignUpPage extends StatelessWidget {
|
|
const SignUpPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// SignUpPage builds its own Navigator which ends up being a nested
|
|
// Navigator in our app.
|
|
return Navigator(
|
|
initialRoute: 'signup/personal_info',
|
|
onGenerateRoute: (RouteSettings settings) {
|
|
WidgetBuilder builder;
|
|
switch (settings.name) {
|
|
case 'signup/personal_info':
|
|
// Assume CollectPersonalInfoPage collects personal info and then
|
|
// navigates to 'signup/choose_credentials'.
|
|
builder = (BuildContext context) => const CollectPersonalInfoPage();
|
|
break;
|
|
case 'signup/choose_credentials':
|
|
// Assume ChooseCredentialsPage collects new credentials and then
|
|
// invokes 'onSignupComplete()'.
|
|
builder = (BuildContext _) => ChooseCredentialsPage(
|
|
onSignupComplete: () {
|
|
// Referencing Navigator.of(context) from here refers to the
|
|
// top level Navigator because SignUpPage is above the
|
|
// nested Navigator that it created. Therefore, this pop()
|
|
// will pop the entire "sign up" journey and return to the
|
|
// "/" route, AKA HomePage.
|
|
Navigator.of(context).pop();
|
|
},
|
|
);
|
|
break;
|
|
default:
|
|
throw Exception('Invalid route: ${settings.name}');
|
|
}
|
|
return MaterialPageRoute<void>(builder: builder, settings: settings);
|
|
},
|
|
);
|
|
}
|
|
}
|