forked from flutter/plugins
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Material 3
AppBar
example (#102823)
- Loading branch information
1 parent
348a2b4
commit 3f5bd7d
Showing
9 changed files
with
295 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// 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 AppBar | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
void main() => runApp(const AppBarApp()); | ||
|
||
class AppBarApp extends StatelessWidget { | ||
const AppBarApp({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return const MaterialApp( | ||
home: AppBarExample(), | ||
); | ||
} | ||
} | ||
|
||
class AppBarExample extends StatelessWidget { | ||
const AppBarExample({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final ButtonStyle style = TextButton.styleFrom( | ||
primary: Theme.of(context).colorScheme.onPrimary, | ||
); | ||
return Scaffold( | ||
appBar: AppBar( | ||
actions: <Widget>[ | ||
TextButton( | ||
style: style, | ||
onPressed: () {}, | ||
child: const Text('Action 1'), | ||
), | ||
TextButton( | ||
style: style, | ||
onPressed: () {}, | ||
child: const Text('Action 2'), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// 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/app_bar/app_bar.0.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Appbar updates on navigation', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const example.AppBarApp(), | ||
); | ||
|
||
expect(find.widgetWithText(AppBar, 'AppBar Demo'), findsOneWidget); | ||
expect(find.text('This is the home page'), findsOneWidget); | ||
|
||
await tester.tap(find.byIcon(Icons.navigate_next)); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(find.widgetWithText(AppBar, 'Next page'), findsOneWidget); | ||
expect(find.text('This is the next page'), findsOneWidget); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// 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/app_bar/app_bar.1.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
const Offset _kOffset = Offset(0.0, -100.0); | ||
|
||
void main() { | ||
testWidgets('Appbar Material 3 test', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const example.AppBarApp() | ||
); | ||
|
||
expect(find.widgetWithText(AppBar, 'AppBar Demo'), findsOneWidget); | ||
Material appbarMaterial = _getAppBarMaterial(tester); | ||
expect(appbarMaterial.shadowColor, null); | ||
expect(appbarMaterial.elevation, 0); | ||
|
||
await tester.drag(find.text('Item 4'), _kOffset, touchSlopY: 0, warnIfMissed: false); | ||
|
||
await tester.pump(); | ||
await tester.pump(const Duration(milliseconds: 500)); | ||
|
||
await tester.tap(find.text('shadow color')); | ||
await tester.pumpAndSettle(); | ||
appbarMaterial = _getAppBarMaterial(tester); | ||
expect(appbarMaterial.shadowColor, Colors.black); | ||
expect(appbarMaterial.elevation, 3.0); | ||
|
||
await tester.tap(find.text('scrolledUnderElevation: default')); | ||
await tester.pumpAndSettle(); | ||
|
||
appbarMaterial = _getAppBarMaterial(tester); | ||
expect(appbarMaterial.shadowColor, Colors.black); | ||
expect(appbarMaterial.elevation, 4.0); | ||
|
||
await tester.tap(find.text('scrolledUnderElevation: 4.0')); | ||
await tester.pumpAndSettle(); | ||
appbarMaterial = _getAppBarMaterial(tester); | ||
expect(appbarMaterial.shadowColor, Colors.black); | ||
expect(appbarMaterial.elevation, 5.0); | ||
}); | ||
} | ||
|
||
Material _getAppBarMaterial(WidgetTester tester) { | ||
return tester.widget<Material>( | ||
find.descendant( | ||
of: find.byType(AppBar), | ||
matching: find.byType(Material), | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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/app_bar/app_bar.2.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Appbar and actions', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const example.AppBarApp(), | ||
); | ||
|
||
expect(find.byType(AppBar), findsOneWidget); | ||
expect(find.widgetWithText(TextButton, 'Action 1'), findsOneWidget); | ||
expect(find.widgetWithText(TextButton, 'Action 2'), findsOneWidget); | ||
}); | ||
} |
25 changes: 25 additions & 0 deletions
25
examples/api/test/material/appbar/sliver_app_bar.1_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// 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/app_bar/sliver_app_bar.1.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
const Offset _kOffset = Offset(0.0, -200.0); | ||
|
||
void main() { | ||
testWidgets('SliverAppbar can be pinned', (WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
const example.AppBarApp(), | ||
); | ||
|
||
expect(find.widgetWithText(SliverAppBar, 'SliverAppBar'), findsOneWidget); | ||
expect(tester.getBottomLeft(find.text('SliverAppBar')).dy, 144.0); | ||
|
||
await tester.drag(find.text('0'), _kOffset, touchSlopY: 0, warnIfMissed: false); | ||
await tester.pump(); | ||
await tester.pump(const Duration(milliseconds: 500)); | ||
expect(tester.getBottomLeft(find.text('SliverAppBar')).dy, 40.0); | ||
}); | ||
} |
Oops, something went wrong.