diff --git a/examples/mirai_gallery/assets/json/text_example.json b/examples/mirai_gallery/assets/json/text_example.json index 6202369a..8b5ec7b3 100644 --- a/examples/mirai_gallery/assets/json/text_example.json +++ b/examples/mirai_gallery/assets/json/text_example.json @@ -29,20 +29,25 @@ "align": "center", "style": { "fontSize": 23, - "fontWeight": "w600" + "fontWeight": "w600", + "fontFamily": "Handjet" } }, { "type": "sizedBox", - "height": 32 + "height": 24 }, { "type": "text", - "data": "This is a normal Text." + "data": "This is a normal Text.", + "style": { + "fontSize": 14, + "fontFamily": "LisuBosa" + } }, { "type": "sizedBox", - "height": 16 + "height": 8 }, { "type": "text", diff --git a/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.dart b/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.dart index 2bddd158..449f0120 100644 --- a/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.dart +++ b/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.dart @@ -15,6 +15,8 @@ class MiraiTextStyle with _$MiraiTextStyle { double? fontSize, MiraiFontWeight? fontWeight, FontStyle? fontStyle, + String? fontFamily, + List? fontFamilyFallback, double? letterSpacing, double? wordSpacing, TextBaseline? textBaseline, @@ -34,6 +36,8 @@ extension MiraiTextStyleParser on MiraiTextStyle { fontSize: fontSize, fontWeight: fontWeight?.value, fontStyle: fontStyle, + fontFamily: fontFamily, + fontFamilyFallback: fontFamilyFallback, letterSpacing: letterSpacing, wordSpacing: wordSpacing, textBaseline: textBaseline, diff --git a/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.freezed.dart b/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.freezed.dart index 32a1f994..8aba930b 100644 --- a/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.freezed.dart +++ b/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.freezed.dart @@ -26,6 +26,8 @@ mixin _$MiraiTextStyle { double? get fontSize => throw _privateConstructorUsedError; MiraiFontWeight? get fontWeight => throw _privateConstructorUsedError; FontStyle? get fontStyle => throw _privateConstructorUsedError; + String? get fontFamily => throw _privateConstructorUsedError; + List? get fontFamilyFallback => throw _privateConstructorUsedError; double? get letterSpacing => throw _privateConstructorUsedError; double? get wordSpacing => throw _privateConstructorUsedError; TextBaseline? get textBaseline => throw _privateConstructorUsedError; @@ -50,6 +52,8 @@ abstract class $MiraiTextStyleCopyWith<$Res> { double? fontSize, MiraiFontWeight? fontWeight, FontStyle? fontStyle, + String? fontFamily, + List? fontFamilyFallback, double? letterSpacing, double? wordSpacing, TextBaseline? textBaseline, @@ -75,6 +79,8 @@ class _$MiraiTextStyleCopyWithImpl<$Res, $Val extends MiraiTextStyle> Object? fontSize = freezed, Object? fontWeight = freezed, Object? fontStyle = freezed, + Object? fontFamily = freezed, + Object? fontFamilyFallback = freezed, Object? letterSpacing = freezed, Object? wordSpacing = freezed, Object? textBaseline = freezed, @@ -105,6 +111,14 @@ class _$MiraiTextStyleCopyWithImpl<$Res, $Val extends MiraiTextStyle> ? _value.fontStyle : fontStyle // ignore: cast_nullable_to_non_nullable as FontStyle?, + fontFamily: freezed == fontFamily + ? _value.fontFamily + : fontFamily // ignore: cast_nullable_to_non_nullable + as String?, + fontFamilyFallback: freezed == fontFamilyFallback + ? _value.fontFamilyFallback + : fontFamilyFallback // ignore: cast_nullable_to_non_nullable + as List?, letterSpacing: freezed == letterSpacing ? _value.letterSpacing : letterSpacing // ignore: cast_nullable_to_non_nullable @@ -140,6 +154,8 @@ abstract class _$$_MiraiTextStyleCopyWith<$Res> double? fontSize, MiraiFontWeight? fontWeight, FontStyle? fontStyle, + String? fontFamily, + List? fontFamilyFallback, double? letterSpacing, double? wordSpacing, TextBaseline? textBaseline, @@ -163,6 +179,8 @@ class __$$_MiraiTextStyleCopyWithImpl<$Res> Object? fontSize = freezed, Object? fontWeight = freezed, Object? fontStyle = freezed, + Object? fontFamily = freezed, + Object? fontFamilyFallback = freezed, Object? letterSpacing = freezed, Object? wordSpacing = freezed, Object? textBaseline = freezed, @@ -193,6 +211,14 @@ class __$$_MiraiTextStyleCopyWithImpl<$Res> ? _value.fontStyle : fontStyle // ignore: cast_nullable_to_non_nullable as FontStyle?, + fontFamily: freezed == fontFamily + ? _value.fontFamily + : fontFamily // ignore: cast_nullable_to_non_nullable + as String?, + fontFamilyFallback: freezed == fontFamilyFallback + ? _value._fontFamilyFallback + : fontFamilyFallback // ignore: cast_nullable_to_non_nullable + as List?, letterSpacing: freezed == letterSpacing ? _value.letterSpacing : letterSpacing // ignore: cast_nullable_to_non_nullable @@ -223,10 +249,13 @@ class _$_MiraiTextStyle implements _MiraiTextStyle { this.fontSize, this.fontWeight, this.fontStyle, + this.fontFamily, + final List? fontFamilyFallback, this.letterSpacing, this.wordSpacing, this.textBaseline, - this.height}); + this.height}) + : _fontFamilyFallback = fontFamilyFallback; factory _$_MiraiTextStyle.fromJson(Map json) => _$$_MiraiTextStyleFromJson(json); @@ -244,6 +273,19 @@ class _$_MiraiTextStyle implements _MiraiTextStyle { final MiraiFontWeight? fontWeight; @override final FontStyle? fontStyle; + @override + final String? fontFamily; + final List? _fontFamilyFallback; + @override + List? get fontFamilyFallback { + final value = _fontFamilyFallback; + if (value == null) return null; + if (_fontFamilyFallback is EqualUnmodifiableListView) + return _fontFamilyFallback; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(value); + } + @override final double? letterSpacing; @override @@ -255,7 +297,7 @@ class _$_MiraiTextStyle implements _MiraiTextStyle { @override String toString() { - return 'MiraiTextStyle(inherit: $inherit, color: $color, backgroundColor: $backgroundColor, fontSize: $fontSize, fontWeight: $fontWeight, fontStyle: $fontStyle, letterSpacing: $letterSpacing, wordSpacing: $wordSpacing, textBaseline: $textBaseline, height: $height)'; + return 'MiraiTextStyle(inherit: $inherit, color: $color, backgroundColor: $backgroundColor, fontSize: $fontSize, fontWeight: $fontWeight, fontStyle: $fontStyle, fontFamily: $fontFamily, fontFamilyFallback: $fontFamilyFallback, letterSpacing: $letterSpacing, wordSpacing: $wordSpacing, textBaseline: $textBaseline, height: $height)'; } @override @@ -273,6 +315,10 @@ class _$_MiraiTextStyle implements _MiraiTextStyle { other.fontWeight == fontWeight) && (identical(other.fontStyle, fontStyle) || other.fontStyle == fontStyle) && + (identical(other.fontFamily, fontFamily) || + other.fontFamily == fontFamily) && + const DeepCollectionEquality() + .equals(other._fontFamilyFallback, _fontFamilyFallback) && (identical(other.letterSpacing, letterSpacing) || other.letterSpacing == letterSpacing) && (identical(other.wordSpacing, wordSpacing) || @@ -292,6 +338,8 @@ class _$_MiraiTextStyle implements _MiraiTextStyle { fontSize, fontWeight, fontStyle, + fontFamily, + const DeepCollectionEquality().hash(_fontFamilyFallback), letterSpacing, wordSpacing, textBaseline, @@ -319,6 +367,8 @@ abstract class _MiraiTextStyle implements MiraiTextStyle { final double? fontSize, final MiraiFontWeight? fontWeight, final FontStyle? fontStyle, + final String? fontFamily, + final List? fontFamilyFallback, final double? letterSpacing, final double? wordSpacing, final TextBaseline? textBaseline, @@ -340,6 +390,10 @@ abstract class _MiraiTextStyle implements MiraiTextStyle { @override FontStyle? get fontStyle; @override + String? get fontFamily; + @override + List? get fontFamilyFallback; + @override double? get letterSpacing; @override double? get wordSpacing; diff --git a/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.g.dart b/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.g.dart index 8b59a89d..7a797c3e 100644 --- a/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.g.dart +++ b/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.g.dart @@ -15,6 +15,10 @@ _$_MiraiTextStyle _$$_MiraiTextStyleFromJson(Map json) => fontWeight: $enumDecodeNullable(_$MiraiFontWeightEnumMap, json['fontWeight']), fontStyle: $enumDecodeNullable(_$FontStyleEnumMap, json['fontStyle']), + fontFamily: json['fontFamily'] as String?, + fontFamilyFallback: (json['fontFamilyFallback'] as List?) + ?.map((e) => e as String) + .toList(), letterSpacing: (json['letterSpacing'] as num?)?.toDouble(), wordSpacing: (json['wordSpacing'] as num?)?.toDouble(), textBaseline: @@ -30,6 +34,8 @@ Map _$$_MiraiTextStyleToJson(_$_MiraiTextStyle instance) => 'fontSize': instance.fontSize, 'fontWeight': _$MiraiFontWeightEnumMap[instance.fontWeight], 'fontStyle': _$FontStyleEnumMap[instance.fontStyle], + 'fontFamily': instance.fontFamily, + 'fontFamilyFallback': instance.fontFamilyFallback, 'letterSpacing': instance.letterSpacing, 'wordSpacing': instance.wordSpacing, 'textBaseline': _$TextBaselineEnumMap[instance.textBaseline], diff --git a/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.dart b/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.dart index 61d9c1e3..0ba4972b 100644 --- a/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.dart +++ b/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.dart @@ -41,7 +41,7 @@ class MiraiTheme with _$MiraiTheme { String? splashColor, String? unselectedWidgetColor, String? fontFamily, - @Default([]) List fontFamilyFallback, + List? fontFamilyFallback, MiraiAppBarTheme? appBarTheme, MiraiButtonStyle? elevatedButtonTheme, MiraiButtonStyle? outlinedButtonTheme, diff --git a/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.freezed.dart b/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.freezed.dart index d21855ef..4e35f8b0 100644 --- a/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.freezed.dart +++ b/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.freezed.dart @@ -47,7 +47,7 @@ mixin _$MiraiTheme { String? get splashColor => throw _privateConstructorUsedError; String? get unselectedWidgetColor => throw _privateConstructorUsedError; String? get fontFamily => throw _privateConstructorUsedError; - List get fontFamilyFallback => throw _privateConstructorUsedError; + List? get fontFamilyFallback => throw _privateConstructorUsedError; MiraiAppBarTheme? get appBarTheme => throw _privateConstructorUsedError; MiraiButtonStyle? get elevatedButtonTheme => throw _privateConstructorUsedError; @@ -113,7 +113,7 @@ abstract class $MiraiThemeCopyWith<$Res> { String? splashColor, String? unselectedWidgetColor, String? fontFamily, - List fontFamilyFallback, + List? fontFamilyFallback, MiraiAppBarTheme? appBarTheme, MiraiButtonStyle? elevatedButtonTheme, MiraiButtonStyle? outlinedButtonTheme, @@ -192,7 +192,7 @@ class _$MiraiThemeCopyWithImpl<$Res, $Val extends MiraiTheme> Object? splashColor = freezed, Object? unselectedWidgetColor = freezed, Object? fontFamily = freezed, - Object? fontFamilyFallback = null, + Object? fontFamilyFallback = freezed, Object? appBarTheme = freezed, Object? elevatedButtonTheme = freezed, Object? outlinedButtonTheme = freezed, @@ -315,10 +315,10 @@ class _$MiraiThemeCopyWithImpl<$Res, $Val extends MiraiTheme> ? _value.fontFamily : fontFamily // ignore: cast_nullable_to_non_nullable as String?, - fontFamilyFallback: null == fontFamilyFallback + fontFamilyFallback: freezed == fontFamilyFallback ? _value.fontFamilyFallback : fontFamilyFallback // ignore: cast_nullable_to_non_nullable - as List, + as List?, appBarTheme: freezed == appBarTheme ? _value.appBarTheme : appBarTheme // ignore: cast_nullable_to_non_nullable @@ -660,7 +660,7 @@ abstract class _$$_MiraiThemeCopyWith<$Res> String? splashColor, String? unselectedWidgetColor, String? fontFamily, - List fontFamilyFallback, + List? fontFamilyFallback, MiraiAppBarTheme? appBarTheme, MiraiButtonStyle? elevatedButtonTheme, MiraiButtonStyle? outlinedButtonTheme, @@ -756,7 +756,7 @@ class __$$_MiraiThemeCopyWithImpl<$Res> Object? splashColor = freezed, Object? unselectedWidgetColor = freezed, Object? fontFamily = freezed, - Object? fontFamilyFallback = null, + Object? fontFamilyFallback = freezed, Object? appBarTheme = freezed, Object? elevatedButtonTheme = freezed, Object? outlinedButtonTheme = freezed, @@ -879,10 +879,10 @@ class __$$_MiraiThemeCopyWithImpl<$Res> ? _value.fontFamily : fontFamily // ignore: cast_nullable_to_non_nullable as String?, - fontFamilyFallback: null == fontFamilyFallback + fontFamilyFallback: freezed == fontFamilyFallback ? _value._fontFamilyFallback : fontFamilyFallback // ignore: cast_nullable_to_non_nullable - as List, + as List?, appBarTheme: freezed == appBarTheme ? _value.appBarTheme : appBarTheme // ignore: cast_nullable_to_non_nullable @@ -981,7 +981,7 @@ class _$_MiraiTheme implements _MiraiTheme { this.splashColor, this.unselectedWidgetColor, this.fontFamily, - final List fontFamilyFallback = const [], + final List? fontFamilyFallback, this.appBarTheme, this.elevatedButtonTheme, this.outlinedButtonTheme, @@ -1055,14 +1055,15 @@ class _$_MiraiTheme implements _MiraiTheme { final String? unselectedWidgetColor; @override final String? fontFamily; - final List _fontFamilyFallback; + final List? _fontFamilyFallback; @override - @JsonKey() - List get fontFamilyFallback { + List? get fontFamilyFallback { + final value = _fontFamilyFallback; + if (value == null) return null; if (_fontFamilyFallback is EqualUnmodifiableListView) return _fontFamilyFallback; // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_fontFamilyFallback); + return EqualUnmodifiableListView(value); } @override @@ -1277,7 +1278,7 @@ abstract class _MiraiTheme implements MiraiTheme { final String? splashColor, final String? unselectedWidgetColor, final String? fontFamily, - final List fontFamilyFallback, + final List? fontFamilyFallback, final MiraiAppBarTheme? appBarTheme, final MiraiButtonStyle? elevatedButtonTheme, final MiraiButtonStyle? outlinedButtonTheme, @@ -1351,7 +1352,7 @@ abstract class _MiraiTheme implements MiraiTheme { @override String? get fontFamily; @override - List get fontFamilyFallback; + List? get fontFamilyFallback; @override MiraiAppBarTheme? get appBarTheme; @override diff --git a/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.g.dart b/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.g.dart index a4634142..43106812 100644 --- a/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.g.dart +++ b/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.g.dart @@ -44,9 +44,8 @@ _$_MiraiTheme _$$_MiraiThemeFromJson(Map json) => unselectedWidgetColor: json['unselectedWidgetColor'] as String?, fontFamily: json['fontFamily'] as String?, fontFamilyFallback: (json['fontFamilyFallback'] as List?) - ?.map((e) => e as String) - .toList() ?? - const [], + ?.map((e) => e as String) + .toList(), appBarTheme: json['appBarTheme'] == null ? null : MiraiAppBarTheme.fromJson(