diff --git a/examples/mirai_gallery/assets/json/home_screen.json b/examples/mirai_gallery/assets/json/home_screen.json index f53e458d..5807490c 100644 --- a/examples/mirai_gallery/assets/json/home_screen.json +++ b/examples/mirai_gallery/assets/json/home_screen.json @@ -641,6 +641,37 @@ } } }, + { + "type": "listTile", + "leading": { + "type": "icon", + "iconType": "material", + "icon": "table_chart" + }, + "title": { + "type": "text", + "data": "Mirai PageView", + "style": { + "fontSize": 21 + } + }, + "subtitle": { + "type": "text", + "data": "A Material Design widget that displays a horizontal row of pages", + "style": { + "fontSize": 12 + } + }, + "isThreeLine": true, + "onTap": { + "actionType": "navigate", + "navigationStyle": "push", + "widgetJson": { + "type": "exampleScreen", + "assetPath": "assets/json/page_view_example.json" + } + } + }, { "type": "listTile", "leading": { diff --git a/examples/mirai_gallery/assets/json/page_view_example.json b/examples/mirai_gallery/assets/json/page_view_example.json new file mode 100644 index 00000000..32c7ef36 --- /dev/null +++ b/examples/mirai_gallery/assets/json/page_view_example.json @@ -0,0 +1,60 @@ +{ + "type": "scaffold", + "appBar": { + "type": "appBar", + "title": { + "type": "text", + "data": "PageView" + } + }, + "body": { + "type": "pageView", + "children": [ + { + "type": "container", + "color": "#D9D9D9", + "child": { + "type": "center", + "child": { + "type": "text", + "data": "Page 1", + "style": { + "fontSize": 23, + "fontWeight": "w400" + } + } + } + }, + { + "type": "container", + "color": "#FC3F1B", + "child": { + "type": "center", + "child": { + "type": "text", + "data": "Page 2", + "style": { + "fontSize": 23, + "fontWeight": "w400" + } + } + } + }, + { + "type": "container", + "color": "#D9D9D9", + "child": { + "type": "center", + "child": { + "type": "text", + "data": "Page 3", + "style": { + "fontSize": 23, + "fontWeight": "w400" + } + } + } + } + ] + } +} \ 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 ca8a30fc..4a81066f 100644 --- a/packages/mirai/lib/src/framework/mirai.dart +++ b/packages/mirai/lib/src/framework/mirai.dart @@ -68,6 +68,7 @@ class Mirai { const MiraiSafeAreaParser(), const MiraiSwitchParser(), const MiraiAlignParser(), + const MiraiPageViewParser(), ]; static final _actionParsers = [ diff --git a/packages/mirai/lib/src/parsers/mirai_page_view/mirai_page_view.dart b/packages/mirai/lib/src/parsers/mirai_page_view/mirai_page_view.dart new file mode 100644 index 00000000..c9ff23ba --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_page_view/mirai_page_view.dart @@ -0,0 +1,32 @@ +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; +import 'package:mirai/mirai.dart'; + +export 'package:mirai/src/parsers/mirai_page_view/mirai_page_view_parser.dart'; + +part 'mirai_page_view.freezed.dart'; +part 'mirai_page_view.g.dart'; + +@freezed +class MiraiPageView with _$MiraiPageView { + const factory MiraiPageView({ + @Default(Axis.horizontal) Axis scrollDirection, + @Default(false) bool reverse, + MiraiScrollPhysics? physics, + @Default(true) bool pageSnapping, + Map? onPageChanged, + @Default(DragStartBehavior.start) DragStartBehavior dragStartBehavior, + @Default(false) bool allowImplicitScrolling, + String? restorationId, + @Default(Clip.hardEdge) Clip clipBehavior, + @Default(true) bool padEnds, + @Default(0) int initialPage, + @Default(true) keepPage, + @Default(1.0) double viewportFraction, + @Default([]) List> children, + }) = _MiraiPageView; + + factory MiraiPageView.fromJson(Map json) => + _$MiraiPageViewFromJson(json); +} diff --git a/packages/mirai/lib/src/parsers/mirai_page_view/mirai_page_view.freezed.dart b/packages/mirai/lib/src/parsers/mirai_page_view/mirai_page_view.freezed.dart new file mode 100644 index 00000000..a7e503b2 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_page_view/mirai_page_view.freezed.dart @@ -0,0 +1,462 @@ +// 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_page_view.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#custom-getters-and-methods'); + +MiraiPageView _$MiraiPageViewFromJson(Map json) { + return _MiraiPageView.fromJson(json); +} + +/// @nodoc +mixin _$MiraiPageView { + bool get allowImplicitScrolling => throw _privateConstructorUsedError; + Clip get clipBehavior => throw _privateConstructorUsedError; + DragStartBehavior get dragStartBehavior => throw _privateConstructorUsedError; + int get initialPage => throw _privateConstructorUsedError; + dynamic get keepPage => throw _privateConstructorUsedError; + Map? get onPageChanged => throw _privateConstructorUsedError; + MiraiScrollPhysics? get physics => throw _privateConstructorUsedError; + bool get pageSnapping => throw _privateConstructorUsedError; + bool get padEnds => throw _privateConstructorUsedError; + String? get restorationId => throw _privateConstructorUsedError; + bool get reverse => throw _privateConstructorUsedError; + Axis get scrollDirection => throw _privateConstructorUsedError; + double get viewportFraction => throw _privateConstructorUsedError; + List> get children => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $MiraiPageViewCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MiraiPageViewCopyWith<$Res> { + factory $MiraiPageViewCopyWith( + MiraiPageView value, $Res Function(MiraiPageView) then) = + _$MiraiPageViewCopyWithImpl<$Res, MiraiPageView>; + @useResult + $Res call( + {bool allowImplicitScrolling, + Clip clipBehavior, + DragStartBehavior dragStartBehavior, + int initialPage, + dynamic keepPage, + Map? onPageChanged, + MiraiScrollPhysics? physics, + bool pageSnapping, + bool padEnds, + String? restorationId, + bool reverse, + Axis scrollDirection, + double viewportFraction, + List> children}); +} + +/// @nodoc +class _$MiraiPageViewCopyWithImpl<$Res, $Val extends MiraiPageView> + implements $MiraiPageViewCopyWith<$Res> { + _$MiraiPageViewCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? allowImplicitScrolling = null, + Object? clipBehavior = null, + Object? dragStartBehavior = null, + Object? initialPage = null, + Object? keepPage = freezed, + Object? onPageChanged = freezed, + Object? physics = freezed, + Object? pageSnapping = null, + Object? padEnds = null, + Object? restorationId = freezed, + Object? reverse = null, + Object? scrollDirection = null, + Object? viewportFraction = null, + Object? children = null, + }) { + return _then(_value.copyWith( + allowImplicitScrolling: null == allowImplicitScrolling + ? _value.allowImplicitScrolling + : allowImplicitScrolling // ignore: cast_nullable_to_non_nullable + as bool, + clipBehavior: null == clipBehavior + ? _value.clipBehavior + : clipBehavior // ignore: cast_nullable_to_non_nullable + as Clip, + dragStartBehavior: null == dragStartBehavior + ? _value.dragStartBehavior + : dragStartBehavior // ignore: cast_nullable_to_non_nullable + as DragStartBehavior, + initialPage: null == initialPage + ? _value.initialPage + : initialPage // ignore: cast_nullable_to_non_nullable + as int, + keepPage: freezed == keepPage + ? _value.keepPage + : keepPage // ignore: cast_nullable_to_non_nullable + as dynamic, + onPageChanged: freezed == onPageChanged + ? _value.onPageChanged + : onPageChanged // ignore: cast_nullable_to_non_nullable + as Map?, + physics: freezed == physics + ? _value.physics + : physics // ignore: cast_nullable_to_non_nullable + as MiraiScrollPhysics?, + pageSnapping: null == pageSnapping + ? _value.pageSnapping + : pageSnapping // ignore: cast_nullable_to_non_nullable + as bool, + padEnds: null == padEnds + ? _value.padEnds + : padEnds // ignore: cast_nullable_to_non_nullable + as bool, + restorationId: freezed == restorationId + ? _value.restorationId + : restorationId // ignore: cast_nullable_to_non_nullable + as String?, + reverse: null == reverse + ? _value.reverse + : reverse // ignore: cast_nullable_to_non_nullable + as bool, + scrollDirection: null == scrollDirection + ? _value.scrollDirection + : scrollDirection // ignore: cast_nullable_to_non_nullable + as Axis, + viewportFraction: null == viewportFraction + ? _value.viewportFraction + : viewportFraction // ignore: cast_nullable_to_non_nullable + as double, + children: null == children + ? _value.children + : children // ignore: cast_nullable_to_non_nullable + as List>, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MiraiPageViewImplCopyWith<$Res> + implements $MiraiPageViewCopyWith<$Res> { + factory _$$MiraiPageViewImplCopyWith( + _$MiraiPageViewImpl value, $Res Function(_$MiraiPageViewImpl) then) = + __$$MiraiPageViewImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {bool allowImplicitScrolling, + Clip clipBehavior, + DragStartBehavior dragStartBehavior, + int initialPage, + dynamic keepPage, + Map? onPageChanged, + MiraiScrollPhysics? physics, + bool pageSnapping, + bool padEnds, + String? restorationId, + bool reverse, + Axis scrollDirection, + double viewportFraction, + List> children}); +} + +/// @nodoc +class __$$MiraiPageViewImplCopyWithImpl<$Res> + extends _$MiraiPageViewCopyWithImpl<$Res, _$MiraiPageViewImpl> + implements _$$MiraiPageViewImplCopyWith<$Res> { + __$$MiraiPageViewImplCopyWithImpl( + _$MiraiPageViewImpl _value, $Res Function(_$MiraiPageViewImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? allowImplicitScrolling = null, + Object? clipBehavior = null, + Object? dragStartBehavior = null, + Object? initialPage = null, + Object? keepPage = freezed, + Object? onPageChanged = freezed, + Object? physics = freezed, + Object? pageSnapping = null, + Object? padEnds = null, + Object? restorationId = freezed, + Object? reverse = null, + Object? scrollDirection = null, + Object? viewportFraction = null, + Object? children = null, + }) { + return _then(_$MiraiPageViewImpl( + allowImplicitScrolling: null == allowImplicitScrolling + ? _value.allowImplicitScrolling + : allowImplicitScrolling // ignore: cast_nullable_to_non_nullable + as bool, + clipBehavior: null == clipBehavior + ? _value.clipBehavior + : clipBehavior // ignore: cast_nullable_to_non_nullable + as Clip, + dragStartBehavior: null == dragStartBehavior + ? _value.dragStartBehavior + : dragStartBehavior // ignore: cast_nullable_to_non_nullable + as DragStartBehavior, + initialPage: null == initialPage + ? _value.initialPage + : initialPage // ignore: cast_nullable_to_non_nullable + as int, + keepPage: freezed == keepPage ? _value.keepPage! : keepPage, + onPageChanged: freezed == onPageChanged + ? _value._onPageChanged + : onPageChanged // ignore: cast_nullable_to_non_nullable + as Map?, + physics: freezed == physics + ? _value.physics + : physics // ignore: cast_nullable_to_non_nullable + as MiraiScrollPhysics?, + pageSnapping: null == pageSnapping + ? _value.pageSnapping + : pageSnapping // ignore: cast_nullable_to_non_nullable + as bool, + padEnds: null == padEnds + ? _value.padEnds + : padEnds // ignore: cast_nullable_to_non_nullable + as bool, + restorationId: freezed == restorationId + ? _value.restorationId + : restorationId // ignore: cast_nullable_to_non_nullable + as String?, + reverse: null == reverse + ? _value.reverse + : reverse // ignore: cast_nullable_to_non_nullable + as bool, + scrollDirection: null == scrollDirection + ? _value.scrollDirection + : scrollDirection // ignore: cast_nullable_to_non_nullable + as Axis, + viewportFraction: null == viewportFraction + ? _value.viewportFraction + : viewportFraction // ignore: cast_nullable_to_non_nullable + as double, + children: null == children + ? _value._children + : children // ignore: cast_nullable_to_non_nullable + as List>, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$MiraiPageViewImpl implements _MiraiPageView { + const _$MiraiPageViewImpl( + {this.allowImplicitScrolling = false, + this.clipBehavior = Clip.hardEdge, + this.dragStartBehavior = DragStartBehavior.start, + this.initialPage = 0, + this.keepPage = true, + final Map? onPageChanged, + this.physics, + this.pageSnapping = true, + this.padEnds = true, + this.restorationId, + this.reverse = false, + this.scrollDirection = Axis.horizontal, + this.viewportFraction = 1.0, + final List> children = const []}) + : _onPageChanged = onPageChanged, + _children = children; + + factory _$MiraiPageViewImpl.fromJson(Map json) => + _$$MiraiPageViewImplFromJson(json); + + @override + @JsonKey() + final bool allowImplicitScrolling; + @override + @JsonKey() + final Clip clipBehavior; + @override + @JsonKey() + final DragStartBehavior dragStartBehavior; + @override + @JsonKey() + final int initialPage; + @override + @JsonKey() + final dynamic keepPage; + final Map? _onPageChanged; + @override + Map? get onPageChanged { + final value = _onPageChanged; + if (value == null) return null; + if (_onPageChanged is EqualUnmodifiableMapView) return _onPageChanged; + // ignore: implicit_dynamic_type + return EqualUnmodifiableMapView(value); + } + + @override + final MiraiScrollPhysics? physics; + @override + @JsonKey() + final bool pageSnapping; + @override + @JsonKey() + final bool padEnds; + @override + final String? restorationId; + @override + @JsonKey() + final bool reverse; + @override + @JsonKey() + final Axis scrollDirection; + @override + @JsonKey() + final double viewportFraction; + final List> _children; + @override + @JsonKey() + List> get children { + if (_children is EqualUnmodifiableListView) return _children; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_children); + } + + @override + String toString() { + return 'MiraiPageView(allowImplicitScrolling: $allowImplicitScrolling, clipBehavior: $clipBehavior, dragStartBehavior: $dragStartBehavior, initialPage: $initialPage, keepPage: $keepPage, onPageChanged: $onPageChanged, physics: $physics, pageSnapping: $pageSnapping, padEnds: $padEnds, restorationId: $restorationId, reverse: $reverse, scrollDirection: $scrollDirection, viewportFraction: $viewportFraction, children: $children)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MiraiPageViewImpl && + (identical(other.allowImplicitScrolling, allowImplicitScrolling) || + other.allowImplicitScrolling == allowImplicitScrolling) && + (identical(other.clipBehavior, clipBehavior) || + other.clipBehavior == clipBehavior) && + (identical(other.dragStartBehavior, dragStartBehavior) || + other.dragStartBehavior == dragStartBehavior) && + (identical(other.initialPage, initialPage) || + other.initialPage == initialPage) && + const DeepCollectionEquality().equals(other.keepPage, keepPage) && + const DeepCollectionEquality() + .equals(other._onPageChanged, _onPageChanged) && + (identical(other.physics, physics) || other.physics == physics) && + (identical(other.pageSnapping, pageSnapping) || + other.pageSnapping == pageSnapping) && + (identical(other.padEnds, padEnds) || other.padEnds == padEnds) && + (identical(other.restorationId, restorationId) || + other.restorationId == restorationId) && + (identical(other.reverse, reverse) || other.reverse == reverse) && + (identical(other.scrollDirection, scrollDirection) || + other.scrollDirection == scrollDirection) && + (identical(other.viewportFraction, viewportFraction) || + other.viewportFraction == viewportFraction) && + const DeepCollectionEquality().equals(other._children, _children)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash( + runtimeType, + allowImplicitScrolling, + clipBehavior, + dragStartBehavior, + initialPage, + const DeepCollectionEquality().hash(keepPage), + const DeepCollectionEquality().hash(_onPageChanged), + physics, + pageSnapping, + padEnds, + restorationId, + reverse, + scrollDirection, + viewportFraction, + const DeepCollectionEquality().hash(_children)); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$MiraiPageViewImplCopyWith<_$MiraiPageViewImpl> get copyWith => + __$$MiraiPageViewImplCopyWithImpl<_$MiraiPageViewImpl>(this, _$identity); + + @override + Map toJson() { + return _$$MiraiPageViewImplToJson( + this, + ); + } +} + +abstract class _MiraiPageView implements MiraiPageView { + const factory _MiraiPageView( + {final bool allowImplicitScrolling, + final Clip clipBehavior, + final DragStartBehavior dragStartBehavior, + final int initialPage, + final dynamic keepPage, + final Map? onPageChanged, + final MiraiScrollPhysics? physics, + final bool pageSnapping, + final bool padEnds, + final String? restorationId, + final bool reverse, + final Axis scrollDirection, + final double viewportFraction, + final List> children}) = _$MiraiPageViewImpl; + + factory _MiraiPageView.fromJson(Map json) = + _$MiraiPageViewImpl.fromJson; + + @override + bool get allowImplicitScrolling; + @override + Clip get clipBehavior; + @override + DragStartBehavior get dragStartBehavior; + @override + int get initialPage; + @override + dynamic get keepPage; + @override + Map? get onPageChanged; + @override + MiraiScrollPhysics? get physics; + @override + bool get pageSnapping; + @override + bool get padEnds; + @override + String? get restorationId; + @override + bool get reverse; + @override + Axis get scrollDirection; + @override + double get viewportFraction; + @override + List> get children; + @override + @JsonKey(ignore: true) + _$$MiraiPageViewImplCopyWith<_$MiraiPageViewImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/packages/mirai/lib/src/parsers/mirai_page_view/mirai_page_view.g.dart b/packages/mirai/lib/src/parsers/mirai_page_view/mirai_page_view.g.dart new file mode 100644 index 00000000..8cae2f1d --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_page_view/mirai_page_view.g.dart @@ -0,0 +1,78 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mirai_page_view.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$MiraiPageViewImpl _$$MiraiPageViewImplFromJson(Map json) => + _$MiraiPageViewImpl( + allowImplicitScrolling: json['allowImplicitScrolling'] as bool? ?? false, + clipBehavior: $enumDecodeNullable(_$ClipEnumMap, json['clipBehavior']) ?? + Clip.hardEdge, + dragStartBehavior: $enumDecodeNullable( + _$DragStartBehaviorEnumMap, json['dragStartBehavior']) ?? + DragStartBehavior.start, + initialPage: json['initialPage'] as int? ?? 0, + keepPage: json['keepPage'] ?? true, + onPageChanged: json['onPageChanged'] as Map?, + physics: + $enumDecodeNullable(_$MiraiScrollPhysicsEnumMap, json['physics']), + pageSnapping: json['pageSnapping'] as bool? ?? true, + padEnds: json['padEnds'] as bool? ?? true, + restorationId: json['restorationId'] as String?, + reverse: json['reverse'] as bool? ?? false, + scrollDirection: + $enumDecodeNullable(_$AxisEnumMap, json['scrollDirection']) ?? + Axis.horizontal, + viewportFraction: (json['viewportFraction'] as num?)?.toDouble() ?? 1.0, + children: (json['children'] as List?) + ?.map((e) => e as Map) + .toList() ?? + const [], + ); + +Map _$$MiraiPageViewImplToJson(_$MiraiPageViewImpl instance) => + { + 'allowImplicitScrolling': instance.allowImplicitScrolling, + 'clipBehavior': _$ClipEnumMap[instance.clipBehavior]!, + 'dragStartBehavior': + _$DragStartBehaviorEnumMap[instance.dragStartBehavior]!, + 'initialPage': instance.initialPage, + 'keepPage': instance.keepPage, + 'onPageChanged': instance.onPageChanged, + 'physics': _$MiraiScrollPhysicsEnumMap[instance.physics], + 'pageSnapping': instance.pageSnapping, + 'padEnds': instance.padEnds, + 'restorationId': instance.restorationId, + 'reverse': instance.reverse, + 'scrollDirection': _$AxisEnumMap[instance.scrollDirection]!, + 'viewportFraction': instance.viewportFraction, + 'children': instance.children, + }; + +const _$ClipEnumMap = { + Clip.none: 'none', + Clip.hardEdge: 'hardEdge', + Clip.antiAlias: 'antiAlias', + Clip.antiAliasWithSaveLayer: 'antiAliasWithSaveLayer', +}; + +const _$DragStartBehaviorEnumMap = { + DragStartBehavior.down: 'down', + DragStartBehavior.start: 'start', +}; + +const _$MiraiScrollPhysicsEnumMap = { + MiraiScrollPhysics.never: 'never', + MiraiScrollPhysics.bouncing: 'bouncing', + MiraiScrollPhysics.clamping: 'clamping', + MiraiScrollPhysics.fixed: 'fixed', + MiraiScrollPhysics.page: 'page', +}; + +const _$AxisEnumMap = { + Axis.horizontal: 'horizontal', + Axis.vertical: 'vertical', +}; diff --git a/packages/mirai/lib/src/parsers/mirai_page_view/mirai_page_view_parser.dart b/packages/mirai/lib/src/parsers/mirai_page_view/mirai_page_view_parser.dart new file mode 100644 index 00000000..3afcef55 --- /dev/null +++ b/packages/mirai/lib/src/parsers/mirai_page_view/mirai_page_view_parser.dart @@ -0,0 +1,71 @@ +import 'package:flutter/material.dart'; +import 'package:mirai/src/framework/framework.dart'; +import 'package:mirai/src/parsers/mirai_page_view/mirai_page_view.dart'; +import 'package:mirai/src/utils/widget_type.dart'; +import 'package:mirai_framework/mirai_framework.dart'; + +class MiraiPageViewParser extends MiraiParser { + const MiraiPageViewParser(); + + @override + MiraiPageView getModel(Map json) => + MiraiPageView.fromJson(json); + + @override + String get type => WidgetType.pageView.name; + + @override + Widget parse(BuildContext context, MiraiPageView model) { + return _MiraiPageViewWidget(model: model); + } +} + +class _MiraiPageViewWidget extends StatefulWidget { + const _MiraiPageViewWidget({ + required this.model, + }); + + final MiraiPageView model; + + @override + State<_MiraiPageViewWidget> createState() => _MiraiPageViewWidgetState(); +} + +class _MiraiPageViewWidgetState extends State<_MiraiPageViewWidget> { + PageController? _pageController; + + @override + void initState() { + super.initState(); + + _pageController = PageController( + initialPage: widget.model.initialPage, + viewportFraction: widget.model.viewportFraction, + keepPage: widget.model.keepPage, + ); + } + + @override + Widget build(BuildContext context) { + return PageView.builder( + scrollDirection: widget.model.scrollDirection, + reverse: widget.model.reverse, + controller: _pageController, + physics: widget.model.physics?.parse, + pageSnapping: widget.model.pageSnapping, + onPageChanged: (int index) { + Mirai.onCallFromJson(widget.model.onPageChanged, context); + }, + itemBuilder: (context, index) { + return Mirai.fromJson(widget.model.children[index], context) ?? + const SizedBox(); + }, + itemCount: widget.model.children.length, + dragStartBehavior: widget.model.dragStartBehavior, + allowImplicitScrolling: widget.model.allowImplicitScrolling, + restorationId: widget.model.restorationId, + clipBehavior: widget.model.clipBehavior, + padEnds: true, + ); + } +} diff --git a/packages/mirai/lib/src/parsers/parsers.dart b/packages/mirai/lib/src/parsers/parsers.dart index fa79f8e3..e9be00ea 100644 --- a/packages/mirai/lib/src/parsers/parsers.dart +++ b/packages/mirai/lib/src/parsers/parsers.dart @@ -59,3 +59,4 @@ export 'package:mirai/src/parsers/mirai_text_form_field/mirai_text_form_field.da export 'package:mirai/src/parsers/mirai_text_style/mirai_text_style.dart'; export 'package:mirai/src/parsers/mirai_theme/mirai_theme.dart'; export 'package:mirai/src/parsers/mirai_align/mirai_align.dart'; +export 'package:mirai/src/parsers/mirai_page_view/mirai_page_view.dart'; diff --git a/packages/mirai/lib/src/utils/widget_type.dart b/packages/mirai/lib/src/utils/widget_type.dart index 34457fa5..b8ae6417 100644 --- a/packages/mirai/lib/src/utils/widget_type.dart +++ b/packages/mirai/lib/src/utils/widget_type.dart @@ -37,5 +37,6 @@ enum WidgetType { flexible, safeArea, switchButton, - align + align, + pageView, }