Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/backward_compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions packages/core/lib/src/data/text_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions packages/core/test/core_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -1585,6 +1586,22 @@ Future<void> main() async {
});
});
});

testWidgets('#698: MaterialApp > CupertinoPageScaffold', (tester) async {
const html = 'Hello world';
final key = GlobalKey<HtmlWidgetState>();

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 {
Expand Down
37 changes: 26 additions & 11 deletions packages/fwfh_text_style/lib/fwfh_text_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions packages/fwfh_text_style/test/fwfh_text_style_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -120,6 +121,7 @@ Future<void> 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)));
Expand Down Expand Up @@ -264,6 +266,27 @@ Future<void> 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,
);
Expand Down