diff --git a/examples/mirai_gallery/assets/json/aspect_ratio_example.json b/examples/mirai_gallery/assets/json/aspect_ratio_example.json new file mode 100644 index 00000000..252f8bf3 --- /dev/null +++ b/examples/mirai_gallery/assets/json/aspect_ratio_example.json @@ -0,0 +1,39 @@ +{ + "type": "scaffold", + "appBar": { + "type": "appBar", + "title": { + "type": "text", + "data": "AspectRatio" + } + }, + "body": { + "type": "padding", + "padding": { + "top": 12, + "left": 12, + "right": 12 + }, + "child": { + "type": "column", + "mainAxisAlignment": "start", + "crossAxisAlignment": "start", + "children": [ + { + "type": "sizedBox", + "height": 12 + }, + { + "type": "aspectRatio", + "aspectRatio": 1.33, + "child": { + "type": "container", + "color": "#FF5733", + "width": 100, + "height": 100 + } + } + ] + } + } +} \ No newline at end of file diff --git a/examples/mirai_gallery/assets/json/fitted_box_example.json b/examples/mirai_gallery/assets/json/fitted_box_example.json new file mode 100644 index 00000000..3107fbe6 --- /dev/null +++ b/examples/mirai_gallery/assets/json/fitted_box_example.json @@ -0,0 +1,42 @@ +{ + "type": "scaffold", + "appBar": { + "type": "appBar", + "title": { + "type": "text", + "data": "FittedBox" + } + }, + "body": { + "type": "padding", + "padding": { + "top": 12, + "left": 12, + "right": 12 + }, + "child": { + "type": "column", + "mainAxisAlignment": "start", + "crossAxisAlignment": "start", + "children": [ + { + "type": "sizedBox", + "height": 12 + }, + { + "type": "fittedBox", + "fit": "contain", + "alignment": "center", + "child": { + "type": "text", + "data": "Hello, World!", + "style": { + "fontSize": 20, + "color": "#000000" + } + } + } + ] + } + } +} \ No newline at end of file diff --git a/examples/mirai_gallery/assets/json/home_screen.json b/examples/mirai_gallery/assets/json/home_screen.json index 8dd0463f..bd9d2cfe 100644 --- a/examples/mirai_gallery/assets/json/home_screen.json +++ b/examples/mirai_gallery/assets/json/home_screen.json @@ -1629,6 +1629,107 @@ "behavior": "floating" } }, + + { + "type": "listTile", + "leading": { + "type": "icon", + "iconType": "material", + "icon": "apartment" + }, + + "title": { + "type": "text", + "data": "Mirai AspectRatio", + "style": { + "fontSize": 21 + } + }, + "subtitle": { + "type": "text", + "data": "A Material Design Mirai AspectRatio widget", + "style": { + "fontSize": 12 + } + }, + "isThreeLine": true, + "onTap": { + "actionType": "navigate", + "navigationStyle": "push", + "widgetJson": { + "type": "exampleScreen", + "assetPath": "assets/json/aspect_ratio_example.json" + } + } + }, + + { + "type": "listTile", + "leading": { + "type": "icon", + "iconType": "material", + "icon": "apartment" + }, + + "title": { + "type": "text", + "data": "Mirai FittedBox", + "style": { + "fontSize": 21 + } + }, + "subtitle": { + "type": "text", + "data": "A Material Design Mirai FittedBox widget", + "style": { + "fontSize": 12 + } + }, + "isThreeLine": true, + "onTap": { + "actionType": "navigate", + "navigationStyle": "push", + "widgetJson": { + "type": "exampleScreen", + "assetPath": "assets/json/fitted_box_example.json" + } + } + }, + + { + "type": "listTile", + "leading": { + "type": "icon", + "iconType": "material", + "icon": "apartment" + }, + + "title": { + "type": "text", + "data": "Mirai LimitedBox", + "style": { + "fontSize": 21 + } + }, + "subtitle": { + "type": "text", + "data": "A Material Design Mirai LimitedBox widget", + "style": { + "fontSize": 12 + } + }, + "isThreeLine": true, + "onTap": { + "actionType": "navigate", + "navigationStyle": "push", + "widgetJson": { + "type": "exampleScreen", + "assetPath": "assets/json/limited_box_example.json" + } + } + }, + + { "type": "sizedBox", "height": 24.0 diff --git a/examples/mirai_gallery/assets/json/limited_box_example.json b/examples/mirai_gallery/assets/json/limited_box_example.json new file mode 100644 index 00000000..fda3e29c --- /dev/null +++ b/examples/mirai_gallery/assets/json/limited_box_example.json @@ -0,0 +1,40 @@ +{ + "type": "scaffold", + "appBar": { + "type": "appBar", + "title": { + "type": "text", + "data": "LimitedBox" + } + }, + "body": { + "type": "listView", + "shrinkWrap": true, + "children": [ + { + "type": "sizedBox", + "height": 25 + }, + + { + "type": "limitedBox", + "child": { + "type": "container", + "height": 100, + "color": "#FF0000", + "child": { + "type": "text", + "data": "Hello, World! from Limited Box", + "style": { + "fontSize": 16, + "color": "#000000" + } + } + + } + } + + + ] + } +} \ No newline at end of file diff --git a/packages/mirai/lib/src/framework/mirai.dart b/packages/mirai/lib/src/framework/mirai.dart index 5388be24..98cfda8e 100644 --- a/packages/mirai/lib/src/framework/mirai.dart +++ b/packages/mirai/lib/src/framework/mirai.dart @@ -92,6 +92,9 @@ class Mirai { const MiraiSliderParser(), const MiraiOpacityParser(), const MiraiPlaceholderParser(), + const MiraiAspectRatioParser(), + const MiraiFittedBoxParser(), + const MiraiLimitedBoxParser(), ]; static final _actionParsers = [ diff --git a/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.dart b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.dart new file mode 100644 index 00000000..c4239708 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.dart @@ -0,0 +1,16 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; +export 'package:mirai/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio_parser.dart'; + +part 'mirai_aspect_ratio.freezed.dart'; +part 'mirai_aspect_ratio.g.dart'; + +@freezed +class MiraiAspectRatio with _$MiraiAspectRatio { + const factory MiraiAspectRatio({ + @Default(1) double aspectRatio, + Map? child, + }) = _MiraiAspectRatio; + + factory MiraiAspectRatio.fromJson(Map json) => + _$MiraiAspectRatioFromJson(json); +} diff --git a/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.freezed.dart b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.freezed.dart new file mode 100644 index 00000000..8e0f9fed --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.freezed.dart @@ -0,0 +1,195 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'mirai_aspect_ratio.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +MiraiAspectRatio _$MiraiAspectRatioFromJson(Map json) { + return _MiraiAspectRatio.fromJson(json); +} + +/// @nodoc +mixin _$MiraiAspectRatio { + double get aspectRatio => throw _privateConstructorUsedError; + Map? get child => throw _privateConstructorUsedError; + + /// Serializes this MiraiAspectRatio to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of MiraiAspectRatio + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $MiraiAspectRatioCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MiraiAspectRatioCopyWith<$Res> { + factory $MiraiAspectRatioCopyWith( + MiraiAspectRatio value, $Res Function(MiraiAspectRatio) then) = + _$MiraiAspectRatioCopyWithImpl<$Res, MiraiAspectRatio>; + @useResult + $Res call({double aspectRatio, Map? child}); +} + +/// @nodoc +class _$MiraiAspectRatioCopyWithImpl<$Res, $Val extends MiraiAspectRatio> + implements $MiraiAspectRatioCopyWith<$Res> { + _$MiraiAspectRatioCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of MiraiAspectRatio + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? aspectRatio = null, + Object? child = freezed, + }) { + return _then(_value.copyWith( + aspectRatio: null == aspectRatio + ? _value.aspectRatio + : aspectRatio // ignore: cast_nullable_to_non_nullable + as double, + child: freezed == child + ? _value.child + : child // ignore: cast_nullable_to_non_nullable + as Map?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MiraiAspectRatioImplCopyWith<$Res> + implements $MiraiAspectRatioCopyWith<$Res> { + factory _$$MiraiAspectRatioImplCopyWith(_$MiraiAspectRatioImpl value, + $Res Function(_$MiraiAspectRatioImpl) then) = + __$$MiraiAspectRatioImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({double aspectRatio, Map? child}); +} + +/// @nodoc +class __$$MiraiAspectRatioImplCopyWithImpl<$Res> + extends _$MiraiAspectRatioCopyWithImpl<$Res, _$MiraiAspectRatioImpl> + implements _$$MiraiAspectRatioImplCopyWith<$Res> { + __$$MiraiAspectRatioImplCopyWithImpl(_$MiraiAspectRatioImpl _value, + $Res Function(_$MiraiAspectRatioImpl) _then) + : super(_value, _then); + + /// Create a copy of MiraiAspectRatio + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? aspectRatio = null, + Object? child = freezed, + }) { + return _then(_$MiraiAspectRatioImpl( + aspectRatio: null == aspectRatio + ? _value.aspectRatio + : aspectRatio // ignore: cast_nullable_to_non_nullable + as double, + child: freezed == child + ? _value._child + : child // ignore: cast_nullable_to_non_nullable + as Map?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$MiraiAspectRatioImpl implements _MiraiAspectRatio { + const _$MiraiAspectRatioImpl( + {this.aspectRatio = 1, final Map? child}) + : _child = child; + + factory _$MiraiAspectRatioImpl.fromJson(Map json) => + _$$MiraiAspectRatioImplFromJson(json); + + @override + @JsonKey() + final double aspectRatio; + final Map? _child; + @override + Map? get child { + final value = _child; + if (value == null) return null; + if (_child is EqualUnmodifiableMapView) return _child; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); + } + + @override + String toString() { + return 'MiraiAspectRatio(aspectRatio: $aspectRatio, child: $child)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MiraiAspectRatioImpl && + (identical(other.aspectRatio, aspectRatio) || + other.aspectRatio == aspectRatio) && + const DeepCollectionEquality().equals(other._child, _child)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash( + runtimeType, aspectRatio, const DeepCollectionEquality().hash(_child)); + + /// Create a copy of MiraiAspectRatio + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$MiraiAspectRatioImplCopyWith<_$MiraiAspectRatioImpl> get copyWith => + __$$MiraiAspectRatioImplCopyWithImpl<_$MiraiAspectRatioImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$MiraiAspectRatioImplToJson( + this, + ); + } +} + +abstract class _MiraiAspectRatio implements MiraiAspectRatio { + const factory _MiraiAspectRatio( + {final double aspectRatio, + final Map? child}) = _$MiraiAspectRatioImpl; + + factory _MiraiAspectRatio.fromJson(Map json) = + _$MiraiAspectRatioImpl.fromJson; + + @override + double get aspectRatio; + @override + Map? get child; + + /// Create a copy of MiraiAspectRatio + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MiraiAspectRatioImplCopyWith<_$MiraiAspectRatioImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.g.dart b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.g.dart new file mode 100644 index 00000000..2bc94e90 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.g.dart @@ -0,0 +1,21 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mirai_aspect_ratio.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$MiraiAspectRatioImpl _$$MiraiAspectRatioImplFromJson( + Map json) => + _$MiraiAspectRatioImpl( + aspectRatio: (json['aspectRatio'] as num?)?.toDouble() ?? 1, + child: json['child'] as Map?, + ); + +Map _$$MiraiAspectRatioImplToJson( + _$MiraiAspectRatioImpl instance) => + { + 'aspectRatio': instance.aspectRatio, + 'child': instance.child, + }; diff --git a/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio_parser.dart b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio_parser.dart new file mode 100644 index 00000000..2eaf477a --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio_parser.dart @@ -0,0 +1,24 @@ +import 'package:flutter/material.dart'; +import 'package:mirai/src/framework/framework.dart'; +import 'package:mirai/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.dart'; +import 'package:mirai/src/utils/widget_type.dart'; +import 'package:mirai_framework/mirai_framework.dart'; + +class MiraiAspectRatioParser extends MiraiParser { + const MiraiAspectRatioParser(); + + @override + String get type => WidgetType.aspectRatio.name; + + @override + MiraiAspectRatio getModel(Map json) => + MiraiAspectRatio.fromJson(json); + + @override + Widget parse(BuildContext context, MiraiAspectRatio model) { + return AspectRatio( + aspectRatio: model.aspectRatio, + child: Mirai.fromJson(model.child, context), + ); + } +} diff --git a/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.dart b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.dart new file mode 100644 index 00000000..4aa981f3 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.dart @@ -0,0 +1,22 @@ +import 'package:flutter/material.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:mirai/src/parsers/parsers.dart'; + +export 'package:mirai/src/parsers/mirai_fitted_box/mirai_fitted_box_parser.dart'; + +part 'mirai_fitted_box.freezed.dart'; +part 'mirai_fitted_box.g.dart'; + +@freezed +class MiraiFittedBox with _$MiraiFittedBox { + const factory MiraiFittedBox({ + @Default(BoxFit.contain) BoxFit fit, + @Default(MiraiAlignmentDirectional.center) + MiraiAlignmentDirectional alignment, + @Default(Clip.none) Clip clipBehavior, + Map? child, + }) = _MiraiFittedBox; + + factory MiraiFittedBox.fromJson(Map json) => + _$MiraiFittedBoxFromJson(json); +} diff --git a/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.freezed.dart b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.freezed.dart new file mode 100644 index 00000000..f52abd02 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.freezed.dart @@ -0,0 +1,243 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'mirai_fitted_box.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +MiraiFittedBox _$MiraiFittedBoxFromJson(Map json) { + return _MiraiFittedBox.fromJson(json); +} + +/// @nodoc +mixin _$MiraiFittedBox { + BoxFit get fit => throw _privateConstructorUsedError; + MiraiAlignmentDirectional get alignment => throw _privateConstructorUsedError; + Clip get clipBehavior => throw _privateConstructorUsedError; + Map? get child => throw _privateConstructorUsedError; + + /// Serializes this MiraiFittedBox to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of MiraiFittedBox + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $MiraiFittedBoxCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MiraiFittedBoxCopyWith<$Res> { + factory $MiraiFittedBoxCopyWith( + MiraiFittedBox value, $Res Function(MiraiFittedBox) then) = + _$MiraiFittedBoxCopyWithImpl<$Res, MiraiFittedBox>; + @useResult + $Res call( + {BoxFit fit, + MiraiAlignmentDirectional alignment, + Clip clipBehavior, + Map? child}); +} + +/// @nodoc +class _$MiraiFittedBoxCopyWithImpl<$Res, $Val extends MiraiFittedBox> + implements $MiraiFittedBoxCopyWith<$Res> { + _$MiraiFittedBoxCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of MiraiFittedBox + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? fit = null, + Object? alignment = null, + Object? clipBehavior = null, + Object? child = freezed, + }) { + return _then(_value.copyWith( + fit: null == fit + ? _value.fit + : fit // ignore: cast_nullable_to_non_nullable + as BoxFit, + alignment: null == alignment + ? _value.alignment + : alignment // ignore: cast_nullable_to_non_nullable + as MiraiAlignmentDirectional, + clipBehavior: null == clipBehavior + ? _value.clipBehavior + : clipBehavior // ignore: cast_nullable_to_non_nullable + as Clip, + child: freezed == child + ? _value.child + : child // ignore: cast_nullable_to_non_nullable + as Map?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MiraiFittedBoxImplCopyWith<$Res> + implements $MiraiFittedBoxCopyWith<$Res> { + factory _$$MiraiFittedBoxImplCopyWith(_$MiraiFittedBoxImpl value, + $Res Function(_$MiraiFittedBoxImpl) then) = + __$$MiraiFittedBoxImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {BoxFit fit, + MiraiAlignmentDirectional alignment, + Clip clipBehavior, + Map? child}); +} + +/// @nodoc +class __$$MiraiFittedBoxImplCopyWithImpl<$Res> + extends _$MiraiFittedBoxCopyWithImpl<$Res, _$MiraiFittedBoxImpl> + implements _$$MiraiFittedBoxImplCopyWith<$Res> { + __$$MiraiFittedBoxImplCopyWithImpl( + _$MiraiFittedBoxImpl _value, $Res Function(_$MiraiFittedBoxImpl) _then) + : super(_value, _then); + + /// Create a copy of MiraiFittedBox + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? fit = null, + Object? alignment = null, + Object? clipBehavior = null, + Object? child = freezed, + }) { + return _then(_$MiraiFittedBoxImpl( + fit: null == fit + ? _value.fit + : fit // ignore: cast_nullable_to_non_nullable + as BoxFit, + alignment: null == alignment + ? _value.alignment + : alignment // ignore: cast_nullable_to_non_nullable + as MiraiAlignmentDirectional, + clipBehavior: null == clipBehavior + ? _value.clipBehavior + : clipBehavior // ignore: cast_nullable_to_non_nullable + as Clip, + child: freezed == child + ? _value._child + : child // ignore: cast_nullable_to_non_nullable + as Map?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$MiraiFittedBoxImpl implements _MiraiFittedBox { + const _$MiraiFittedBoxImpl( + {this.fit = BoxFit.contain, + this.alignment = MiraiAlignmentDirectional.center, + this.clipBehavior = Clip.none, + final Map? child}) + : _child = child; + + factory _$MiraiFittedBoxImpl.fromJson(Map json) => + _$$MiraiFittedBoxImplFromJson(json); + + @override + @JsonKey() + final BoxFit fit; + @override + @JsonKey() + final MiraiAlignmentDirectional alignment; + @override + @JsonKey() + final Clip clipBehavior; + final Map? _child; + @override + Map? get child { + final value = _child; + if (value == null) return null; + if (_child is EqualUnmodifiableMapView) return _child; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); + } + + @override + String toString() { + return 'MiraiFittedBox(fit: $fit, alignment: $alignment, clipBehavior: $clipBehavior, child: $child)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MiraiFittedBoxImpl && + (identical(other.fit, fit) || other.fit == fit) && + (identical(other.alignment, alignment) || + other.alignment == alignment) && + (identical(other.clipBehavior, clipBehavior) || + other.clipBehavior == clipBehavior) && + const DeepCollectionEquality().equals(other._child, _child)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, fit, alignment, clipBehavior, + const DeepCollectionEquality().hash(_child)); + + /// Create a copy of MiraiFittedBox + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$MiraiFittedBoxImplCopyWith<_$MiraiFittedBoxImpl> get copyWith => + __$$MiraiFittedBoxImplCopyWithImpl<_$MiraiFittedBoxImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$MiraiFittedBoxImplToJson( + this, + ); + } +} + +abstract class _MiraiFittedBox implements MiraiFittedBox { + const factory _MiraiFittedBox( + {final BoxFit fit, + final MiraiAlignmentDirectional alignment, + final Clip clipBehavior, + final Map? child}) = _$MiraiFittedBoxImpl; + + factory _MiraiFittedBox.fromJson(Map json) = + _$MiraiFittedBoxImpl.fromJson; + + @override + BoxFit get fit; + @override + MiraiAlignmentDirectional get alignment; + @override + Clip get clipBehavior; + @override + Map? get child; + + /// Create a copy of MiraiFittedBox + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MiraiFittedBoxImplCopyWith<_$MiraiFittedBoxImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.g.dart b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.g.dart new file mode 100644 index 00000000..b1ae465e --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box.g.dart @@ -0,0 +1,56 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mirai_fitted_box.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$MiraiFittedBoxImpl _$$MiraiFittedBoxImplFromJson(Map json) => + _$MiraiFittedBoxImpl( + fit: $enumDecodeNullable(_$BoxFitEnumMap, json['fit']) ?? BoxFit.contain, + alignment: $enumDecodeNullable( + _$MiraiAlignmentDirectionalEnumMap, json['alignment']) ?? + MiraiAlignmentDirectional.center, + clipBehavior: + $enumDecodeNullable(_$ClipEnumMap, json['clipBehavior']) ?? Clip.none, + child: json['child'] as Map?, + ); + +Map _$$MiraiFittedBoxImplToJson( + _$MiraiFittedBoxImpl instance) => + { + 'fit': _$BoxFitEnumMap[instance.fit]!, + 'alignment': _$MiraiAlignmentDirectionalEnumMap[instance.alignment]!, + 'clipBehavior': _$ClipEnumMap[instance.clipBehavior]!, + 'child': instance.child, + }; + +const _$BoxFitEnumMap = { + BoxFit.fill: 'fill', + BoxFit.contain: 'contain', + BoxFit.cover: 'cover', + BoxFit.fitWidth: 'fitWidth', + BoxFit.fitHeight: 'fitHeight', + BoxFit.none: 'none', + BoxFit.scaleDown: 'scaleDown', +}; + +const _$MiraiAlignmentDirectionalEnumMap = { + MiraiAlignmentDirectional.topStart: 'topStart', + MiraiAlignmentDirectional.topCenter: 'topCenter', + MiraiAlignmentDirectional.topEnd: 'topEnd', + MiraiAlignmentDirectional.centerStart: 'centerStart', + MiraiAlignmentDirectional.center: 'center', + MiraiAlignmentDirectional.centerEnd: 'centerEnd', + MiraiAlignmentDirectional.bottomStart: 'bottomStart', + MiraiAlignmentDirectional.bottomCenter: 'bottomCenter', + MiraiAlignmentDirectional.bottomEnd: 'bottomEnd', +}; + +const _$ClipEnumMap = { + Clip.none: 'none', + Clip.hardEdge: 'hardEdge', + Clip.antiAlias: 'antiAlias', + Clip.antiAliasWithSaveLayer: 'antiAliasWithSaveLayer', +}; diff --git a/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box_parser.dart b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box_parser.dart new file mode 100644 index 00000000..6f8a71cc --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_fitted_box/mirai_fitted_box_parser.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; +import 'package:mirai/src/framework/framework.dart'; +import 'package:mirai/src/parsers/mirai_fitted_box/mirai_fitted_box.dart'; +import 'package:mirai/src/utils/widget_type.dart'; +import 'package:mirai_framework/mirai_framework.dart'; + +class MiraiFittedBoxParser extends MiraiParser { + const MiraiFittedBoxParser(); + + @override + String get type => WidgetType.fittedBox.name; + + @override + MiraiFittedBox getModel(Map json) => + MiraiFittedBox.fromJson(json); + + @override + Widget parse(BuildContext context, MiraiFittedBox model) { + return FittedBox( + fit: model.fit, + alignment: model.alignment.value, + clipBehavior: model.clipBehavior, + child: Mirai.fromJson(model.child, context), + ); + } +} diff --git a/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.dart b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.dart new file mode 100644 index 00000000..89d8c405 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.dart @@ -0,0 +1,18 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +export 'package:mirai/src/parsers/mirai_limited_box/mirai_limited_box_parser.dart'; + +part 'mirai_limited_box.freezed.dart'; +part 'mirai_limited_box.g.dart'; + +@freezed +class MiraiLimitedBox with _$MiraiLimitedBox { + const factory MiraiLimitedBox({ + @Default(double.infinity) double maxHeight, + @Default(double.infinity) double maxWidth, + Map? child, + }) = _MiraiLimitedBox; + + factory MiraiLimitedBox.fromJson(Map json) => + _$MiraiLimitedBoxFromJson(json); +} diff --git a/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.freezed.dart b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.freezed.dart new file mode 100644 index 00000000..7776dba6 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.freezed.dart @@ -0,0 +1,216 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'mirai_limited_box.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +MiraiLimitedBox _$MiraiLimitedBoxFromJson(Map json) { + return _MiraiLimitedBox.fromJson(json); +} + +/// @nodoc +mixin _$MiraiLimitedBox { + double get maxHeight => throw _privateConstructorUsedError; + double get maxWidth => throw _privateConstructorUsedError; + Map? get child => throw _privateConstructorUsedError; + + /// Serializes this MiraiLimitedBox to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of MiraiLimitedBox + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $MiraiLimitedBoxCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MiraiLimitedBoxCopyWith<$Res> { + factory $MiraiLimitedBoxCopyWith( + MiraiLimitedBox value, $Res Function(MiraiLimitedBox) then) = + _$MiraiLimitedBoxCopyWithImpl<$Res, MiraiLimitedBox>; + @useResult + $Res call({double maxHeight, double maxWidth, Map? child}); +} + +/// @nodoc +class _$MiraiLimitedBoxCopyWithImpl<$Res, $Val extends MiraiLimitedBox> + implements $MiraiLimitedBoxCopyWith<$Res> { + _$MiraiLimitedBoxCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of MiraiLimitedBox + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? maxHeight = null, + Object? maxWidth = null, + Object? child = freezed, + }) { + return _then(_value.copyWith( + maxHeight: null == maxHeight + ? _value.maxHeight + : maxHeight // ignore: cast_nullable_to_non_nullable + as double, + maxWidth: null == maxWidth + ? _value.maxWidth + : maxWidth // ignore: cast_nullable_to_non_nullable + as double, + child: freezed == child + ? _value.child + : child // ignore: cast_nullable_to_non_nullable + as Map?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MiraiLimitedBoxImplCopyWith<$Res> + implements $MiraiLimitedBoxCopyWith<$Res> { + factory _$$MiraiLimitedBoxImplCopyWith(_$MiraiLimitedBoxImpl value, + $Res Function(_$MiraiLimitedBoxImpl) then) = + __$$MiraiLimitedBoxImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({double maxHeight, double maxWidth, Map? child}); +} + +/// @nodoc +class __$$MiraiLimitedBoxImplCopyWithImpl<$Res> + extends _$MiraiLimitedBoxCopyWithImpl<$Res, _$MiraiLimitedBoxImpl> + implements _$$MiraiLimitedBoxImplCopyWith<$Res> { + __$$MiraiLimitedBoxImplCopyWithImpl( + _$MiraiLimitedBoxImpl _value, $Res Function(_$MiraiLimitedBoxImpl) _then) + : super(_value, _then); + + /// Create a copy of MiraiLimitedBox + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? maxHeight = null, + Object? maxWidth = null, + Object? child = freezed, + }) { + return _then(_$MiraiLimitedBoxImpl( + maxHeight: null == maxHeight + ? _value.maxHeight + : maxHeight // ignore: cast_nullable_to_non_nullable + as double, + maxWidth: null == maxWidth + ? _value.maxWidth + : maxWidth // ignore: cast_nullable_to_non_nullable + as double, + child: freezed == child + ? _value._child + : child // ignore: cast_nullable_to_non_nullable + as Map?, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$MiraiLimitedBoxImpl implements _MiraiLimitedBox { + const _$MiraiLimitedBoxImpl( + {this.maxHeight = double.infinity, + this.maxWidth = double.infinity, + final Map? child}) + : _child = child; + + factory _$MiraiLimitedBoxImpl.fromJson(Map json) => + _$$MiraiLimitedBoxImplFromJson(json); + + @override + @JsonKey() + final double maxHeight; + @override + @JsonKey() + final double maxWidth; + final Map? _child; + @override + Map? get child { + final value = _child; + if (value == null) return null; + if (_child is EqualUnmodifiableMapView) return _child; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); + } + + @override + String toString() { + return 'MiraiLimitedBox(maxHeight: $maxHeight, maxWidth: $maxWidth, child: $child)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MiraiLimitedBoxImpl && + (identical(other.maxHeight, maxHeight) || + other.maxHeight == maxHeight) && + (identical(other.maxWidth, maxWidth) || + other.maxWidth == maxWidth) && + const DeepCollectionEquality().equals(other._child, _child)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, maxHeight, maxWidth, + const DeepCollectionEquality().hash(_child)); + + /// Create a copy of MiraiLimitedBox + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$MiraiLimitedBoxImplCopyWith<_$MiraiLimitedBoxImpl> get copyWith => + __$$MiraiLimitedBoxImplCopyWithImpl<_$MiraiLimitedBoxImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$MiraiLimitedBoxImplToJson( + this, + ); + } +} + +abstract class _MiraiLimitedBox implements MiraiLimitedBox { + const factory _MiraiLimitedBox( + {final double maxHeight, + final double maxWidth, + final Map? child}) = _$MiraiLimitedBoxImpl; + + factory _MiraiLimitedBox.fromJson(Map json) = + _$MiraiLimitedBoxImpl.fromJson; + + @override + double get maxHeight; + @override + double get maxWidth; + @override + Map? get child; + + /// Create a copy of MiraiLimitedBox + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MiraiLimitedBoxImplCopyWith<_$MiraiLimitedBoxImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.g.dart b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.g.dart new file mode 100644 index 00000000..9babb576 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box.g.dart @@ -0,0 +1,23 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mirai_limited_box.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$MiraiLimitedBoxImpl _$$MiraiLimitedBoxImplFromJson( + Map json) => + _$MiraiLimitedBoxImpl( + maxHeight: (json['maxHeight'] as num?)?.toDouble() ?? double.infinity, + maxWidth: (json['maxWidth'] as num?)?.toDouble() ?? double.infinity, + child: json['child'] as Map?, + ); + +Map _$$MiraiLimitedBoxImplToJson( + _$MiraiLimitedBoxImpl instance) => + { + 'maxHeight': instance.maxHeight, + 'maxWidth': instance.maxWidth, + 'child': instance.child, + }; diff --git a/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box_parser.dart b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box_parser.dart new file mode 100644 index 00000000..b0cc7190 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_limited_box/mirai_limited_box_parser.dart @@ -0,0 +1,25 @@ +import 'package:flutter/material.dart'; +import 'package:mirai/src/framework/framework.dart'; +import 'package:mirai/src/parsers/mirai_limited_box/mirai_limited_box.dart'; +import 'package:mirai/src/utils/widget_type.dart'; +import 'package:mirai_framework/mirai_framework.dart'; + +class MiraiLimitedBoxParser extends MiraiParser { + const MiraiLimitedBoxParser(); + + @override + String get type => WidgetType.limitedBox.name; + + @override + MiraiLimitedBox getModel(Map json) => + MiraiLimitedBox.fromJson(json); + + @override + Widget parse(BuildContext context, MiraiLimitedBox model) { + return LimitedBox( + maxHeight: model.maxHeight, + maxWidth: model.maxWidth, + child: Mirai.fromJson(model.child, context), + ); + } +} diff --git a/packages/mirai/lib/src/parsers/parsers.dart b/packages/mirai/lib/src/parsers/parsers.dart index a6d14bd7..304ab6be 100644 --- a/packages/mirai/lib/src/parsers/parsers.dart +++ b/packages/mirai/lib/src/parsers/parsers.dart @@ -87,3 +87,6 @@ export 'package:mirai/src/parsers/mirai_radio_group/mirai_radio_group.dart'; export 'package:mirai/src/parsers/mirai_slider/mirai_slider.dart'; export 'package:mirai/src/parsers/mirai_opacity/mirai_opacity.dart'; export 'package:mirai/src/parsers/mirai_placeholder/mirai_placeholder.dart'; +export 'package:mirai/src/parsers/mirai_aspect_ratio/mirai_aspect_ratio.dart'; +export 'package:mirai/src/parsers/mirai_fitted_box/mirai_fitted_box.dart'; +export 'package:mirai/src/parsers/mirai_limited_box/mirai_limited_box.dart'; diff --git a/packages/mirai/lib/src/utils/widget_type.dart b/packages/mirai/lib/src/utils/widget_type.dart index a8262727..2033b652 100644 --- a/packages/mirai/lib/src/utils/widget_type.dart +++ b/packages/mirai/lib/src/utils/widget_type.dart @@ -62,4 +62,7 @@ enum WidgetType { slider, opacity, placeholder, + aspectRatio, + fittedBox, + limitedBox, } diff --git a/website/docs/styles/_category_.json b/website/docs/styles/_category_.json new file mode 100644 index 00000000..b56cf829 --- /dev/null +++ b/website/docs/styles/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Mirai Styles", + "position": 6, + "link": { + "type": "generated-index", + "description": "Learn about the various Styles provided by Mirai" + } +} \ No newline at end of file diff --git a/website/docs/styles/box_fit.md b/website/docs/styles/box_fit.md new file mode 100644 index 00000000..efcf671a --- /dev/null +++ b/website/docs/styles/box_fit.md @@ -0,0 +1,22 @@ +# BoxFit + +The `fit` property supports the following values: + +| Value | Description | +| ----------- | ----------------------------------------------------------------------------------- | +| `fill` | Stretches the child to fill the box, distorting the aspect ratio if necessary. | +| `contain` | Scales the child to fit within the box while maintaining its aspect ratio. | +| `cover` | Scales the child to completely cover the box, possibly cropping parts of it. | +| `fitWidth` | Scales the child to match the width of the box, possibly overflowing vertically. | +| `fitHeight` | Scales the child to match the height of the box, possibly overflowing horizontally. | +| `none` | Positions the child without scaling, potentially allowing it to overflow the box. | +| `scaleDown` | Scales the child down to fit within the box only if it is larger than the box. | + +## Example JSON + +```json +{ + "type": "fittedBox", + "fit": "contain" +} +``` diff --git a/website/docs/styles/clip_behavior.md b/website/docs/styles/clip_behavior.md new file mode 100644 index 00000000..a34834f6 --- /dev/null +++ b/website/docs/styles/clip_behavior.md @@ -0,0 +1,19 @@ +# Clip + +The `clipBehavior` property determines how the content outside the box is handled: + +| Value | Description | +| ------------------------ | -------------------------------------------------------------------------------- | +| `none` | No clipping is applied (default). | +| `hardEdge` | Clips the content without anti-aliasing. | +| `antiAlias` | Clips the content with anti-aliasing for smoother edges. | +| `antiAliasWithSaveLayer` | Clips the content with anti-aliasing and saves an offscreen buffer for painting. | + +## Example JSON + +```json +{ + "type": "fittedBox", + "clipBehavior": "hardEdge" +} +``` diff --git a/website/docs/styles/mirai_alignment_directional.md b/website/docs/styles/mirai_alignment_directional.md new file mode 100644 index 00000000..0ab45f0e --- /dev/null +++ b/website/docs/styles/mirai_alignment_directional.md @@ -0,0 +1,26 @@ +# MiraiAlignmentDirectional + +Mirai AlignmentDirectional allows you to handling alignment widget using JSON. + +The `alignment` property determines where the child is positioned within the box: + +| Value | Description | +| -------------- | ----------------------------------------- | +| `topStart` | Aligns the child to the top-start corner. | +| `topCenter` | Aligns the child to the top-center. | +| `topEnd` | Aligns the child to the top-end corner. | +| `centerStart` | Aligns the child to the center-start. | +| `center` | Centers the child in the box. | +| `centerEnd` | Aligns the child to the center-end. | +| `bottomStart` | Aligns the child to the bottom-start. | +| `bottomCenter` | Aligns the child to the bottom-center. | +| `bottomEnd` | Aligns the child to the bottom-end. | + +## Example JSON + +```json +{ + "type": "fittedBox", + "alignment": "center" +} +``` diff --git a/website/docs/widgets/aspect_ratio.md b/website/docs/widgets/aspect_ratio.md new file mode 100644 index 00000000..36e47daa --- /dev/null +++ b/website/docs/widgets/aspect_ratio.md @@ -0,0 +1,30 @@ +# AspectRatio + +Mirai aspectRatio allows you to build the Flutter AspectRatio widget using JSON. +To know more about the aspectRatio widget in Flutter, refer to the [official documentation](https://api.flutter.dev/flutter/widgets/AspectRatio-class.html). + +--- + +## Properties + +| Property | Type | Description | +| ------------- | ----------------------- | ------------------------------------------------------------------------------------------------ | +| `aspectRatio` | `double` | The desired width-to-height ratio for the child widget. Defaults to `1` (a square aspect ratio). | +| `child` | `Map?` | The child widget that should adhere to the specified aspect ratio, represented as a JSON object. | + +--- + +## Example JSON + +```json +{ + "type": "aspectRatio", + "aspectRatio": 1.33, + "child": { + "type": "container", + "color": "#FF5733", + "width": 100, + "height": 100 + } +} +``` diff --git a/website/docs/widgets/fitted_box.md b/website/docs/widgets/fitted_box.md new file mode 100644 index 00000000..6f0ffde1 --- /dev/null +++ b/website/docs/widgets/fitted_box.md @@ -0,0 +1,35 @@ +# FittedBox + +Mirai FittedBox allows you to build the Flutter FittedBox widget using JSON. +To know more about the FittedBox widget in Flutter, refer to the [official documentation](https://api.flutter.dev/flutter/widgets/FittedBox-class.html). + +--- + +## Properties + +| Property | Type | Description | +| -------------- | --------------------------- | ------------------------------------------------------------------------------------ | +| `fit` | `BoxFit` | Defines how the child should be fitted within the box. Defaults to `BoxFit.contain`. | +| `alignment` | `MiraiAlignmentDirectional` | Aligns the child within the box. Defaults to `MiraiAlignmentDirectional.center`. | +| `clipBehavior` | `Clip` | Specifies whether and how the content should be clipped. Defaults to `Clip.none`. | +| `child` | `Map?` | The child widget, represented as a JSON object, to be positioned and scaled. | + +--- + +## Example JSON + +```json +{ + "type": "fittedBox", + "fit": "contain", + "alignment": "center", + "child": { + "type": "text", + "data": "Hello, World!", + "style": { + "fontSize": 20, + "color": "#000000" + } + } +} +``` diff --git a/website/docs/widgets/limited_box.md b/website/docs/widgets/limited_box.md new file mode 100644 index 00000000..11747a08 --- /dev/null +++ b/website/docs/widgets/limited_box.md @@ -0,0 +1,48 @@ +# LimitedBox + +Mirai LimitedBox allows you to build the Flutter LimitedBox widget using JSON. +To know more about the LimitedBox widget in Flutter, refer to the [official documentation](https://api.flutter.dev/flutter/widgets/LimitedBox-class.html). + +## Properties + +| Property | Type | Description | +| ----------- | ----------------------- | ---------------------------------------------------------------------------------------------------- | +| `maxHeight` | `double` | The maximum height for the child if the parent's height is unbounded. Defaults to `double.infinity`. | +| `maxWidth` | `double` | The maximum width for the child if the parent's width is unbounded. Defaults to `double.infinity`. | +| `child` | `Map?` | The child widget represented as a JSON object. | + +--- + +## Example JSON + +### Example 1: Limited Box with Default Constraints + +```json +{ + "type": "limitedBox", + "child": { + "type": "container", + "width": 100, + "height": 100, + "color": "#FF0000" + } +} +``` + +### Example 2: Limited Box with Custom Constraints + +```json +{ + "type": "limitedBox", + "maxHeight": 200.0, + "maxWidth": 300.0, + "child": { + "type": "text", + "data": "Hello, World! from Limited Box", + "style": { + "fontSize": 16, + "color": "#000000" + } + } +} +``` diff --git a/website/docs/widgets/visibility.md b/website/docs/widgets/visibility.md new file mode 100644 index 00000000..bb58d703 --- /dev/null +++ b/website/docs/widgets/visibility.md @@ -0,0 +1,55 @@ +# Visibility + +Mirai Visibility allows you to build the Flutter Visibility widget using JSON. +To know more about the Visibility widget in Flutter, refer to the [official documentation](https://api.flutter.dev/flutter/widgets/Visibility-class.html). + +--- + +## Properties + +| Property | Type | Description | +| ----------------------- | ----------------------- | ------------------------------------------------------------------------------------------------- | +| `child` | `Map` | The widget to be displayed when `visible` is `true`. | +| `replacement` | `Map?` | The widget to display when `visible` is `false`. Defaults to an empty widget (`SizedBox.shrink`). | +| `visible` | `bool` | Whether the child is visible. Defaults to `true`. | +| `maintainState` | `bool` | Whether to maintain the state of the widget when it is hidden. Defaults to `false`. | +| `maintainAnimation` | `bool` | Whether to maintain the animation of the widget when it is hidden. Defaults to `false`. | +| `maintainSize` | `bool` | Whether to maintain the size of the widget when it is hidden. Defaults to `false`. | +| `maintainSemantics` | `bool` | Whether to maintain the semantics of the widget when it is hidden. Defaults to `false`. | +| `maintainInteractivity` | `bool` | Whether to maintain the interactivity of the widget when it is hidden. Defaults to `false`. | + +--- + +## Example JSON + +### Example 1: Basic Visibility + +```json +{ + "type": "visibility", + "child": { + "type": "text", + "data": "I am visible!" + }, + "visible": true +} +``` + +### Example 2: Hidden with Replacement + +```json +{ + "type": "visibility", + "child": { + "type": "text", + "data": "I am hidden!" + }, + "replacement": { + "type": "container", + "color": "#FF5733", + "width": 50, + "height": 50 + }, + "visible": false +} +```