Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the `engine` subdirectory and enforces that these files stay formatted with a presubmit check. **Reviewers:** Please carefully review all the commits except for the one titled "formatted". The "formatted" commit was auto-generated by running `dev/tools/format.sh -a -f`. The other commits were hand-crafted to prepare the repo for the formatting change. I recommend reviewing the commits one-by-one via the "Commits" tab and avoiding Github's "Files changed" tab as it will likely slow down your browser because of the size of this PR. --------- Co-authored-by: Kate Lovett <katelovett@google.com> Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8e0993eda8
commit
5491c8c146
@@ -21,25 +21,19 @@ class NavigatorPopHandlerApp extends StatelessWidget {
|
||||
onGenerateRoute: (RouteSettings settings) {
|
||||
return switch (settings.name) {
|
||||
'/' => MaterialPageRoute<void>(
|
||||
settings: const RouteSettings(
|
||||
name: '/',
|
||||
),
|
||||
settings: const RouteSettings(name: '/'),
|
||||
builder: (BuildContext context) {
|
||||
return _HomePage();
|
||||
},
|
||||
),
|
||||
'/nested_navigators' => MaterialPageRoute<void>(
|
||||
settings: const RouteSettings(
|
||||
name: '/nested_navigators',
|
||||
),
|
||||
settings: const RouteSettings(name: '/nested_navigators'),
|
||||
builder: (BuildContext context) {
|
||||
return const _NestedNavigatorsPage();
|
||||
},
|
||||
),
|
||||
_ => MaterialPageRoute<void>(
|
||||
settings: const RouteSettings(
|
||||
name: 'unknown_page',
|
||||
),
|
||||
settings: const RouteSettings(name: 'unknown_page'),
|
||||
builder: (BuildContext context) {
|
||||
return const _UnknownPage();
|
||||
},
|
||||
@@ -54,9 +48,7 @@ class _HomePage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Nested Navigators Example'),
|
||||
),
|
||||
appBar: AppBar(title: const Text('Nested Navigators Example')),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@@ -66,7 +58,9 @@ class _HomePage extends StatelessWidget {
|
||||
const SizedBox(height: 20.0),
|
||||
ListTile(
|
||||
title: const Text('Nested Navigator route'),
|
||||
subtitle: const Text('This route has another Navigator widget in addition to the one inside MaterialApp above.'),
|
||||
subtitle: const Text(
|
||||
'This route has another Navigator widget in addition to the one inside MaterialApp above.',
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.of(context).restorablePushNamed('/nested_navigators');
|
||||
},
|
||||
@@ -102,25 +96,20 @@ class _NestedNavigatorsPageState extends State<_NestedNavigatorsPage> {
|
||||
final BuildContext rootContext = context;
|
||||
return switch (settings.name) {
|
||||
'nested_navigators/one' => MaterialPageRoute<void>(
|
||||
settings: const RouteSettings(
|
||||
name: 'nested_navigators/one',
|
||||
),
|
||||
builder: (BuildContext context) => _NestedNavigatorsPageOne(
|
||||
onBack: () {
|
||||
Navigator.of(rootContext).pop();
|
||||
},
|
||||
),
|
||||
settings: const RouteSettings(name: 'nested_navigators/one'),
|
||||
builder:
|
||||
(BuildContext context) => _NestedNavigatorsPageOne(
|
||||
onBack: () {
|
||||
Navigator.of(rootContext).pop();
|
||||
},
|
||||
),
|
||||
),
|
||||
'nested_navigators/one/another_one' => MaterialPageRoute<void>(
|
||||
settings: const RouteSettings(
|
||||
name: 'nested_navigators/one',
|
||||
),
|
||||
settings: const RouteSettings(name: 'nested_navigators/one'),
|
||||
builder: (BuildContext context) => const _NestedNavigatorsPageTwo(),
|
||||
),
|
||||
_ => MaterialPageRoute<void>(
|
||||
settings: const RouteSettings(
|
||||
name: 'unknown_page',
|
||||
),
|
||||
settings: const RouteSettings(name: 'unknown_page'),
|
||||
builder: (BuildContext context) {
|
||||
return const _UnknownPage();
|
||||
},
|
||||
@@ -133,9 +122,7 @@ class _NestedNavigatorsPageState extends State<_NestedNavigatorsPage> {
|
||||
}
|
||||
|
||||
class _NestedNavigatorsPageOne extends StatelessWidget {
|
||||
const _NestedNavigatorsPageOne({
|
||||
required this.onBack,
|
||||
});
|
||||
const _NestedNavigatorsPageOne({required this.onBack});
|
||||
|
||||
final VoidCallback onBack;
|
||||
|
||||
@@ -203,12 +190,7 @@ class _UnknownPage extends StatelessWidget {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.grey.withBlue(180),
|
||||
body: const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Text('404'),
|
||||
],
|
||||
),
|
||||
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[Text('404')]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,11 +7,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// There are three possible tabs.
|
||||
enum _Tab {
|
||||
home,
|
||||
one,
|
||||
two,
|
||||
}
|
||||
enum _Tab { home, one, two }
|
||||
|
||||
// Each tab has two possible pages.
|
||||
enum _TabPage {
|
||||
@@ -42,17 +38,13 @@ class NavigatorPopHandlerApp extends StatelessWidget {
|
||||
onGenerateRoute: (RouteSettings settings) {
|
||||
return switch (settings.name) {
|
||||
'/' => MaterialPageRoute<void>(
|
||||
settings: const RouteSettings(
|
||||
name: '/',
|
||||
),
|
||||
settings: const RouteSettings(name: '/'),
|
||||
builder: (BuildContext context) {
|
||||
return const _BottomNavPage();
|
||||
},
|
||||
),
|
||||
_ => MaterialPageRoute<void>(
|
||||
settings: const RouteSettings(
|
||||
name: 'unknown_page',
|
||||
),
|
||||
settings: const RouteSettings(name: 'unknown_page'),
|
||||
builder: (BuildContext context) {
|
||||
return const _UnknownPage();
|
||||
},
|
||||
@@ -84,20 +76,11 @@ class _BottomNavPageState extends State<_BottomNavPage> with RestorationMixin {
|
||||
BottomNavigationBarItem _itemForPage(_Tab page) {
|
||||
switch (page) {
|
||||
case _Tab.home:
|
||||
return const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.home),
|
||||
label: 'Go to Home',
|
||||
);
|
||||
return const BottomNavigationBarItem(icon: Icon(Icons.home), label: 'Go to Home');
|
||||
case _Tab.one:
|
||||
return const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.one_k),
|
||||
label: 'Go to One',
|
||||
);
|
||||
return const BottomNavigationBarItem(icon: Icon(Icons.one_k), label: 'Go to One');
|
||||
case _Tab.two:
|
||||
return const BottomNavigationBarItem(
|
||||
icon: Icon(Icons.two_k),
|
||||
label: 'Go to Two',
|
||||
);
|
||||
return const BottomNavigationBarItem(icon: Icon(Icons.two_k), label: 'Go to Two');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,9 +158,7 @@ class _BottomNavPageState extends State<_BottomNavPage> with RestorationMixin {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: _getPage(_restorableTab.value),
|
||||
),
|
||||
body: Center(child: _getPage(_restorableTab.value)),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
items: _Tab.values.map(_itemForPage).toList(),
|
||||
currentIndex: _Tab.values.indexOf(_restorableTab.value),
|
||||
@@ -223,64 +204,58 @@ class _BottomNavTabState extends State<_BottomNavTab> {
|
||||
if (tabPage == null) {
|
||||
return;
|
||||
}
|
||||
final List<_TabPage> nextPages = <_TabPage>[
|
||||
...widget.pages,
|
||||
]..remove(tabPage);
|
||||
final List<_TabPage> nextPages = <_TabPage>[...widget.pages]..remove(tabPage);
|
||||
if (nextPages.length < widget.pages.length) {
|
||||
widget.onChangePages(nextPages);
|
||||
}
|
||||
},
|
||||
pages: widget.pages.map((_TabPage page) {
|
||||
switch (page) {
|
||||
case _TabPage.home:
|
||||
return MaterialPage<void>(
|
||||
restorationId: _TabPage.home.toString(),
|
||||
name: 'home',
|
||||
child: _LinksPage(
|
||||
title: 'Bottom nav - tab ${widget.title} - route $page',
|
||||
backgroundColor: widget.color,
|
||||
buttons: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
assert(!widget.pages.contains(_TabPage.one));
|
||||
widget.onChangePages(<_TabPage>[
|
||||
...widget.pages,
|
||||
_TabPage.one,
|
||||
]);
|
||||
},
|
||||
child: const Text('Go to another route in this nested Navigator'),
|
||||
pages:
|
||||
widget.pages.map((_TabPage page) {
|
||||
switch (page) {
|
||||
case _TabPage.home:
|
||||
return MaterialPage<void>(
|
||||
restorationId: _TabPage.home.toString(),
|
||||
name: 'home',
|
||||
child: _LinksPage(
|
||||
title: 'Bottom nav - tab ${widget.title} - route $page',
|
||||
backgroundColor: widget.color,
|
||||
buttons: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
assert(!widget.pages.contains(_TabPage.one));
|
||||
widget.onChangePages(<_TabPage>[...widget.pages, _TabPage.one]);
|
||||
},
|
||||
child: const Text('Go to another route in this nested Navigator'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
case _TabPage.one:
|
||||
return MaterialPage<void>(
|
||||
restorationId: _TabPage.one.toString(),
|
||||
name: 'one',
|
||||
child: _LinksPage(
|
||||
backgroundColor: widget.color,
|
||||
title: 'Bottom nav - tab ${widget.title} - route $page',
|
||||
buttons: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
widget.onChangePages(<_TabPage>[
|
||||
...widget.pages,
|
||||
]..removeLast());
|
||||
},
|
||||
child: const Text('Go back'),
|
||||
);
|
||||
case _TabPage.one:
|
||||
return MaterialPage<void>(
|
||||
restorationId: _TabPage.one.toString(),
|
||||
name: 'one',
|
||||
child: _LinksPage(
|
||||
backgroundColor: widget.color,
|
||||
title: 'Bottom nav - tab ${widget.title} - route $page',
|
||||
buttons: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
widget.onChangePages(<_TabPage>[...widget.pages]..removeLast());
|
||||
},
|
||||
child: const Text('Go back'),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _LinksPage extends StatelessWidget {
|
||||
const _LinksPage ({
|
||||
const _LinksPage({
|
||||
required this.backgroundColor,
|
||||
this.buttons = const <Widget>[],
|
||||
required this.title,
|
||||
@@ -297,10 +272,7 @@ class _LinksPage extends StatelessWidget {
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Text(title),
|
||||
...buttons,
|
||||
],
|
||||
children: <Widget>[Text(title), ...buttons],
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -315,12 +287,7 @@ class _UnknownPage extends StatelessWidget {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.grey.withBlue(180),
|
||||
body: const Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Text('404'),
|
||||
],
|
||||
),
|
||||
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[Text('404')]),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -377,8 +344,6 @@ class _RestorableTabPageList extends RestorableValue<List<_TabPage>> {
|
||||
|
||||
@override
|
||||
Object toPrimitives() {
|
||||
return value
|
||||
.map((_TabPage tabPage) => tabPage.name)
|
||||
.join(',');
|
||||
return value.map((_TabPage tabPage) => tabPage.name).join(',');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user