Unverified Commit 169f1579 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Step 1 of 2: Warn about Flutter's FloatingActionButton dependency on ThemeData...

Step 1 of 2: Warn about Flutter's FloatingActionButton dependency on ThemeData accent properties (#48435)
parent d291de08
...@@ -10,6 +10,7 @@ import 'package:flutter/rendering.dart'; ...@@ -10,6 +10,7 @@ import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'button.dart'; import 'button.dart';
import 'colors.dart';
import 'floating_action_button_theme.dart'; import 'floating_action_button_theme.dart';
import 'scaffold.dart'; import 'scaffold.dart';
import 'theme.dart'; import 'theme.dart';
...@@ -230,14 +231,25 @@ class FloatingActionButton extends StatelessWidget { ...@@ -230,14 +231,25 @@ class FloatingActionButton extends StatelessWidget {
/// used for accessibility. /// used for accessibility.
final String tooltip; 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; 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; final Color backgroundColor;
/// The color to use for filling the button when the button has input focus. /// The color to use for filling the button when the button has input focus.
...@@ -411,6 +423,25 @@ class FloatingActionButton extends StatelessWidget { ...@@ -411,6 +423,25 @@ class FloatingActionButton extends StatelessWidget {
final ThemeData theme = Theme.of(context); final ThemeData theme = Theme.of(context);
final FloatingActionButtonThemeData floatingActionButtonTheme = theme.floatingActionButtonTheme; 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 final Color foregroundColor = this.foregroundColor
?? floatingActionButtonTheme.foregroundColor ?? floatingActionButtonTheme.foregroundColor
?? theme.accentIconTheme.color ?? theme.accentIconTheme.color
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -117,7 +118,16 @@ void main() { ...@@ -117,7 +118,16 @@ void main() {
expect(_getRawMaterialButton(tester).splashColor, splashColor); 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 { 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( await tester.pumpWidget(MaterialApp(
home: Scaffold( home: Scaffold(
floatingActionButton: Theme( floatingActionButton: Theme(
...@@ -132,6 +142,11 @@ void main() { ...@@ -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)); expect(_getRichText(tester).text.style.color, const Color(0xFACEFACE));
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment