diff --git a/examples/mirai_gallery/assets/json/table_example.json b/examples/mirai_gallery/assets/json/table_example.json index 3bb824c1..34e62504 100644 --- a/examples/mirai_gallery/assets/json/table_example.json +++ b/examples/mirai_gallery/assets/json/table_example.json @@ -17,11 +17,8 @@ "value": 1 }, "border": { - "type": "tableBorder", - "borderSide": { - "color": "#000000", - "width": 1.0 - } + "color": "#000000", + "width": 1.0 }, "children": [ { diff --git a/packages/mirai/lib/src/parsers/mirai_table/mirai_table.dart b/packages/mirai/lib/src/parsers/mirai_table/mirai_table.dart index 350d3d02..e63500d0 100644 --- a/packages/mirai/lib/src/parsers/mirai_table/mirai_table.dart +++ b/packages/mirai/lib/src/parsers/mirai_table/mirai_table.dart @@ -45,13 +45,10 @@ class MiraiTableRow with _$MiraiTableRow { @freezed class MiraiTableBorder with _$MiraiTableBorder { const factory MiraiTableBorder({ - MiraiBorderSide? top, - MiraiBorderSide? right, - MiraiBorderSide? bottom, - MiraiBorderSide? left, - MiraiBorderSide? horizontalInside, - MiraiBorderSide? verticalInside, - MiraiBorderRadius? borderRadius, + @Default('#000000') String color, + @Default(1.0) double width, + @Default(BorderStyle.solid) BorderStyle style, + @Default(MiraiBorderRadius()) MiraiBorderRadius borderRadius, }) = _MiraiTableBorder; factory MiraiTableBorder.fromJson(Map json) => diff --git a/packages/mirai/lib/src/parsers/mirai_table/mirai_table.freezed.dart b/packages/mirai/lib/src/parsers/mirai_table/mirai_table.freezed.dart index 1c7545d0..eebcc769 100644 --- a/packages/mirai/lib/src/parsers/mirai_table/mirai_table.freezed.dart +++ b/packages/mirai/lib/src/parsers/mirai_table/mirai_table.freezed.dart @@ -563,13 +563,10 @@ MiraiTableBorder _$MiraiTableBorderFromJson(Map json) { /// @nodoc mixin _$MiraiTableBorder { - MiraiBorderSide? get top => throw _privateConstructorUsedError; - MiraiBorderSide? get right => throw _privateConstructorUsedError; - MiraiBorderSide? get bottom => throw _privateConstructorUsedError; - MiraiBorderSide? get left => throw _privateConstructorUsedError; - MiraiBorderSide? get horizontalInside => throw _privateConstructorUsedError; - MiraiBorderSide? get verticalInside => throw _privateConstructorUsedError; - MiraiBorderRadius? get borderRadius => throw _privateConstructorUsedError; + String get color => throw _privateConstructorUsedError; + double get width => throw _privateConstructorUsedError; + BorderStyle get style => throw _privateConstructorUsedError; + MiraiBorderRadius get borderRadius => throw _privateConstructorUsedError; /// Serializes this MiraiTableBorder to a JSON map. Map toJson() => throw _privateConstructorUsedError; @@ -588,21 +585,12 @@ abstract class $MiraiTableBorderCopyWith<$Res> { _$MiraiTableBorderCopyWithImpl<$Res, MiraiTableBorder>; @useResult $Res call( - {MiraiBorderSide? top, - MiraiBorderSide? right, - MiraiBorderSide? bottom, - MiraiBorderSide? left, - MiraiBorderSide? horizontalInside, - MiraiBorderSide? verticalInside, - MiraiBorderRadius? borderRadius}); - - $MiraiBorderSideCopyWith<$Res>? get top; - $MiraiBorderSideCopyWith<$Res>? get right; - $MiraiBorderSideCopyWith<$Res>? get bottom; - $MiraiBorderSideCopyWith<$Res>? get left; - $MiraiBorderSideCopyWith<$Res>? get horizontalInside; - $MiraiBorderSideCopyWith<$Res>? get verticalInside; - $MiraiBorderRadiusCopyWith<$Res>? get borderRadius; + {String color, + double width, + BorderStyle style, + MiraiBorderRadius borderRadius}); + + $MiraiBorderRadiusCopyWith<$Res> get borderRadius; } /// @nodoc @@ -620,43 +608,28 @@ class _$MiraiTableBorderCopyWithImpl<$Res, $Val extends MiraiTableBorder> @pragma('vm:prefer-inline') @override $Res call({ - Object? top = freezed, - Object? right = freezed, - Object? bottom = freezed, - Object? left = freezed, - Object? horizontalInside = freezed, - Object? verticalInside = freezed, - Object? borderRadius = freezed, + Object? color = null, + Object? width = null, + Object? style = null, + Object? borderRadius = null, }) { return _then(_value.copyWith( - top: freezed == top - ? _value.top - : top // ignore: cast_nullable_to_non_nullable - as MiraiBorderSide?, - right: freezed == right - ? _value.right - : right // ignore: cast_nullable_to_non_nullable - as MiraiBorderSide?, - bottom: freezed == bottom - ? _value.bottom - : bottom // ignore: cast_nullable_to_non_nullable - as MiraiBorderSide?, - left: freezed == left - ? _value.left - : left // ignore: cast_nullable_to_non_nullable - as MiraiBorderSide?, - horizontalInside: freezed == horizontalInside - ? _value.horizontalInside - : horizontalInside // ignore: cast_nullable_to_non_nullable - as MiraiBorderSide?, - verticalInside: freezed == verticalInside - ? _value.verticalInside - : verticalInside // ignore: cast_nullable_to_non_nullable - as MiraiBorderSide?, - borderRadius: freezed == borderRadius + color: null == color + ? _value.color + : color // ignore: cast_nullable_to_non_nullable + as String, + width: null == width + ? _value.width + : width // ignore: cast_nullable_to_non_nullable + as double, + style: null == style + ? _value.style + : style // ignore: cast_nullable_to_non_nullable + as BorderStyle, + borderRadius: null == borderRadius ? _value.borderRadius : borderRadius // ignore: cast_nullable_to_non_nullable - as MiraiBorderRadius?, + as MiraiBorderRadius, ) as $Val); } @@ -664,96 +637,8 @@ class _$MiraiTableBorderCopyWithImpl<$Res, $Val extends MiraiTableBorder> /// with the given fields replaced by the non-null parameter values. @override @pragma('vm:prefer-inline') - $MiraiBorderSideCopyWith<$Res>? get top { - if (_value.top == null) { - return null; - } - - return $MiraiBorderSideCopyWith<$Res>(_value.top!, (value) { - return _then(_value.copyWith(top: value) as $Val); - }); - } - - /// Create a copy of MiraiTableBorder - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $MiraiBorderSideCopyWith<$Res>? get right { - if (_value.right == null) { - return null; - } - - return $MiraiBorderSideCopyWith<$Res>(_value.right!, (value) { - return _then(_value.copyWith(right: value) as $Val); - }); - } - - /// Create a copy of MiraiTableBorder - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $MiraiBorderSideCopyWith<$Res>? get bottom { - if (_value.bottom == null) { - return null; - } - - return $MiraiBorderSideCopyWith<$Res>(_value.bottom!, (value) { - return _then(_value.copyWith(bottom: value) as $Val); - }); - } - - /// Create a copy of MiraiTableBorder - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $MiraiBorderSideCopyWith<$Res>? get left { - if (_value.left == null) { - return null; - } - - return $MiraiBorderSideCopyWith<$Res>(_value.left!, (value) { - return _then(_value.copyWith(left: value) as $Val); - }); - } - - /// Create a copy of MiraiTableBorder - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $MiraiBorderSideCopyWith<$Res>? get horizontalInside { - if (_value.horizontalInside == null) { - return null; - } - - return $MiraiBorderSideCopyWith<$Res>(_value.horizontalInside!, (value) { - return _then(_value.copyWith(horizontalInside: value) as $Val); - }); - } - - /// Create a copy of MiraiTableBorder - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $MiraiBorderSideCopyWith<$Res>? get verticalInside { - if (_value.verticalInside == null) { - return null; - } - - return $MiraiBorderSideCopyWith<$Res>(_value.verticalInside!, (value) { - return _then(_value.copyWith(verticalInside: value) as $Val); - }); - } - - /// Create a copy of MiraiTableBorder - /// with the given fields replaced by the non-null parameter values. - @override - @pragma('vm:prefer-inline') - $MiraiBorderRadiusCopyWith<$Res>? get borderRadius { - if (_value.borderRadius == null) { - return null; - } - - return $MiraiBorderRadiusCopyWith<$Res>(_value.borderRadius!, (value) { + $MiraiBorderRadiusCopyWith<$Res> get borderRadius { + return $MiraiBorderRadiusCopyWith<$Res>(_value.borderRadius, (value) { return _then(_value.copyWith(borderRadius: value) as $Val); }); } @@ -768,28 +653,13 @@ abstract class _$$MiraiTableBorderImplCopyWith<$Res> @override @useResult $Res call( - {MiraiBorderSide? top, - MiraiBorderSide? right, - MiraiBorderSide? bottom, - MiraiBorderSide? left, - MiraiBorderSide? horizontalInside, - MiraiBorderSide? verticalInside, - MiraiBorderRadius? borderRadius}); + {String color, + double width, + BorderStyle style, + MiraiBorderRadius borderRadius}); @override - $MiraiBorderSideCopyWith<$Res>? get top; - @override - $MiraiBorderSideCopyWith<$Res>? get right; - @override - $MiraiBorderSideCopyWith<$Res>? get bottom; - @override - $MiraiBorderSideCopyWith<$Res>? get left; - @override - $MiraiBorderSideCopyWith<$Res>? get horizontalInside; - @override - $MiraiBorderSideCopyWith<$Res>? get verticalInside; - @override - $MiraiBorderRadiusCopyWith<$Res>? get borderRadius; + $MiraiBorderRadiusCopyWith<$Res> get borderRadius; } /// @nodoc @@ -805,43 +675,28 @@ class __$$MiraiTableBorderImplCopyWithImpl<$Res> @pragma('vm:prefer-inline') @override $Res call({ - Object? top = freezed, - Object? right = freezed, - Object? bottom = freezed, - Object? left = freezed, - Object? horizontalInside = freezed, - Object? verticalInside = freezed, - Object? borderRadius = freezed, + Object? color = null, + Object? width = null, + Object? style = null, + Object? borderRadius = null, }) { return _then(_$MiraiTableBorderImpl( - top: freezed == top - ? _value.top - : top // ignore: cast_nullable_to_non_nullable - as MiraiBorderSide?, - right: freezed == right - ? _value.right - : right // ignore: cast_nullable_to_non_nullable - as MiraiBorderSide?, - bottom: freezed == bottom - ? _value.bottom - : bottom // ignore: cast_nullable_to_non_nullable - as MiraiBorderSide?, - left: freezed == left - ? _value.left - : left // ignore: cast_nullable_to_non_nullable - as MiraiBorderSide?, - horizontalInside: freezed == horizontalInside - ? _value.horizontalInside - : horizontalInside // ignore: cast_nullable_to_non_nullable - as MiraiBorderSide?, - verticalInside: freezed == verticalInside - ? _value.verticalInside - : verticalInside // ignore: cast_nullable_to_non_nullable - as MiraiBorderSide?, - borderRadius: freezed == borderRadius + color: null == color + ? _value.color + : color // ignore: cast_nullable_to_non_nullable + as String, + width: null == width + ? _value.width + : width // ignore: cast_nullable_to_non_nullable + as double, + style: null == style + ? _value.style + : style // ignore: cast_nullable_to_non_nullable + as BorderStyle, + borderRadius: null == borderRadius ? _value.borderRadius : borderRadius // ignore: cast_nullable_to_non_nullable - as MiraiBorderRadius?, + as MiraiBorderRadius, )); } } @@ -850,35 +705,30 @@ class __$$MiraiTableBorderImplCopyWithImpl<$Res> @JsonSerializable() class _$MiraiTableBorderImpl implements _MiraiTableBorder { const _$MiraiTableBorderImpl( - {this.top, - this.right, - this.bottom, - this.left, - this.horizontalInside, - this.verticalInside, - this.borderRadius}); + {this.color = '#000000', + this.width = 1.0, + this.style = BorderStyle.solid, + this.borderRadius = const MiraiBorderRadius()}); factory _$MiraiTableBorderImpl.fromJson(Map json) => _$$MiraiTableBorderImplFromJson(json); @override - final MiraiBorderSide? top; - @override - final MiraiBorderSide? right; - @override - final MiraiBorderSide? bottom; - @override - final MiraiBorderSide? left; + @JsonKey() + final String color; @override - final MiraiBorderSide? horizontalInside; + @JsonKey() + final double width; @override - final MiraiBorderSide? verticalInside; + @JsonKey() + final BorderStyle style; @override - final MiraiBorderRadius? borderRadius; + @JsonKey() + final MiraiBorderRadius borderRadius; @override String toString() { - return 'MiraiTableBorder(top: $top, right: $right, bottom: $bottom, left: $left, horizontalInside: $horizontalInside, verticalInside: $verticalInside, borderRadius: $borderRadius)'; + return 'MiraiTableBorder(color: $color, width: $width, style: $style, borderRadius: $borderRadius)'; } @override @@ -886,22 +736,17 @@ class _$MiraiTableBorderImpl implements _MiraiTableBorder { return identical(this, other) || (other.runtimeType == runtimeType && other is _$MiraiTableBorderImpl && - (identical(other.top, top) || other.top == top) && - (identical(other.right, right) || other.right == right) && - (identical(other.bottom, bottom) || other.bottom == bottom) && - (identical(other.left, left) || other.left == left) && - (identical(other.horizontalInside, horizontalInside) || - other.horizontalInside == horizontalInside) && - (identical(other.verticalInside, verticalInside) || - other.verticalInside == verticalInside) && + (identical(other.color, color) || other.color == color) && + (identical(other.width, width) || other.width == width) && + (identical(other.style, style) || other.style == style) && (identical(other.borderRadius, borderRadius) || other.borderRadius == borderRadius)); } @JsonKey(includeFromJson: false, includeToJson: false) @override - int get hashCode => Object.hash(runtimeType, top, right, bottom, left, - horizontalInside, verticalInside, borderRadius); + int get hashCode => + Object.hash(runtimeType, color, width, style, borderRadius); /// Create a copy of MiraiTableBorder /// with the given fields replaced by the non-null parameter values. @@ -922,31 +767,22 @@ class _$MiraiTableBorderImpl implements _MiraiTableBorder { abstract class _MiraiTableBorder implements MiraiTableBorder { const factory _MiraiTableBorder( - {final MiraiBorderSide? top, - final MiraiBorderSide? right, - final MiraiBorderSide? bottom, - final MiraiBorderSide? left, - final MiraiBorderSide? horizontalInside, - final MiraiBorderSide? verticalInside, - final MiraiBorderRadius? borderRadius}) = _$MiraiTableBorderImpl; + {final String color, + final double width, + final BorderStyle style, + final MiraiBorderRadius borderRadius}) = _$MiraiTableBorderImpl; factory _MiraiTableBorder.fromJson(Map json) = _$MiraiTableBorderImpl.fromJson; @override - MiraiBorderSide? get top; - @override - MiraiBorderSide? get right; - @override - MiraiBorderSide? get bottom; - @override - MiraiBorderSide? get left; + String get color; @override - MiraiBorderSide? get horizontalInside; + double get width; @override - MiraiBorderSide? get verticalInside; + BorderStyle get style; @override - MiraiBorderRadius? get borderRadius; + MiraiBorderRadius get borderRadius; /// Create a copy of MiraiTableBorder /// with the given fields replaced by the non-null parameter values. diff --git a/packages/mirai/lib/src/parsers/mirai_table/mirai_table.g.dart b/packages/mirai/lib/src/parsers/mirai_table/mirai_table.g.dart index 6182275c..d24e04e0 100644 --- a/packages/mirai/lib/src/parsers/mirai_table/mirai_table.g.dart +++ b/packages/mirai/lib/src/parsers/mirai_table/mirai_table.g.dart @@ -86,43 +86,29 @@ Map _$$MiraiTableRowImplToJson(_$MiraiTableRowImpl instance) => _$MiraiTableBorderImpl _$$MiraiTableBorderImplFromJson( Map json) => _$MiraiTableBorderImpl( - top: json['top'] == null - ? null - : MiraiBorderSide.fromJson(json['top'] as Map), - right: json['right'] == null - ? null - : MiraiBorderSide.fromJson(json['right'] as Map), - bottom: json['bottom'] == null - ? null - : MiraiBorderSide.fromJson(json['bottom'] as Map), - left: json['left'] == null - ? null - : MiraiBorderSide.fromJson(json['left'] as Map), - horizontalInside: json['horizontalInside'] == null - ? null - : MiraiBorderSide.fromJson( - json['horizontalInside'] as Map), - verticalInside: json['verticalInside'] == null - ? null - : MiraiBorderSide.fromJson( - json['verticalInside'] as Map), + color: json['color'] as String? ?? '#000000', + width: (json['width'] as num?)?.toDouble() ?? 1.0, + style: $enumDecodeNullable(_$BorderStyleEnumMap, json['style']) ?? + BorderStyle.solid, borderRadius: json['borderRadius'] == null - ? null + ? const MiraiBorderRadius() : MiraiBorderRadius.fromJson(json['borderRadius']), ); Map _$$MiraiTableBorderImplToJson( _$MiraiTableBorderImpl instance) => { - 'top': instance.top, - 'right': instance.right, - 'bottom': instance.bottom, - 'left': instance.left, - 'horizontalInside': instance.horizontalInside, - 'verticalInside': instance.verticalInside, + 'color': instance.color, + 'width': instance.width, + 'style': _$BorderStyleEnumMap[instance.style]!, 'borderRadius': instance.borderRadius, }; +const _$BorderStyleEnumMap = { + BorderStyle.none: 'none', + BorderStyle.solid: 'solid', +}; + _$MiraiTableColumnWidthImpl _$$MiraiTableColumnWidthImplFromJson( Map json) => _$MiraiTableColumnWidthImpl( diff --git a/packages/mirai/lib/src/parsers/mirai_table/mirai_table_parser.dart b/packages/mirai/lib/src/parsers/mirai_table/mirai_table_parser.dart index 5b87bab1..51af2e0a 100644 --- a/packages/mirai/lib/src/parsers/mirai_table/mirai_table_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_table/mirai_table_parser.dart @@ -41,13 +41,10 @@ extension MiraiTableRowParser on MiraiTableRow { extension MiraiTableBorderParser on MiraiTableBorder { TableBorder parse(BuildContext context) { - return TableBorder( - top: top.parse(context), - right: right.parse(context), - bottom: bottom.parse(context), - left: left.parse(context), - horizontalInside: horizontalInside.parse(context), - verticalInside: verticalInside.parse(context), + return TableBorder.all( + color: color.toColor(context) ?? Colors.black, + width: width, + style: style, borderRadius: borderRadius.parse, ); } diff --git a/website/docs/styles/border_radius.md b/website/docs/styles/border_radius.md index 5c6c8026..5d1aa783 100644 --- a/website/docs/styles/border_radius.md +++ b/website/docs/styles/border_radius.md @@ -19,13 +19,14 @@ Above three properties defined are optional. i.e. `MiraiBorderRadius` can be def ## Example -```json // Generic Declaration +```json { "borderRadius": 16.0 } - +``` // Explicit Declaration +```json { "borderRadius": { "topLeft": 16.0, @@ -34,14 +35,16 @@ Above three properties defined are optional. i.e. `MiraiBorderRadius` can be def "bottomRight": 16.0 } } +``` // Explicit Declaration (List) +```json { "borderRadius": [ - 16.0, //topLeft - 16.0, //topRight - 16.0, //bottomLeft - 16.0, //bottomRight + 16.0, + 16.0, + 16.0, + 16.0 ] } ``` \ No newline at end of file diff --git a/website/docs/styles/table_border.md b/website/docs/styles/table_border.md index 37adb39f..654f82a3 100644 --- a/website/docs/styles/table_border.md +++ b/website/docs/styles/table_border.md @@ -5,44 +5,28 @@ To know more about the TableBorder class in Flutter, refer to the [official docu ## Properties -| Property | Type | Description | -| ---------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | -| top | `MiraiBorderSide?` | Defines the top border of the table. See [`MiraiBorderSide`](./../styles_and_attributes/border_side). | -| right | `MiraiBorderSide?` | Defines the right border of the table. See [`MiraiBorderSide`](./../styles_and_attributes/border_side). | -| bottom | `MiraiBorderSide?` | Defines the bottom border of the table. See [`MiraiBorderSide`](./../styles_and_attributes/border_side). | -| left | `MiraiBorderSide?` | Defines the left border of the table. See [`MiraiBorderSide`](./../styles_and_attributes/border_side). | -| horizontalInside | `MiraiBorderSide?` | Defines the inner horizontal borders of the table. See [`MiraiBorderSide`](./../styles_and_attributes/border_side). | -| verticalInside | `MiraiBorderSide?` | Defines the inner vertical borders of the table. See [`MiraiBorderSide`](./../styles_and_attributes/border_side). | -| borderRadius | `MiraiBorderRadius?` | Defines the border radius to be used while rendering table corners. See [`MiraiBorderRadius`](./../styles_and_attributes/border_radius) | +| Property | Type | Description | +|--------------|---------------------|------------------------------------------------| +| color | `String` | Defines the color of the table border. | +| width | `double` | Defines the width of the table border. | +| style | `BorderStyle` | Defines the style of the table border. | +| borderRadius | `MiraiBorderRadius` | Defines the border radius of the table border. | + ## Example ```json { - "border": { - "type": "tableBorder", - "top": { - "color": "#428AF5", - "width": 1.0 - }, - "right": { - "color": "#428AF5", - "width": 1.0 - }, - "bottom": { - "color": "#428AF5", - "width": 1.0 - }, - "left": { - "color": "#428AF5", - "width": 1.0 - }, - "borderRadius": { - "topLeft": 16, - "topRight": 16, - "bottomLeft": 16, - "bottomRight": 16, + "tableBorder": { + "color": "#000000", + "width": 1.0, + "style": "solid", + "borderRadius": { + "topLeft": 16.0, + "topRight": 16.0, + "bottomLeft": 16.0, + "bottomRight": 16.0 + } } - }, } ``` \ No newline at end of file