Add missing example links (#130521)
## Description This adds some more missing example links. I also wrote another PR for adding a check to make sure that examples are all linked from a source file and have tests: https://github.com/flutter/flutter/pull/130523 ## Related Issues - https://github.com/flutter/flutter/issues/129956 ## Tests - Documentation and refactoring only.
This commit is contained in:
parent
1937ae6539
commit
0df4496cdb
90
examples/api/lib/material/drawer/drawer.0.dart
Normal file
90
examples/api/lib/material/drawer/drawer.0.dart
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// Flutter code sample for [Drawer].
|
||||||
|
|
||||||
|
void main() => runApp(const DrawerApp());
|
||||||
|
|
||||||
|
class DrawerApp extends StatelessWidget {
|
||||||
|
const DrawerApp({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MaterialApp(
|
||||||
|
theme: ThemeData(useMaterial3: true),
|
||||||
|
home: const DrawerExample(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DrawerExample extends StatefulWidget {
|
||||||
|
const DrawerExample({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<DrawerExample> createState() => _DrawerExampleState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DrawerExampleState extends State<DrawerExample> {
|
||||||
|
String selectedPage = '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('Drawer Example'),
|
||||||
|
),
|
||||||
|
drawer: Drawer(
|
||||||
|
child: ListView(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
children: <Widget>[
|
||||||
|
const DrawerHeader(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.blue,
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
'Drawer Header',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 24,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.message),
|
||||||
|
title: const Text('Messages'),
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
selectedPage = 'Messages';
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.account_circle),
|
||||||
|
title: const Text('Profile'),
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
selectedPage = 'Profile';
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.settings),
|
||||||
|
title: const Text('Settings'),
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
selectedPage = 'Settings';
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
body: Center(
|
||||||
|
child: Text('Page: $selectedPage'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,8 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
/// Flutter code sample for [NavigationDrawer].
|
/// Flutter code sample for [NavigationDrawer].
|
||||||
|
|
||||||
|
void main() => runApp(const NavigationDrawerApp());
|
||||||
|
|
||||||
class ExampleDestination {
|
class ExampleDestination {
|
||||||
const ExampleDestination(this.label, this.icon, this.selectedIcon);
|
const ExampleDestination(this.label, this.icon, this.selectedIcon);
|
||||||
|
|
||||||
@ -20,20 +22,22 @@ class ExampleDestination {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const List<ExampleDestination> destinations = <ExampleDestination>[
|
const List<ExampleDestination> destinations = <ExampleDestination>[
|
||||||
ExampleDestination('page 0', Icon(Icons.widgets_outlined), Icon(Icons.widgets)),
|
ExampleDestination('Messages', Icon(Icons.widgets_outlined), Icon(Icons.widgets)),
|
||||||
ExampleDestination('page 1', Icon(Icons.format_paint_outlined), Icon(Icons.format_paint)),
|
ExampleDestination('Profile', Icon(Icons.format_paint_outlined), Icon(Icons.format_paint)),
|
||||||
ExampleDestination('page 2', Icon(Icons.text_snippet_outlined), Icon(Icons.text_snippet)),
|
ExampleDestination('Settings', Icon(Icons.settings_outlined), Icon(Icons.settings)),
|
||||||
ExampleDestination('page 3', Icon(Icons.invert_colors_on_outlined), Icon(Icons.opacity)),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
void main() {
|
class NavigationDrawerApp extends StatelessWidget {
|
||||||
runApp(
|
const NavigationDrawerApp({super.key});
|
||||||
MaterialApp(
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MaterialApp(
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
theme: ThemeData(useMaterial3: true),
|
theme: ThemeData(useMaterial3: true),
|
||||||
home: const NavigationDrawerExample(),
|
home: const NavigationDrawerExample(),
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NavigationDrawerExample extends StatefulWidget {
|
class NavigationDrawerExample extends StatefulWidget {
|
||||||
@ -65,7 +69,7 @@ class _NavigationDrawerExampleState extends State<NavigationDrawerExample> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text('Page Index = $screenIndex'),
|
Text('Page Index = $screenIndex'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -125,7 +129,7 @@ class _NavigationDrawerExampleState extends State<NavigationDrawerExample> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text('Page Index = $screenIndex'),
|
Text('Page Index = $screenIndex'),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: openDrawer,
|
onPressed: openDrawer,
|
||||||
child: const Text('Open Drawer'),
|
child: const Text('Open Drawer'),
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
/// Flutter code sample for [NavigationDrawer].
|
|
||||||
|
|
||||||
void main() => runApp(const MyApp());
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
title: 'Flutter Demo',
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
theme: ThemeData(
|
|
||||||
useMaterial3: true,
|
|
||||||
),
|
|
||||||
home: const MyHomePage(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyHomePage extends StatelessWidget {
|
|
||||||
const MyHomePage({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: const Text('Drawer Demo'),
|
|
||||||
),
|
|
||||||
drawer: NavigationDrawer(
|
|
||||||
children: <Widget>[
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.fromLTRB(28, 16, 16, 10),
|
|
||||||
child: Text(
|
|
||||||
'Drawer Header',
|
|
||||||
style: Theme.of(context).textTheme.titleSmall,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const NavigationDrawerDestination(
|
|
||||||
icon: Icon(Icons.message),
|
|
||||||
label: Text('Messages'),
|
|
||||||
),
|
|
||||||
const NavigationDrawerDestination(
|
|
||||||
icon: Icon(Icons.account_circle),
|
|
||||||
label: Text('Profile'),
|
|
||||||
),
|
|
||||||
const NavigationDrawerDestination(
|
|
||||||
icon: Icon(Icons.settings),
|
|
||||||
label: Text('Settings'),
|
|
||||||
),
|
|
||||||
])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
/// Flutter code sample for [ScaffoldState.showSnackBar].
|
|
||||||
|
|
||||||
void main() => runApp(const ShowSnackBarExampleApp());
|
|
||||||
|
|
||||||
class ShowSnackBarExampleApp extends StatelessWidget {
|
|
||||||
const ShowSnackBarExampleApp({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return MaterialApp(
|
|
||||||
home: Scaffold(
|
|
||||||
appBar: AppBar(title: const Text('ScaffoldState Sample')),
|
|
||||||
body: const Center(
|
|
||||||
child: ShowSnackBarExample(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ShowSnackBarExample extends StatelessWidget {
|
|
||||||
const ShowSnackBarExample({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return OutlinedButton(
|
|
||||||
onPressed: () {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
const SnackBar(
|
|
||||||
content: Text('A SnackBar has been shown.'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: const Text('Show SnackBar'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
43
examples/api/test/material/drawer/drawer.0_test.dart
Normal file
43
examples/api/test/material/drawer/drawer.0_test.dart
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_api_samples/material/drawer/drawer.0.dart'
|
||||||
|
as example;
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('Navigation bar updates destination on tap',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const example.DrawerApp(),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.tap(find.byIcon(Icons.menu));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
/// NavigationDestinations must be rendered
|
||||||
|
expect(find.text('Messages'), findsOneWidget);
|
||||||
|
expect(find.text('Profile'), findsOneWidget);
|
||||||
|
expect(find.text('Settings'), findsOneWidget);
|
||||||
|
|
||||||
|
/// Initial index must be zero
|
||||||
|
expect(find.text('Page: '), findsOneWidget);
|
||||||
|
|
||||||
|
/// Switch to second tab
|
||||||
|
await tester.tap(find.ancestor(of: find.text('Messages'), matching: find.byType(InkWell)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Page: Messages'), findsOneWidget);
|
||||||
|
|
||||||
|
/// Switch to third tab
|
||||||
|
await tester.tap(find.ancestor(of: find.text('Profile'), matching: find.byType(InkWell)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Page: Profile'), findsOneWidget);
|
||||||
|
|
||||||
|
/// Switch to fourth tab
|
||||||
|
await tester.tap(find.ancestor(of: find.text('Settings'), matching: find.byType(InkWell)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Page: Settings'), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_api_samples/material/navigation_drawer/navigation_drawer.0.dart'
|
||||||
|
as example;
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('Navigation bar updates destination on tap',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(
|
||||||
|
const example.NavigationDrawerApp(),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.tap(find.text('Open Drawer'));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final NavigationDrawer navigationDrawerWidget = tester.firstWidget(find.byType(NavigationDrawer));
|
||||||
|
|
||||||
|
/// NavigationDestinations must be rendered
|
||||||
|
expect(find.text('Messages'), findsNWidgets(2));
|
||||||
|
expect(find.text('Profile'), findsNWidgets(2));
|
||||||
|
expect(find.text('Settings'), findsNWidgets(2));
|
||||||
|
|
||||||
|
/// Initial index must be zero
|
||||||
|
expect(navigationDrawerWidget.selectedIndex, 0);
|
||||||
|
expect(find.text('Page Index = 0'), findsOneWidget);
|
||||||
|
|
||||||
|
/// Switch to second tab
|
||||||
|
await tester.tap(find.ancestor(of: find.text('Profile'), matching: find.byType(InkWell)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Page Index = 1'), findsOneWidget);
|
||||||
|
|
||||||
|
/// Switch to fourth tab
|
||||||
|
await tester.tap(find.ancestor(of: find.text('Settings'), matching: find.byType(InkWell)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(find.text('Page Index = 2'), findsOneWidget);
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user