forked from firka/flutter
Step 1 of 2: Warn about Flutter's FloatingActionButton dependency on ThemeData accent properties (#48435)
This commit is contained in:
@@ -10,6 +10,7 @@ import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'button.dart';
|
||||
import 'colors.dart';
|
||||
import 'floating_action_button_theme.dart';
|
||||
import 'scaffold.dart';
|
||||
import 'theme.dart';
|
||||
@@ -230,14 +231,25 @@ class FloatingActionButton extends StatelessWidget {
|
||||
/// used for accessibility.
|
||||
final String tooltip;
|
||||
|
||||
/// The default icon and text color.
|
||||
/// The default foreground color for icons and text within the button.
|
||||
///
|
||||
/// Defaults to [ThemeData.accentIconTheme.color] for the current theme.
|
||||
/// If this property is null, then the [Theme]'s
|
||||
/// [ThemeData.floatingActionButtonTheme.foregroundColor] is used. If that
|
||||
/// property is also null, then the [Theme]'s
|
||||
/// [ThemeData.colorScheme.onSecondary] color is used.
|
||||
///
|
||||
/// Although the color of theme's `accentIconTheme` currently provides a
|
||||
/// default that supercedes the `onSecondary` color, this dependency
|
||||
/// has been deprecated: https://flutter.dev/go/remove-fab-accent-theme-dependency.
|
||||
/// It will be removed in the future.
|
||||
final Color foregroundColor;
|
||||
|
||||
/// The color to use when filling the button.
|
||||
/// The button's background color.
|
||||
///
|
||||
/// Defaults to [ThemeData.accentColor] for the current theme.
|
||||
/// If this property is null, then the [Theme]'s
|
||||
/// [ThemeData.floatingActionButtonTheme.backgroundColor] is used. If that
|
||||
/// property is also null, then the [Theme]'s
|
||||
/// [ThemeData.colorScheme.secondary] color is used.
|
||||
final Color backgroundColor;
|
||||
|
||||
/// The color to use for filling the button when the button has input focus.
|
||||
@@ -411,6 +423,25 @@ class FloatingActionButton extends StatelessWidget {
|
||||
final ThemeData theme = Theme.of(context);
|
||||
final FloatingActionButtonThemeData floatingActionButtonTheme = theme.floatingActionButtonTheme;
|
||||
|
||||
// Applications should no longer use accentIconTheme's color to configure
|
||||
// the foreground color of floating action buttons. For more information, see
|
||||
// https://flutter.dev/go/remove-fab-accent-theme-dependency.
|
||||
if (this.foregroundColor == null && floatingActionButtonTheme.foregroundColor == null) {
|
||||
final bool accentIsDark = theme.accentColorBrightness == Brightness.dark;
|
||||
final Color defaultAccentIconThemeColor = accentIsDark ? Colors.white : Colors.black;
|
||||
if (theme.accentIconTheme.color != defaultAccentIconThemeColor) {
|
||||
debugPrint(
|
||||
'Warning: '
|
||||
'The support for configuring the foreground color of '
|
||||
'FloatingActionButtons using ThemeData.accentIconTheme '
|
||||
'has been deprecated. Please use ThemeData.floatingActionButtonTheme '
|
||||
'instead. See '
|
||||
'https://flutter.dev/docs/release/breaking-changes/fab_accent_dependency. '
|
||||
'This feature was deprecated after v1.13.2.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
final Color foregroundColor = this.foregroundColor
|
||||
?? floatingActionButtonTheme.foregroundColor
|
||||
?? theme.accentIconTheme.color
|
||||
|
||||
@@ -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/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -117,7 +118,16 @@ void main() {
|
||||
expect(_getRawMaterialButton(tester).splashColor, splashColor);
|
||||
});
|
||||
|
||||
// The feature checked by this test has been deprecated, see
|
||||
// https://flutter.dev/go/remove-fab-accent-theme-dependency. This test will be
|
||||
// removed in the future.
|
||||
testWidgets('FloatingActionButton foreground color uses iconAccentTheme if no widget or widget theme color is specified', (WidgetTester tester) async {
|
||||
final DebugPrintCallback oldPrint = debugPrint;
|
||||
final List<String> log = <String>[];
|
||||
debugPrint = (String message, { int wrapWidth }) {
|
||||
log.add(message);
|
||||
};
|
||||
|
||||
await tester.pumpWidget(MaterialApp(
|
||||
home: Scaffold(
|
||||
floatingActionButton: Theme(
|
||||
@@ -132,6 +142,11 @@ void main() {
|
||||
),
|
||||
));
|
||||
|
||||
debugPrint = oldPrint;
|
||||
|
||||
// Verify that a warning message is generated.
|
||||
expect(log.first, contains('https://flutter.dev/docs/release/breaking-changes/fab_accent_dependency'));
|
||||
|
||||
expect(_getRichText(tester).text.style.color, const Color(0xFACEFACE));
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user