diff --git a/examples/api/lib/material/drawer/drawer.0.dart b/examples/api/lib/material/drawer/drawer.0.dart new file mode 100644 index 0000000000..46c96ac435 --- /dev/null +++ b/examples/api/lib/material/drawer/drawer.0.dart @@ -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 createState() => _DrawerExampleState(); +} + +class _DrawerExampleState extends State { + String selectedPage = ''; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Drawer Example'), + ), + drawer: Drawer( + child: ListView( + padding: EdgeInsets.zero, + children: [ + 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'), + ), + ); + } +} diff --git a/examples/api/lib/material/navigation_drawer/navigation_drawer.0.dart b/examples/api/lib/material/navigation_drawer/navigation_drawer.0.dart index 446cd1308c..1854b6f850 100644 --- a/examples/api/lib/material/navigation_drawer/navigation_drawer.0.dart +++ b/examples/api/lib/material/navigation_drawer/navigation_drawer.0.dart @@ -11,6 +11,8 @@ import 'package:flutter/material.dart'; /// Flutter code sample for [NavigationDrawer]. +void main() => runApp(const NavigationDrawerApp()); + class ExampleDestination { const ExampleDestination(this.label, this.icon, this.selectedIcon); @@ -20,20 +22,22 @@ class ExampleDestination { } const List destinations = [ - ExampleDestination('page 0', Icon(Icons.widgets_outlined), Icon(Icons.widgets)), - ExampleDestination('page 1', Icon(Icons.format_paint_outlined), Icon(Icons.format_paint)), - ExampleDestination('page 2', Icon(Icons.text_snippet_outlined), Icon(Icons.text_snippet)), - ExampleDestination('page 3', Icon(Icons.invert_colors_on_outlined), Icon(Icons.opacity)), + ExampleDestination('Messages', Icon(Icons.widgets_outlined), Icon(Icons.widgets)), + ExampleDestination('Profile', Icon(Icons.format_paint_outlined), Icon(Icons.format_paint)), + ExampleDestination('Settings', Icon(Icons.settings_outlined), Icon(Icons.settings)), ]; -void main() { - runApp( - MaterialApp( +class NavigationDrawerApp extends StatelessWidget { + const NavigationDrawerApp({super.key}); + + @override + Widget build(BuildContext context) { + return MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData(useMaterial3: true), home: const NavigationDrawerExample(), - ), - ); + ); + } } class NavigationDrawerExample extends StatefulWidget { @@ -65,7 +69,7 @@ class _NavigationDrawerExampleState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - Text('Page Index = $screenIndex'), + Text('Page Index = $screenIndex'), ], ), ), @@ -125,7 +129,7 @@ class _NavigationDrawerExampleState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - Text('Page Index = $screenIndex'), + Text('Page Index = $screenIndex'), ElevatedButton( onPressed: openDrawer, child: const Text('Open Drawer'), diff --git a/examples/api/lib/material/navigation_drawer/navigation_drawer.1.dart b/examples/api/lib/material/navigation_drawer/navigation_drawer.1.dart deleted file mode 100644 index 344f410481..0000000000 --- a/examples/api/lib/material/navigation_drawer/navigation_drawer.1.dart +++ /dev/null @@ -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: [ - 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'), - ), - ]) - ); - } -} diff --git a/examples/api/lib/material/scaffold/scaffold_state.show_snack_bar.0.dart b/examples/api/lib/material/scaffold/scaffold_state.show_snack_bar.0.dart deleted file mode 100644 index 0f077982b9..0000000000 --- a/examples/api/lib/material/scaffold/scaffold_state.show_snack_bar.0.dart +++ /dev/null @@ -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'), - ); - } -} diff --git a/examples/api/test/material/drawer/drawer.0_test.dart b/examples/api/test/material/drawer/drawer.0_test.dart new file mode 100644 index 0000000000..6b94202217 --- /dev/null +++ b/examples/api/test/material/drawer/drawer.0_test.dart @@ -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); + }); +} diff --git a/examples/api/test/material/navigation_drawer/navigation_drawer.0_test.dart b/examples/api/test/material/navigation_drawer/navigation_drawer.0_test.dart new file mode 100644 index 0000000000..a7e9916d82 --- /dev/null +++ b/examples/api/test/material/navigation_drawer/navigation_drawer.0_test.dart @@ -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); + }); +}