Unverified Commit f5fb9e8c authored by Andree Yosua's avatar Andree Yosua Committed by GitHub

Fix ThemeData extension throws when the ThemeExtension not found (#103343)

parent a259fcb6
......@@ -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', () {
......
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