mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
platform_design: Enforce use_key_in_widget_constructors (#927)
This commit is contained in:
@@ -11,9 +11,11 @@ import 'settings_tab.dart';
|
||||
import 'songs_tab.dart';
|
||||
import 'widgets.dart';
|
||||
|
||||
void main() => runApp(MyAdaptingApp());
|
||||
void main() => runApp(const MyAdaptingApp());
|
||||
|
||||
class MyAdaptingApp extends StatelessWidget {
|
||||
const MyAdaptingApp({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(context) {
|
||||
// Either Material or Cupertino widgets work in either Material or Cupertino
|
||||
@@ -34,6 +36,7 @@ class MyAdaptingApp extends StatelessWidget {
|
||||
child: Material(child: child),
|
||||
);
|
||||
},
|
||||
// ignore: use_key_in_widget_constructors
|
||||
home: PlatformAdaptingHomePage(),
|
||||
);
|
||||
}
|
||||
@@ -47,6 +50,8 @@ class MyAdaptingApp extends StatelessWidget {
|
||||
// These differences are also subjective and have more than one 'right' answer
|
||||
// depending on the app and content.
|
||||
class PlatformAdaptingHomePage extends StatefulWidget {
|
||||
const PlatformAdaptingHomePage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_PlatformAdaptingHomePageState createState() =>
|
||||
_PlatformAdaptingHomePageState();
|
||||
@@ -107,12 +112,12 @@ class _PlatformAdaptingHomePageState extends State<PlatformAdaptingHomePage> {
|
||||
case 1:
|
||||
return CupertinoTabView(
|
||||
defaultTitle: NewsTab.title,
|
||||
builder: (context) => NewsTab(),
|
||||
builder: (context) => const NewsTab(),
|
||||
);
|
||||
case 2:
|
||||
return CupertinoTabView(
|
||||
defaultTitle: ProfileTab.title,
|
||||
builder: (context) => ProfileTab(),
|
||||
builder: (context) => const ProfileTab(),
|
||||
);
|
||||
default:
|
||||
assert(false, 'Unexpected tab');
|
||||
@@ -161,8 +166,8 @@ class _AndroidDrawer extends StatelessWidget {
|
||||
title: const Text(NewsTab.title),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.push<void>(
|
||||
context, MaterialPageRoute(builder: (context) => NewsTab()));
|
||||
Navigator.push<void>(context,
|
||||
MaterialPageRoute(builder: (context) => const NewsTab()));
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
@@ -171,7 +176,7 @@ class _AndroidDrawer extends StatelessWidget {
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.push<void>(context,
|
||||
MaterialPageRoute(builder: (context) => ProfileTab()));
|
||||
MaterialPageRoute(builder: (context) => const ProfileTab()));
|
||||
},
|
||||
),
|
||||
// Long drawer contents are often segmented.
|
||||
@@ -185,7 +190,7 @@ class _AndroidDrawer extends StatelessWidget {
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.push<void>(context,
|
||||
MaterialPageRoute(builder: (context) => SettingsTab()));
|
||||
MaterialPageRoute(builder: (context) => const SettingsTab()));
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user