Fix ThemeData extension throws when the ThemeExtension not found (#103343)
This commit is contained in:
@@ -1077,7 +1077,7 @@ class ThemeData with Diagnosticable {
|
||||
/// Obtain with `Theme.of(context).extension<MyThemeExtension>()`.
|
||||
///
|
||||
/// See [extensions] for an interactive example.
|
||||
T? extension<T>() => extensions[T] as T;
|
||||
T? extension<T>() => extensions[T] as T?;
|
||||
|
||||
/// The default [InputDecoration] values for [InputDecorator], [TextField],
|
||||
/// and [TextFormField] are based on this theme.
|
||||
|
||||
@@ -561,6 +561,14 @@ void main() {
|
||||
expect(lerped.extension<MyThemeExtensionA>()!.color2, const Color(0xff90ab7d));
|
||||
expect(lerped.extension<MyThemeExtensionB>()!.textStyle, const TextStyle(fontSize: 100)); // Not lerped
|
||||
});
|
||||
|
||||
testWidgets('should return null on extension not found', (WidgetTester tester) async {
|
||||
final ThemeData theme = ThemeData(
|
||||
extensions: const <ThemeExtension<dynamic>>{},
|
||||
);
|
||||
|
||||
expect(theme.extension<MyThemeExtensionA>(), isNull);
|
||||
});
|
||||
});
|
||||
|
||||
test('copyWith, ==, hashCode basics', () {
|
||||
|
||||
Reference in New Issue
Block a user