Skip to content

Commit a8bd4b5

Browse files
committed
fix: [rfw] Fix fontWeight not applied in release mode
1 parent 23280da commit a8bd4b5

3 files changed

Lines changed: 763 additions & 224 deletions

File tree

packages/rfw/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## NEXT
2+
3+
* Fixes `fontWeight` not being applied in release mode for `Text` widgets.
4+
15
## 1.1.3
26

37
* Fixes dartdoc comments that accidentally used HTML.

packages/rfw/lib/src/flutter/argument_decoders.dart

Lines changed: 117 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ class AnimationDefaults extends InheritedWidget {
2727
///
2828
/// The [duration] and [curve] are optional, and default to 200ms and
2929
/// [Curves.fastOutSlowIn] respectively.
30-
const AnimationDefaults({
31-
super.key,
32-
this.duration,
33-
this.curve,
34-
required super.child,
35-
});
30+
const AnimationDefaults({super.key, this.duration, this.curve, required super.child});
3631

3732
/// The default duration that [ArgumentsDecoder.duration] should use.
3833
///
@@ -48,7 +43,8 @@ class AnimationDefaults extends InheritedWidget {
4843
/// ambient [AnimationDefaults] or if the nearest [AnimationDefaults] has a
4944
/// null [duration].
5045
static Duration durationOf(BuildContext context) {
51-
return context.dependOnInheritedWidgetOfExactType<AnimationDefaults>()?.duration ?? const Duration(milliseconds: 200);
46+
return context.dependOnInheritedWidgetOfExactType<AnimationDefaults>()?.duration ??
47+
const Duration(milliseconds: 200);
5248
}
5349

5450
/// Return the ambient [AnimationDefaults.curve], or [Curves.fastOutSlowIn] if
@@ -81,7 +77,8 @@ class ArgumentDecoders {
8177
const ArgumentDecoders._();
8278

8379
/// This is a workaround for https://github.com/dart-lang/sdk/issues/47021
84-
static const ArgumentDecoders __ = ArgumentDecoders._(); // ignore: unused_field
80+
// ignore: unused_field
81+
static const ArgumentDecoders __ = ArgumentDecoders._();
8582

8683
// (in alphabetical order)
8784

@@ -147,12 +144,7 @@ class ArgumentDecoders {
147144
final BorderSide? b = borderSide(source, [...key, 1]);
148145
final BorderSide? c = borderSide(source, [...key, 2]);
149146
final BorderSide? d = borderSide(source, [...key, 3]);
150-
return BorderDirectional(
151-
start: a,
152-
top: b ?? a,
153-
end: c ?? a,
154-
bottom: d ?? b ?? a,
155-
);
147+
return BorderDirectional(start: a, top: b ?? a, end: c ?? a, bottom: d ?? b ?? a);
156148
}
157149

158150
/// Returns a [BorderRadiusDirectional] from the specified list.
@@ -175,12 +167,7 @@ class ArgumentDecoders {
175167
final Radius? b = radius(source, [...key, 1]);
176168
final Radius? c = radius(source, [...key, 2]);
177169
final Radius? d = radius(source, [...key, 3]);
178-
return BorderRadiusDirectional.only(
179-
topStart: a,
180-
topEnd: b ?? a,
181-
bottomStart: c ?? a,
182-
bottomEnd: d ?? b ?? a,
183-
);
170+
return BorderRadiusDirectional.only(topStart: a, topEnd: b ?? a, bottomStart: c ?? a, bottomEnd: d ?? b ?? a);
184171
}
185172

186173
/// Returns a [BorderSide] from the specified map.
@@ -284,7 +271,8 @@ class ArgumentDecoders {
284271
}
285272

286273
/// Extension mechanism for [colorFilter].
287-
static final Map<String, ArgumentDecoder<ColorFilter?>> colorFilterDecoders = <String, ArgumentDecoder<ColorFilter?>>{};
274+
static final Map<String, ArgumentDecoder<ColorFilter?>> colorFilterDecoders =
275+
<String, ArgumentDecoder<ColorFilter?>>{};
288276

289277
/// Returns a list of 20 doubles from the specified list.
290278
///
@@ -495,7 +483,9 @@ class ArgumentDecoders {
495483
case 'flutterLogo':
496484
return FlutterLogoDecoration(
497485
textColor: color(source, [...key, 'color']) ?? const Color(0xFF757575),
498-
style: enumValue<FlutterLogoStyle>(FlutterLogoStyle.values, source, [...key, 'style']) ?? FlutterLogoStyle.markOnly,
486+
style:
487+
enumValue<FlutterLogoStyle>(FlutterLogoStyle.values, source, [...key, 'style']) ??
488+
FlutterLogoStyle.markOnly,
499489
margin: (edgeInsets(source, [...key, 'margin']) ?? EdgeInsets.zero).resolve(TextDirection.ltr),
500490
);
501491
case 'shape':
@@ -539,7 +529,10 @@ class ArgumentDecoders {
539529
return DecorationImage(
540530
image: provider,
541531
onError: (Object exception, StackTrace? stackTrace) {
542-
final VoidCallback? handler = source.voidHandler([...key, 'onError'], { 'exception': exception.toString(), 'stackTrack': stackTrace.toString() });
532+
final VoidCallback? handler = source.voidHandler(
533+
[...key, 'onError'],
534+
{'exception': exception.toString(), 'stackTrack': stackTrace.toString()},
535+
);
543536
if (handler != null) {
544537
handler();
545538
}
@@ -550,7 +543,8 @@ class ArgumentDecoders {
550543
centerSlice: rect(source, [...key, 'centerSlice']),
551544
repeat: enumValue<ImageRepeat>(ImageRepeat.values, source, [...key, 'repeat']) ?? ImageRepeat.noRepeat,
552545
matchTextDirection: source.v<bool>([...key, 'matchTextDirection']) ?? false,
553-
filterQuality: enumValue<FilterQuality>(FilterQuality.values, source, [...key, 'filterQuality']) ?? FilterQuality.medium,
546+
filterQuality:
547+
enumValue<FilterQuality>(FilterQuality.values, source, [...key, 'filterQuality']) ?? FilterQuality.medium,
554548
);
555549
}
556550

@@ -598,12 +592,7 @@ class ArgumentDecoders {
598592
final double? b = source.v<double>([...key, 1]);
599593
final double? c = source.v<double>([...key, 2]);
600594
final double? d = source.v<double>([...key, 3]);
601-
return EdgeInsetsDirectional.fromSTEB(
602-
a,
603-
b ?? a,
604-
c ?? a,
605-
d ?? b ?? a,
606-
);
595+
return EdgeInsetsDirectional.fromSTEB(a, b ?? a, c ?? a, d ?? b ?? a);
607596
}
608597

609598
/// Returns one of the values of the specified enum `T`, from the specified string.
@@ -632,6 +621,66 @@ class ArgumentDecoders {
632621
return null;
633622
}
634623

624+
/// Returns a [FontWeight] from the specified string or integer.
625+
///
626+
/// This does not use [FontWeight.toString], which is not guaranteed to be
627+
/// stable in release builds.
628+
///
629+
/// Supported values:
630+
///
631+
/// * strings `"w100"` ... `"w900"`
632+
/// * strings `"normal"` (mapped to [FontWeight.w400]) and `"bold"` (mapped
633+
/// to [FontWeight.w700])
634+
/// * integers `100` ... `900` in steps of 100
635+
static FontWeight? fontWeight(DataSource source, List<Object> key) {
636+
final int? numeric = source.v<int>(key);
637+
if (numeric != null) {
638+
switch (numeric) {
639+
case 100:
640+
return FontWeight.w100;
641+
case 200:
642+
return FontWeight.w200;
643+
case 300:
644+
return FontWeight.w300;
645+
case 400:
646+
return FontWeight.w400;
647+
case 500:
648+
return FontWeight.w500;
649+
case 600:
650+
return FontWeight.w600;
651+
case 700:
652+
return FontWeight.w700;
653+
case 800:
654+
return FontWeight.w800;
655+
case 900:
656+
return FontWeight.w900;
657+
}
658+
}
659+
switch (source.v<String>(key)) {
660+
case 'w100':
661+
return FontWeight.w100;
662+
case 'w200':
663+
return FontWeight.w200;
664+
case 'w300':
665+
return FontWeight.w300;
666+
case 'w400':
667+
case 'normal':
668+
return FontWeight.w400;
669+
case 'w500':
670+
return FontWeight.w500;
671+
case 'w600':
672+
return FontWeight.w600;
673+
case 'w700':
674+
case 'bold':
675+
return FontWeight.w700;
676+
case 'w800':
677+
return FontWeight.w800;
678+
case 'w900':
679+
return FontWeight.w900;
680+
}
681+
return null;
682+
}
683+
635684
/// Returns a [FontFeature] from the specified map.
636685
///
637686
/// The `feature` key is used as the font feature name (defaulting to the
@@ -689,7 +738,9 @@ class ArgumentDecoders {
689738
return LinearGradient(
690739
begin: alignment(source, [...key, 'begin']) ?? Alignment.centerLeft,
691740
end: alignment(source, [...key, 'end']) ?? Alignment.centerRight,
692-
colors: list<Color>(source, [...key, 'colors'], colorOrBlack) ?? const <Color>[Color(0xFF000000), Color(0xFFFFFFFF)],
741+
colors:
742+
list<Color>(source, [...key, 'colors'], colorOrBlack) ??
743+
const <Color>[Color(0xFF000000), Color(0xFFFFFFFF)],
693744
stops: list<double>(source, [...key, 'stops'], doubleOrZero),
694745
tileMode: enumValue<TileMode>(TileMode.values, source, [...key, 'tileMode']) ?? TileMode.clamp,
695746
// transform: GradientTransformMatrix(matrix(source, [...key, 'transform'])), // blocked by https://github.com/flutter/flutter/issues/87208
@@ -698,7 +749,9 @@ class ArgumentDecoders {
698749
return RadialGradient(
699750
center: alignment(source, [...key, 'center']) ?? Alignment.center,
700751
radius: source.v<double>([...key, 'radius']) ?? 0.5,
701-
colors: list<Color>(source, [...key, 'colors'], colorOrBlack) ?? const <Color>[Color(0xFF000000), Color(0xFFFFFFFF)],
752+
colors:
753+
list<Color>(source, [...key, 'colors'], colorOrBlack) ??
754+
const <Color>[Color(0xFF000000), Color(0xFFFFFFFF)],
702755
stops: list<double>(source, [...key, 'stops'], doubleOrZero),
703756
tileMode: enumValue<TileMode>(TileMode.values, source, [...key, 'tileMode']) ?? TileMode.clamp,
704757
focal: alignment(source, [...key, 'focal']),
@@ -710,7 +763,9 @@ class ArgumentDecoders {
710763
center: alignment(source, [...key, 'center']) ?? Alignment.center,
711764
startAngle: source.v<double>([...key, 'startAngle']) ?? 0.0,
712765
endAngle: source.v<double>([...key, 'endAngle']) ?? math.pi * 2,
713-
colors: list<Color>(source, [...key, 'colors'], colorOrBlack) ?? const <Color>[Color(0xFF000000), Color(0xFFFFFFFF)],
766+
colors:
767+
list<Color>(source, [...key, 'colors'], colorOrBlack) ??
768+
const <Color>[Color(0xFF000000), Color(0xFFFFFFFF)],
714769
stops: list<double>(source, [...key, 'stops'], doubleOrZero),
715770
tileMode: enumValue<TileMode>(TileMode.values, source, [...key, 'tileMode']) ?? TileMode.clamp,
716771
// transform: GradientTransformMatrix(matrix(source, [...key, 'transform'])), // blocked by https://github.com/flutter/flutter/issues/87208
@@ -780,7 +835,8 @@ class ArgumentDecoders {
780835
}
781836

782837
/// Extension mechanism for [gridDelegate].
783-
static final Map<String, ArgumentDecoder<SliverGridDelegate?>> gridDelegateDecoders = <String, ArgumentDecoder<SliverGridDelegate?>>{};
838+
static final Map<String, ArgumentDecoder<SliverGridDelegate?>> gridDelegateDecoders =
839+
<String, ArgumentDecoder<SliverGridDelegate?>>{};
784840

785841
/// Returns an [IconData] from the specified map.
786842
///
@@ -870,7 +926,8 @@ class ArgumentDecoders {
870926
}
871927

872928
/// Extension mechanism for [imageProvider].
873-
static final Map<String, ArgumentDecoder<ImageProvider?>> imageProviderDecoders = <String, ArgumentDecoder<ImageProvider?>>{};
929+
static final Map<String, ArgumentDecoder<ImageProvider?>> imageProviderDecoders =
930+
<String, ArgumentDecoder<ImageProvider?>>{};
874931

875932
/// Returns a [List] of `T` values from the specified list, using the given
876933
/// `decoder` to parse each value.
@@ -1047,7 +1104,10 @@ class ArgumentDecoders {
10471104
if (paintColorFilter != null) {
10481105
result.colorFilter = paintColorFilter;
10491106
}
1050-
final FilterQuality? paintFilterQuality = enumValue<FilterQuality>(FilterQuality.values, source, [...key, 'filterQuality']);
1107+
final FilterQuality? paintFilterQuality = enumValue<FilterQuality>(FilterQuality.values, source, [
1108+
...key,
1109+
'filterQuality',
1110+
]);
10511111
if (paintFilterQuality != null) {
10521112
result.filterQuality = paintFilterQuality;
10531113
}
@@ -1190,9 +1250,7 @@ class ArgumentDecoders {
11901250
borderRadius: borderRadius(source, [...key, 'borderRadius']) ?? BorderRadius.zero,
11911251
);
11921252
case 'circle':
1193-
return CircleBorder(
1194-
side: borderSide(source, [...key, 'side']) ?? BorderSide.none,
1195-
);
1253+
return CircleBorder(side: borderSide(source, [...key, 'side']) ?? BorderSide.none);
11961254
case 'continuous':
11971255
return ContinuousRectangleBorder(
11981256
side: borderSide(source, [...key, 'side']) ?? BorderSide.none,
@@ -1204,9 +1262,7 @@ class ArgumentDecoders {
12041262
borderRadius: borderRadius(source, [...key, 'borderRadius']) ?? BorderRadius.zero,
12051263
);
12061264
case 'stadium':
1207-
return StadiumBorder(
1208-
side: borderSide(source, [...key, 'side']) ?? BorderSide.none,
1209-
);
1265+
return StadiumBorder(side: borderSide(source, [...key, 'side']) ?? BorderSide.none);
12101266
default:
12111267
final ArgumentDecoder<ShapeBorder>? decoder = shapeBorderDecoders[type];
12121268
if (decoder == null) {
@@ -1243,7 +1299,8 @@ class ArgumentDecoders {
12431299
case 'sweep':
12441300
return gradient(source, key)!.createShader(
12451301
rect(source, [...key, 'rect']) ?? Rect.zero,
1246-
textDirection: enumValue<TextDirection>(TextDirection.values, source, ['textDirection']) ?? TextDirection.ltr,
1302+
textDirection:
1303+
enumValue<TextDirection>(TextDirection.values, source, [...key, 'textDirection']) ?? TextDirection.ltr,
12471304
);
12481305
default:
12491306
final ArgumentDecoder<Shader?>? decoder = shaderDecoders[type];
@@ -1276,7 +1333,7 @@ class ArgumentDecoders {
12761333
/// following keys: 'fontFamily` (string), `fontFamilyFallback` ([list] of
12771334
/// [string]), `fontSize` (double), `height` (double), `leadingDistribution`
12781335
/// ([enumValue] of [TextLeadingDistribution]), `leading` (double),
1279-
/// `fontWeight` ([enumValue] of [FontWeight]), `fontStyle` ([enumValue] of
1336+
/// `fontWeight` ([fontWeight]), `fontStyle` ([enumValue] of
12801337
/// [FontStyle]), `forceStrutHeight` (boolean).
12811338
static StrutStyle? strutStyle(DataSource source, List<Object> key) {
12821339
if (!source.isMap(key)) {
@@ -1287,9 +1344,12 @@ class ArgumentDecoders {
12871344
fontFamilyFallback: list<String>(source, [...key, 'fontFamilyFallback'], string),
12881345
fontSize: source.v<double>([...key, 'fontSize']),
12891346
height: source.v<double>([...key, 'height']),
1290-
leadingDistribution: enumValue<TextLeadingDistribution>(TextLeadingDistribution.values, source, [...key, 'leadingDistribution']),
1347+
leadingDistribution: enumValue<TextLeadingDistribution>(TextLeadingDistribution.values, source, [
1348+
...key,
1349+
'leadingDistribution',
1350+
]),
12911351
leading: source.v<double>([...key, 'leading']),
1292-
fontWeight: enumValue<FontWeight>(FontWeight.values, source, [...key, 'fontWeight']),
1352+
fontWeight: fontWeight(source, [...key, 'fontWeight']),
12931353
fontStyle: enumValue<FontStyle>(FontStyle.values, source, [...key, 'fontStyle']),
12941354
forceStrutHeight: source.v<bool>([...key, 'forceStrutHeight']),
12951355
);
@@ -1311,7 +1371,9 @@ class ArgumentDecoders {
13111371
return TextHeightBehavior(
13121372
applyHeightToFirstAscent: source.v<bool>([...key, 'applyHeightToFirstAscent']) ?? true,
13131373
applyHeightToLastDescent: source.v<bool>([...key, 'applyHeightToLastDescent']) ?? true,
1314-
leadingDistribution: enumValue<TextLeadingDistribution>(TextLeadingDistribution.values, source, [...key, 'leadingDistribution']) ?? TextLeadingDistribution.proportional,
1374+
leadingDistribution:
1375+
enumValue<TextLeadingDistribution>(TextLeadingDistribution.values, source, [...key, 'leadingDistribution']) ??
1376+
TextLeadingDistribution.proportional,
13151377
);
13161378
}
13171379

@@ -1350,7 +1412,7 @@ class ArgumentDecoders {
13501412
///
13511413
/// Otherwise (even if it has no keys), the [TextStyle] is created from the
13521414
/// following keys: `color` ([color]), `backgroundColor` ([color]), `fontSize`
1353-
/// (double), `fontWeight` ([enumValue] of [FontWeight]), `fontStyle`
1415+
/// (double), `fontWeight` ([fontWeight]), `fontStyle`
13541416
/// ([enumValue] of [FontStyle]), `letterSpacing` (double), `wordSpacing`
13551417
/// (double), `textBaseline` ([enumValue] of [TextBaseline]), `height`
13561418
/// (double), `leadingDistribution` ([enumValue] of
@@ -1369,13 +1431,16 @@ class ArgumentDecoders {
13691431
color: color(source, [...key, 'color']),
13701432
backgroundColor: color(source, [...key, 'backgroundColor']),
13711433
fontSize: source.v<double>([...key, 'fontSize']),
1372-
fontWeight: enumValue<FontWeight>(FontWeight.values, source, [...key, 'fontWeight']),
1434+
fontWeight: fontWeight(source, [...key, 'fontWeight']),
13731435
fontStyle: enumValue<FontStyle>(FontStyle.values, source, [...key, 'fontStyle']),
13741436
letterSpacing: source.v<double>([...key, 'letterSpacing']),
13751437
wordSpacing: source.v<double>([...key, 'wordSpacing']),
1376-
textBaseline: enumValue<TextBaseline>(TextBaseline.values, source, ['textBaseline']),
1438+
textBaseline: enumValue<TextBaseline>(TextBaseline.values, source, [...key, 'textBaseline']),
13771439
height: source.v<double>([...key, 'height']),
1378-
leadingDistribution: enumValue<TextLeadingDistribution>(TextLeadingDistribution.values, source, [...key, 'leadingDistribution']),
1440+
leadingDistribution: enumValue<TextLeadingDistribution>(TextLeadingDistribution.values, source, [
1441+
...key,
1442+
'leadingDistribution',
1443+
]),
13791444
locale: locale(source, [...key, 'locale']),
13801445
foreground: paint(source, [...key, 'foreground']),
13811446
background: paint(source, [...key, 'background']),
@@ -1387,7 +1452,7 @@ class ArgumentDecoders {
13871452
decorationThickness: source.v<double>([...key, 'decorationThickness']),
13881453
fontFamily: source.v<String>([...key, 'fontFamily']),
13891454
fontFamilyFallback: list<String>(source, [...key, 'fontFamilyFallback'], string),
1390-
overflow: enumValue<TextOverflow>(TextOverflow.values, source, ['overflow']),
1455+
overflow: enumValue<TextOverflow>(TextOverflow.values, source, [...key, 'overflow']),
13911456
);
13921457
}
13931458

0 commit comments

Comments
 (0)