Dev, examples/api, etc updated for Material 3 by default (#129683)

Updated tests in dev, examples/api, and tests/widgets to ensure that
they continue to pass when the default for `ThemeData.useMaterial3` is
changed to true.

This is the final set of changes required for
https://github.com/flutter/flutter/issues/127064.
This commit is contained in:
Hans Muller
2023-06-28 09:41:58 -07:00
committed by GitHub
parent 32fe4d7f0a
commit 0d4b5ae122
29 changed files with 231 additions and 199 deletions

View File

@@ -463,6 +463,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Scaffold(
body: Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
@@ -517,6 +518,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Scaffold(
body: Row(
crossAxisAlignment: CrossAxisAlignment.baseline,

View File

@@ -41,7 +41,7 @@ void main() {
colorFilter: sepia,
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(primarySwatch: Colors.blue),
theme: ThemeData(primarySwatch: Colors.blue, useMaterial3: false),
home: Scaffold(
appBar: AppBar(
title: const Text('Sepia ColorFilter Test'),

View File

@@ -927,6 +927,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Padding(
padding: const EdgeInsets.only(top: 0.25),
child: Material(

View File

@@ -95,7 +95,7 @@ void main() {
imageFilter: matrix,
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(primarySwatch: Colors.blue),
theme: ThemeData(useMaterial3: false, primarySwatch: Colors.blue),
home: Scaffold(
appBar: AppBar(
title: const Text('Matrix ImageFilter Test'),
@@ -132,7 +132,7 @@ void main() {
imageFilter: matrixFilter,
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(primarySwatch: Colors.blue),
theme: ThemeData(useMaterial3: false, primarySwatch: Colors.blue),
home: Scaffold(
appBar: AppBar(
title: const Text('Matrix ImageFilter Test'),

View File

@@ -231,7 +231,7 @@ void main() {
testWidgets('ListView reinvoke builders', (WidgetTester tester) async {
late StateSetter setState;
ThemeData themeData = ThemeData.light();
ThemeData themeData = ThemeData.light(useMaterial3: false);
Widget itemBuilder(BuildContext context, int index) {
return Container(
@@ -263,7 +263,7 @@ void main() {
expect(widget.color, equals(Colors.blue));
setState(() {
themeData = ThemeData(primarySwatch: Colors.green);
themeData = ThemeData(primarySwatch: Colors.green, useMaterial3: false);
});
await tester.pump();

View File

@@ -32,17 +32,8 @@ Widget buildTest({
Key? key,
bool expanded = true,
}) {
return Localizations(
locale: const Locale('en', 'US'),
delegates: const <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
child: Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(),
child: Scaffold(
return MaterialApp(
home: Scaffold(
drawerDragStartBehavior: DragStartBehavior.down,
body: DefaultTabController(
length: 4,
@@ -114,8 +105,6 @@ Widget buildTest({
),
),
),
),
),
);
}
@@ -577,7 +566,7 @@ void main() {
const List<String> tabs = <String>['Hello', 'World'];
int buildCount = 0;
await tester.pumpWidget(
MaterialApp(home: Material(child:
MaterialApp(theme: ThemeData(useMaterial3: false), home: Material(child:
// THE FOLLOWING SECTION IS FROM THE NestedScrollView DOCUMENTATION
// (EXCEPT FOR THE CHANGES TO THE buildCount COUNTER)
DefaultTabController(
@@ -2274,6 +2263,7 @@ void main() {
// Regression tests for https://github.com/flutter/flutter/issues/17096
Widget buildBallisticTest(ScrollController controller) {
return MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Scaffold(
body: NestedScrollView(
controller: controller,

View File

@@ -155,6 +155,7 @@ void main() {
testWidgets('offset is correctly handled in Opacity', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Scaffold(
body: SingleChildScrollView(
child: RepaintBoundary(

View File

@@ -47,20 +47,23 @@ void main() {
testWidgets('PhysicalModel - clips when overflows and elevation is 0', (WidgetTester tester) async {
const Key key = Key('test');
await tester.pumpWidget(
const MediaQuery(
key: key,
data: MediaQueryData(),
child: Directionality(
textDirection: TextDirection.ltr,
child: Padding(
padding: EdgeInsets.all(50),
child: Row(
children: <Widget>[
Material(child: Text('A long long long long long long long string')),
Material(child: Text('A long long long long long long long string')),
Material(child: Text('A long long long long long long long string')),
Material(child: Text('A long long long long long long long string')),
],
Theme(
data: ThemeData(useMaterial3: false),
child: const MediaQuery(
key: key,
data: MediaQueryData(),
child: Directionality(
textDirection: TextDirection.ltr,
child: Padding(
padding: EdgeInsets.all(50),
child: Row(
children: <Widget>[
Material(child: Text('A long long long long long long long string')),
Material(child: Text('A long long long long long long long string')),
Material(child: Text('A long long long long long long long string')),
Material(child: Text('A long long long long long long long string')),
],
),
),
),
),

View File

@@ -158,6 +158,7 @@ void main() {
testWidgets('select to scroll works for small scrollable', (WidgetTester tester) async {
final ScrollController controller = ScrollController();
await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: false),
home: SelectionArea(
selectionControls: materialTextSelectionControls,
child: Scaffold(

View File

@@ -947,6 +947,7 @@ void main() {
final ScrollController outerController = ScrollController();
final ScrollController innerController = ScrollController();
await tester.pumpWidget(MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Scaffold(
body: SingleChildScrollView(
controller: outerController,

View File

@@ -1248,6 +1248,7 @@ void main() {
final UniqueKey outerText = UniqueKey();
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: SelectableRegion(
focusNode: FocusNode(),
selectionControls: materialTextSelectionControls,

View File

@@ -59,20 +59,23 @@ Widget overlay({ Widget? child }) {
}
Widget overlayWithEntry(OverlayEntry entry) {
return Localizations(
locale: const Locale('en', 'US'),
delegates: <LocalizationsDelegate<dynamic>>[
WidgetsLocalizationsDelegate(),
MaterialLocalizationsDelegate(),
],
child: Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(size: Size(800.0, 600.0)),
child: Overlay(
initialEntries: <OverlayEntry>[
entry,
],
return Theme(
data: ThemeData(useMaterial3: false),
child: Localizations(
locale: const Locale('en', 'US'),
delegates: <LocalizationsDelegate<dynamic>>[
WidgetsLocalizationsDelegate(),
MaterialLocalizationsDelegate(),
],
child: Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(size: Size(800.0, 600.0)),
child: Overlay(
initialEntries: <OverlayEntry>[
entry,
],
),
),
),
),
@@ -80,19 +83,22 @@ Widget overlayWithEntry(OverlayEntry entry) {
}
Widget boilerplate({ Widget? child }) {
return Localizations(
locale: const Locale('en', 'US'),
delegates: <LocalizationsDelegate<dynamic>>[
WidgetsLocalizationsDelegate(),
MaterialLocalizationsDelegate(),
],
child: Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(size: Size(800.0, 600.0)),
child: Center(
child: Material(
child: child,
return Theme(
data: ThemeData(useMaterial3: false),
child:Localizations(
locale: const Locale('en', 'US'),
delegates: <LocalizationsDelegate<dynamic>>[
WidgetsLocalizationsDelegate(),
MaterialLocalizationsDelegate(),
],
child: Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(size: Size(800.0, 600.0)),
child: Center(
child: Material(
child: child,
),
),
),
),
@@ -100,6 +106,7 @@ Widget boilerplate({ Widget? child }) {
);
}
Future<void> skipPastScrollingAnimation(WidgetTester tester) async {
await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
@@ -4130,7 +4137,7 @@ void main() {
(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false),
home: const Material(
child: Center(
child: SelectableText('something'),
@@ -4153,7 +4160,7 @@ void main() {
(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false),
home: const Material(
child: Center(
child: SelectableText(
@@ -4174,7 +4181,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false),
home: const Material(
child: Center(
child: SelectableText(
@@ -4200,7 +4207,7 @@ void main() {
(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false),
home: const Material(
child: Center(
child: SelectableText(
@@ -4224,7 +4231,7 @@ void main() {
(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false),
home: const Material(
child: Center(
child: SelectableText(
@@ -4256,7 +4263,7 @@ void main() {
(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false),
home: const Material(
child: Center(
child: SelectableText(
@@ -4285,7 +4292,7 @@ void main() {
(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false),
home: const Material(
child: Center(
child: SelectableText(
@@ -4314,7 +4321,7 @@ void main() {
(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(platform: TargetPlatform.android),
theme: ThemeData(platform: TargetPlatform.android, useMaterial3: false),
home: const Material(
child: Center(
child: SelectableText(
@@ -5019,6 +5026,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Material(
child: Center(
child: SelectableText(
@@ -5186,6 +5194,7 @@ void main() {
testWidgets('keeps alive when has focus', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: DefaultTabController(
length: 2,
child: Scaffold(
@@ -5349,8 +5358,9 @@ void main() {
const TextStyle textStyle = TextStyle(color: Color(0xff00ff00), fontSize: 12.0);
await tester.pumpWidget(
const MaterialApp(
home: SelectableText.rich(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: const SelectableText.rich(
TextSpan(
text: 'Abcd',
style: textStyle,
@@ -5369,6 +5379,7 @@ void main() {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: SelectableText(
'I love Flutter!',
onSelectionChanged: (TextSelection s, _) {
@@ -5408,6 +5419,7 @@ void main() {
TextSelection? selection;
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Material(
child: Builder(
builder: (BuildContext context) {

View File

@@ -24,6 +24,7 @@ void main() {
}) {
return MaterialApp(
theme: ThemeData(
useMaterial3: false,
materialTapTargetSize: MaterialTapTargetSize.padded,
),
home: Scaffold(

View File

@@ -244,35 +244,25 @@ void main() {
testWidgets('Sliver appbars - floating and pinned - second app bar stacks below', (WidgetTester tester) async {
final ScrollController controller = ScrollController();
await tester.pumpWidget(
Localizations(
locale: const Locale('en', 'us'),
delegates: const <LocalizationsDelegate<dynamic>>[
DefaultWidgetsLocalizations.delegate,
DefaultMaterialLocalizations.delegate,
],
child: Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: const MediaQueryData(),
child: CustomScrollView(
controller: controller,
slivers: <Widget>[
const SliverAppBar(floating: true, pinned: true, expandedHeight: 200.0, title: Text('A')),
const SliverAppBar(primary: false, pinned: true, title: Text('B')),
SliverList(
delegate: SliverChildListDelegate(
const <Widget>[
Text('C'),
Text('D'),
SizedBox(height: 500.0),
Text('E'),
SizedBox(height: 500.0),
],
),
),
],
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: CustomScrollView(
controller: controller,
slivers: <Widget>[
const SliverAppBar(floating: true, pinned: true, expandedHeight: 200.0, title: Text('A')),
const SliverAppBar(primary: false, pinned: true, title: Text('B')),
SliverList(
delegate: SliverChildListDelegate(
const <Widget>[
Text('C'),
Text('D'),
SizedBox(height: 500.0),
Text('E'),
SizedBox(height: 500.0),
],
),
),
),
],
),
),
);

View File

@@ -426,6 +426,7 @@ void main() {
}
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Scaffold(
body: CustomScrollView(
slivers: <Widget> [

View File

@@ -191,6 +191,7 @@ void main() {
testWidgets('Text Fade', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Scaffold(
backgroundColor: Colors.transparent,
body: RepaintBoundary(
@@ -520,7 +521,7 @@ void main() {
testWidgets('Text Inline widget', (WidgetTester tester) async {
await tester.pumpWidget(
Center(
Theme(data: ThemeData(useMaterial3: false), child: Center(
child: RepaintBoundary(
child: Material(
child: Directionality(
@@ -604,7 +605,7 @@ void main() {
),
),
),
),
)),
);
await expectLater(
find.byType(Container),
@@ -616,6 +617,7 @@ void main() {
await tester.pumpWidget(
Center(
child: MaterialApp(
theme: ThemeData(useMaterial3: false),
home: RepaintBoundary(
child: Material(
child: Container(
@@ -662,6 +664,7 @@ void main() {
await tester.pumpWidget(
Center(
child: MaterialApp(
theme: ThemeData(useMaterial3: false),
home: RepaintBoundary(
child: Material(
child: Container(

View File

@@ -208,6 +208,7 @@ void main() {
double textScaleFactor = 1.0;
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Scaffold(
appBar: AppBar(title: const Text('title')),
body: Center(
@@ -236,6 +237,7 @@ void main() {
textScaleFactor = textScaleFactor * 5;
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Scaffold(
appBar: AppBar(title: const Text('title')),
body: Center(
@@ -1132,6 +1134,7 @@ void main() {
Future<void> createText(TextWidthBasis textWidthBasis) {
return tester.pumpWidget(
MaterialApp(
theme: ThemeData(useMaterial3: false),
home: Scaffold(
body: Center(
// Each word takes up more than a half of a line. Together they

View File

@@ -46,6 +46,7 @@ Widget simpleBuilderTest({
bool setLayoutOffset = true,
}) {
return MaterialApp(
theme: ThemeData(useMaterial3: false),
restorationScopeId: restorationID,
home: Scaffold(
body: SimpleBuilderTableView(