Skip to content

Commit

Permalink
Added fontFamily and fontfamilyFallback in Mirai text style
Browse files Browse the repository at this point in the history
  • Loading branch information
i-asimkhan committed Jul 26, 2023
1 parent 0b20cf1 commit 81aabd2
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 26 deletions.
13 changes: 9 additions & 4 deletions examples/mirai_gallery/assets/json/text_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class MiraiTextStyle with _$MiraiTextStyle {
double? fontSize,
MiraiFontWeight? fontWeight,
FontStyle? fontStyle,
String? fontFamily,
List<String>? fontFamilyFallback,
double? letterSpacing,
double? wordSpacing,
TextBaseline? textBaseline,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>? get fontFamilyFallback => throw _privateConstructorUsedError;
double? get letterSpacing => throw _privateConstructorUsedError;
double? get wordSpacing => throw _privateConstructorUsedError;
TextBaseline? get textBaseline => throw _privateConstructorUsedError;
Expand All @@ -50,6 +52,8 @@ abstract class $MiraiTextStyleCopyWith<$Res> {
double? fontSize,
MiraiFontWeight? fontWeight,
FontStyle? fontStyle,
String? fontFamily,
List<String>? fontFamilyFallback,
double? letterSpacing,
double? wordSpacing,
TextBaseline? textBaseline,
Expand All @@ -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,
Expand Down Expand Up @@ -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<String>?,
letterSpacing: freezed == letterSpacing
? _value.letterSpacing
: letterSpacing // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -140,6 +154,8 @@ abstract class _$$_MiraiTextStyleCopyWith<$Res>
double? fontSize,
MiraiFontWeight? fontWeight,
FontStyle? fontStyle,
String? fontFamily,
List<String>? fontFamilyFallback,
double? letterSpacing,
double? wordSpacing,
TextBaseline? textBaseline,
Expand All @@ -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,
Expand Down Expand Up @@ -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<String>?,
letterSpacing: freezed == letterSpacing
? _value.letterSpacing
: letterSpacing // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -223,10 +249,13 @@ class _$_MiraiTextStyle implements _MiraiTextStyle {
this.fontSize,
this.fontWeight,
this.fontStyle,
this.fontFamily,
final List<String>? fontFamilyFallback,
this.letterSpacing,
this.wordSpacing,
this.textBaseline,
this.height});
this.height})
: _fontFamilyFallback = fontFamilyFallback;

factory _$_MiraiTextStyle.fromJson(Map<String, dynamic> json) =>
_$$_MiraiTextStyleFromJson(json);
Expand All @@ -244,6 +273,19 @@ class _$_MiraiTextStyle implements _MiraiTextStyle {
final MiraiFontWeight? fontWeight;
@override
final FontStyle? fontStyle;
@override
final String? fontFamily;
final List<String>? _fontFamilyFallback;
@override
List<String>? 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
Expand All @@ -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
Expand All @@ -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) ||
Expand All @@ -292,6 +338,8 @@ class _$_MiraiTextStyle implements _MiraiTextStyle {
fontSize,
fontWeight,
fontStyle,
fontFamily,
const DeepCollectionEquality().hash(_fontFamilyFallback),
letterSpacing,
wordSpacing,
textBaseline,
Expand Down Expand Up @@ -319,6 +367,8 @@ abstract class _MiraiTextStyle implements MiraiTextStyle {
final double? fontSize,
final MiraiFontWeight? fontWeight,
final FontStyle? fontStyle,
final String? fontFamily,
final List<String>? fontFamilyFallback,
final double? letterSpacing,
final double? wordSpacing,
final TextBaseline? textBaseline,
Expand All @@ -340,6 +390,10 @@ abstract class _MiraiTextStyle implements MiraiTextStyle {
@override
FontStyle? get fontStyle;
@override
String? get fontFamily;
@override
List<String>? get fontFamilyFallback;
@override
double? get letterSpacing;
@override
double? get wordSpacing;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MiraiTheme with _$MiraiTheme {
String? splashColor,
String? unselectedWidgetColor,
String? fontFamily,
@Default([]) List<String> fontFamilyFallback,
List<String>? fontFamilyFallback,
MiraiAppBarTheme? appBarTheme,
MiraiButtonStyle? elevatedButtonTheme,
MiraiButtonStyle? outlinedButtonTheme,
Expand Down
33 changes: 17 additions & 16 deletions packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mixin _$MiraiTheme {
String? get splashColor => throw _privateConstructorUsedError;
String? get unselectedWidgetColor => throw _privateConstructorUsedError;
String? get fontFamily => throw _privateConstructorUsedError;
List<String> get fontFamilyFallback => throw _privateConstructorUsedError;
List<String>? get fontFamilyFallback => throw _privateConstructorUsedError;
MiraiAppBarTheme? get appBarTheme => throw _privateConstructorUsedError;
MiraiButtonStyle? get elevatedButtonTheme =>
throw _privateConstructorUsedError;
Expand Down Expand Up @@ -113,7 +113,7 @@ abstract class $MiraiThemeCopyWith<$Res> {
String? splashColor,
String? unselectedWidgetColor,
String? fontFamily,
List<String> fontFamilyFallback,
List<String>? fontFamilyFallback,
MiraiAppBarTheme? appBarTheme,
MiraiButtonStyle? elevatedButtonTheme,
MiraiButtonStyle? outlinedButtonTheme,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<String>,
as List<String>?,
appBarTheme: freezed == appBarTheme
? _value.appBarTheme
: appBarTheme // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -660,7 +660,7 @@ abstract class _$$_MiraiThemeCopyWith<$Res>
String? splashColor,
String? unselectedWidgetColor,
String? fontFamily,
List<String> fontFamilyFallback,
List<String>? fontFamilyFallback,
MiraiAppBarTheme? appBarTheme,
MiraiButtonStyle? elevatedButtonTheme,
MiraiButtonStyle? outlinedButtonTheme,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<String>,
as List<String>?,
appBarTheme: freezed == appBarTheme
? _value.appBarTheme
: appBarTheme // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -981,7 +981,7 @@ class _$_MiraiTheme implements _MiraiTheme {
this.splashColor,
this.unselectedWidgetColor,
this.fontFamily,
final List<String> fontFamilyFallback = const [],
final List<String>? fontFamilyFallback,
this.appBarTheme,
this.elevatedButtonTheme,
this.outlinedButtonTheme,
Expand Down Expand Up @@ -1055,14 +1055,15 @@ class _$_MiraiTheme implements _MiraiTheme {
final String? unselectedWidgetColor;
@override
final String? fontFamily;
final List<String> _fontFamilyFallback;
final List<String>? _fontFamilyFallback;
@override
@JsonKey()
List<String> get fontFamilyFallback {
List<String>? 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
Expand Down Expand Up @@ -1277,7 +1278,7 @@ abstract class _MiraiTheme implements MiraiTheme {
final String? splashColor,
final String? unselectedWidgetColor,
final String? fontFamily,
final List<String> fontFamilyFallback,
final List<String>? fontFamilyFallback,
final MiraiAppBarTheme? appBarTheme,
final MiraiButtonStyle? elevatedButtonTheme,
final MiraiButtonStyle? outlinedButtonTheme,
Expand Down Expand Up @@ -1351,7 +1352,7 @@ abstract class _MiraiTheme implements MiraiTheme {
@override
String? get fontFamily;
@override
List<String> get fontFamilyFallback;
List<String>? get fontFamilyFallback;
@override
MiraiAppBarTheme? get appBarTheme;
@override
Expand Down
5 changes: 2 additions & 3 deletions packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 81aabd2

Please sign in to comment.