Material 3 common buttons should use sparkle splash effect on Android. (#101075)
This commit is contained in:
@@ -306,7 +306,7 @@ class ElevatedButton extends ButtonStyleButton {
|
||||
animationDuration: kThemeChangeDuration,
|
||||
enableFeedback: true,
|
||||
alignment: Alignment.center,
|
||||
splashFactory: InkRipple.splashFactory,
|
||||
splashFactory: theme.useMaterial3 ? theme.splashFactory : InkRipple.splashFactory,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -281,7 +281,7 @@ class OutlinedButton extends ButtonStyleButton {
|
||||
animationDuration: kThemeChangeDuration,
|
||||
enableFeedback: true,
|
||||
alignment: Alignment.center,
|
||||
splashFactory: InkRipple.splashFactory,
|
||||
splashFactory: theme.useMaterial3 ? theme.splashFactory : InkRipple.splashFactory,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -294,7 +294,7 @@ class TextButton extends ButtonStyleButton {
|
||||
animationDuration: kThemeChangeDuration,
|
||||
enableFeedback: true,
|
||||
alignment: Alignment.center,
|
||||
splashFactory: InkRipple.splashFactory,
|
||||
splashFactory: theme.useMaterial3 ? theme.splashFactory : InkRipple.splashFactory,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import 'drawer_theme.dart';
|
||||
import 'elevated_button_theme.dart';
|
||||
import 'expansion_tile_theme.dart';
|
||||
import 'floating_action_button_theme.dart';
|
||||
import 'ink_ripple.dart';
|
||||
import 'ink_sparkle.dart';
|
||||
import 'ink_splash.dart';
|
||||
import 'ink_well.dart' show InteractiveInkFeatureFactory;
|
||||
@@ -446,7 +447,9 @@ class ThemeData with Diagnosticable {
|
||||
visualDensity ??= VisualDensity.adaptivePlatformDensity;
|
||||
useMaterial3 ??= false;
|
||||
final bool useInkSparkle = platform == TargetPlatform.android && !kIsWeb;
|
||||
splashFactory ??= (useMaterial3 && useInkSparkle) ? InkSparkle.splashFactory : InkSplash.splashFactory;
|
||||
splashFactory ??= useMaterial3
|
||||
? useInkSparkle ? InkSparkle.splashFactory : InkRipple.splashFactory
|
||||
: InkSplash.splashFactory;
|
||||
|
||||
// COLOR
|
||||
assert(colorScheme?.brightness == null || brightness == null || colorScheme!.brightness == brightness);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
@@ -1272,6 +1273,55 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('ElevatedButton uses InkSparkle only for Android non-web when useMaterial3 is true', (WidgetTester tester) async {
|
||||
final ThemeData theme = ThemeData(useMaterial3: true);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: () { },
|
||||
child: const Text('button'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final InkWell buttonInkWell = tester.widget<InkWell>(find.descendant(
|
||||
of: find.byType(ElevatedButton),
|
||||
matching: find.byType(InkWell),
|
||||
));
|
||||
|
||||
if (debugDefaultTargetPlatformOverride! == TargetPlatform.android && !kIsWeb) {
|
||||
expect(buttonInkWell.splashFactory, equals(InkSparkle.splashFactory));
|
||||
} else {
|
||||
expect(buttonInkWell.splashFactory, equals(InkRipple.splashFactory));
|
||||
}
|
||||
}, variant: TargetPlatformVariant.all());
|
||||
|
||||
testWidgets('ElevatedButton uses InkRipple when useMaterial3 is false', (WidgetTester tester) async {
|
||||
final ThemeData theme = ThemeData(useMaterial3: false);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: () { },
|
||||
child: const Text('button'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final InkWell buttonInkWell = tester.widget<InkWell>(find.descendant(
|
||||
of: find.byType(ElevatedButton),
|
||||
matching: find.byType(InkWell),
|
||||
));
|
||||
expect(buttonInkWell.splashFactory, equals(InkRipple.splashFactory));
|
||||
}, variant: TargetPlatformVariant.all());
|
||||
|
||||
testWidgets('ElevatedButton.icon does not overflow', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/77815
|
||||
await tester.pumpWidget(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
@@ -1445,7 +1446,56 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('OultinedButton.icon does not overflow', (WidgetTester tester) async {
|
||||
testWidgets('OutlinedButton uses InkSparkle only for Android non-web when useMaterial3 is true', (WidgetTester tester) async {
|
||||
final ThemeData theme = ThemeData(useMaterial3: true);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: Center(
|
||||
child: OutlinedButton(
|
||||
onPressed: () { },
|
||||
child: const Text('button'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final InkWell buttonInkWell = tester.widget<InkWell>(find.descendant(
|
||||
of: find.byType(OutlinedButton),
|
||||
matching: find.byType(InkWell),
|
||||
));
|
||||
|
||||
if (debugDefaultTargetPlatformOverride! == TargetPlatform.android && !kIsWeb) {
|
||||
expect(buttonInkWell.splashFactory, equals(InkSparkle.splashFactory));
|
||||
} else {
|
||||
expect(buttonInkWell.splashFactory, equals(InkRipple.splashFactory));
|
||||
}
|
||||
}, variant: TargetPlatformVariant.all());
|
||||
|
||||
testWidgets('OutlinedButton uses InkRipple when useMaterial3 is false', (WidgetTester tester) async {
|
||||
final ThemeData theme = ThemeData(useMaterial3: false);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: Center(
|
||||
child: OutlinedButton(
|
||||
onPressed: () { },
|
||||
child: const Text('button'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final InkWell buttonInkWell = tester.widget<InkWell>(find.descendant(
|
||||
of: find.byType(OutlinedButton),
|
||||
matching: find.byType(InkWell),
|
||||
));
|
||||
expect(buttonInkWell.splashFactory, equals(InkRipple.splashFactory));
|
||||
}, variant: TargetPlatformVariant.all());
|
||||
|
||||
testWidgets('OutlinedButton.icon does not overflow', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/77815
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
@@ -1238,6 +1239,55 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('TextButton uses InkSparkle only for Android non-web when useMaterial3 is true', (WidgetTester tester) async {
|
||||
final ThemeData theme = ThemeData(useMaterial3: true);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: Center(
|
||||
child: TextButton(
|
||||
onPressed: () { },
|
||||
child: const Text('button'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final InkWell buttonInkWell = tester.widget<InkWell>(find.descendant(
|
||||
of: find.byType(TextButton),
|
||||
matching: find.byType(InkWell),
|
||||
));
|
||||
|
||||
if (debugDefaultTargetPlatformOverride! == TargetPlatform.android && !kIsWeb) {
|
||||
expect(buttonInkWell.splashFactory, equals(InkSparkle.splashFactory));
|
||||
} else {
|
||||
expect(buttonInkWell.splashFactory, equals(InkRipple.splashFactory));
|
||||
}
|
||||
}, variant: TargetPlatformVariant.all());
|
||||
|
||||
testWidgets('TextButton uses InkRipple when useMaterial3 is false', (WidgetTester tester) async {
|
||||
final ThemeData theme = ThemeData(useMaterial3: false);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: Center(
|
||||
child: TextButton(
|
||||
onPressed: () { },
|
||||
child: const Text('button'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final InkWell buttonInkWell = tester.widget<InkWell>(find.descendant(
|
||||
of: find.byType(TextButton),
|
||||
matching: find.byType(InkWell),
|
||||
));
|
||||
expect(buttonInkWell.splashFactory, equals(InkRipple.splashFactory));
|
||||
}, variant: TargetPlatformVariant.all());
|
||||
|
||||
testWidgets('TextButton.icon does not overflow', (WidgetTester tester) async {
|
||||
// Regression test for https://github.com/flutter/flutter/issues/77815
|
||||
await tester.pumpWidget(
|
||||
|
||||
@@ -333,7 +333,7 @@ void main() {
|
||||
switch (debugDefaultTargetPlatformOverride!) {
|
||||
case TargetPlatform.android:
|
||||
if (kIsWeb) {
|
||||
expect(theme.splashFactory, equals(InkSplash.splashFactory));
|
||||
expect(theme.splashFactory, equals(InkRipple.splashFactory));
|
||||
} else {
|
||||
expect(theme.splashFactory, equals(InkSparkle.splashFactory));
|
||||
}
|
||||
@@ -343,7 +343,7 @@ void main() {
|
||||
case TargetPlatform.linux:
|
||||
case TargetPlatform.macOS:
|
||||
case TargetPlatform.windows:
|
||||
expect(theme.splashFactory, equals(InkSplash.splashFactory));
|
||||
expect(theme.splashFactory, equals(InkRipple.splashFactory));
|
||||
}
|
||||
}, variant: TargetPlatformVariant.all());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user