diff --git a/.github/workflows/backward_compatibility.yml b/.github/workflows/backward_compatibility.yml index 951c0b794..4c86f58be 100644 --- a/.github/workflows/backward_compatibility.yml +++ b/.github/workflows/backward_compatibility.yml @@ -75,6 +75,11 @@ jobs: flutter-version: ${{ env.FLUTTER_VERSION }} - run: flutter test + - uses: actions/upload-artifact@v2 + if: failure() + with: + name: failures + path: packages/${{ matrix.package }}/test/failures/ fwfh_text_style: strategy: @@ -109,3 +114,8 @@ jobs: channel: ${{ matrix.channel }} - run: flutter --version - run: flutter test + - uses: actions/upload-artifact@v2 + if: failure() + with: + name: failures + path: packages/fwfh_text_style/test/failures/ diff --git a/demo_app/test/fwfh_text_style/CupertinoPageScaffold.png b/demo_app/test/fwfh_text_style/CupertinoPageScaffold.png new file mode 100644 index 000000000..7472ebdaa Binary files /dev/null and b/demo_app/test/fwfh_text_style/CupertinoPageScaffold.png differ diff --git a/packages/core/lib/src/data/text_style.dart b/packages/core/lib/src/data/text_style.dart index 8b4a50cb4..67e9730d3 100644 --- a/packages/core/lib/src/data/text_style.dart +++ b/packages/core/lib/src/data/text_style.dart @@ -57,12 +57,6 @@ class TextStyleHtml { TextDirection? textDirection, CssWhitespace? whitespace, }) { - assert( - style is FwfhTextStyle?, - 'The text style should be modified by methods of the existing instance: ' - 'apply(), copyWith() or merge().', - ); - return TextStyleHtml._( deps: _deps, parent: parent ?? this.parent, diff --git a/packages/core/test/core_test.dart b/packages/core/test/core_test.dart index 2db0e2dc7..7ecfec4fa 100644 --- a/packages/core/test/core_test.dart +++ b/packages/core/test/core_test.dart @@ -1,3 +1,4 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart'; @@ -1585,6 +1586,22 @@ Future main() async { }); }); }); + + testWidgets('#698: MaterialApp > CupertinoPageScaffold', (tester) async { + const html = 'Hello world'; + final key = GlobalKey(); + + await tester.pumpWidget( + MaterialApp( + home: CupertinoPageScaffold( + child: HtmlWidget(html, key: key), + ), + ), + ); + + final explained = await explainWithoutPumping(key: key); + expect(explained, equals('[RichText:(#D0FF0000:$html)]')); + }); } class _InlineBlockOnWidgetsFactory extends WidgetFactory { diff --git a/packages/fwfh_text_style/lib/fwfh_text_style.dart b/packages/fwfh_text_style/lib/fwfh_text_style.dart index b25a083fc..6e44a83b2 100644 --- a/packages/fwfh_text_style/lib/fwfh_text_style.dart +++ b/packages/fwfh_text_style/lib/fwfh_text_style.dart @@ -7,16 +7,33 @@ const _default = _DefaultValue(); /// A [TextStyle] replacement. class FwfhTextStyle extends _TextStyleProxy { - /// Creates an instance from a [TextStyle] with inherit=false. + /// Creates an instance from another [TextStyle]. /// /// See also: [FwfhTextStyle.of]. - FwfhTextStyle.from(TextStyle ref) - : super._(ref is FwfhTextStyle ? ref.ref : ref); + static TextStyle from(TextStyle ref) { + if (ref.inherit) { + debugPrint( + 'Warning: Text style instance #${ref.hashCode} has inherit=true, ' + 'resetting its height will not be supported.', + ); + assert( + () { + debugPrint(StackTrace.current.toString()); + return true; + }(), + ); + return ref; + } else { + return FwfhTextStyle._(ref is FwfhTextStyle ? ref.ref : ref); + } + } /// Creates an instance from the closest [DefaultTextStyle]. - factory FwfhTextStyle.of(BuildContext context) => + static TextStyle of(BuildContext context) => FwfhTextStyle.from(DefaultTextStyle.of(context).style); + FwfhTextStyle._(TextStyle ref) : super._(ref); + @override TextStyle apply({ Color? color, @@ -163,12 +180,7 @@ class _DefaultValue { abstract class _TextStyleProxy implements TextStyle { final TextStyle ref; - _TextStyleProxy._(this.ref) - : assert( - ref.inherit == false, - "FwfhTextStyle.from() doesn't support incomplete TextStyle. " - 'Use `DefaultTextStyle.of(context)` to obtain the current style.', - ); + _TextStyleProxy._(this.ref); @override Paint? get background => ref.background; @@ -279,8 +291,11 @@ abstract class _TextStyleProxy implements TextStyle { @override double? get height => ref.height; + /// Flutter's [TextStyle.merge] implementation uses private properties + /// which will trigger weird errors in people's apps. + /// We cannot let that happen. @override - bool get inherit => ref.inherit; + bool get inherit => false; @override TextLeadingDistribution? get leadingDistribution => ref.leadingDistribution; diff --git a/packages/fwfh_text_style/test/fwfh_text_style_test.dart b/packages/fwfh_text_style/test/fwfh_text_style_test.dart index 4ffd9af77..1788b70eb 100644 --- a/packages/fwfh_text_style/test/fwfh_text_style_test.dart +++ b/packages/fwfh_text_style/test/fwfh_text_style_test.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:fwfh_text_style/fwfh_text_style.dart'; @@ -120,6 +121,7 @@ Future main() async { }); test('resets to null', () { + // ignore: avoid_redundant_argument_values final copied = obj.copyWith(height: null); expect(copied.height, isNull); expect(copied, isNot(equals(obj))); @@ -264,6 +266,27 @@ Future main() async { await screenMatchesGolden(tester, 'TextSpan'); }); + + testGoldens( + '#698: MaterialApp > CupertinoPageScaffold', + (tester) async { + await tester.pumpWidget( + MaterialApp( + home: CupertinoPageScaffold( + child: Builder( + builder: (context) => Text( + 'Foo Roboto', + style: FwfhTextStyle.of(context) + .copyWith(fontFamily: 'Roboto'), + ), + ), + ), + ), + ); + + await screenMatchesGolden(tester, 'CupertinoPageScaffold'); + }, + ); }, skip: goldenSkip, );