Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Animated Container #106

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions examples/mirai_gallery/assets/json/animated_container.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"type": "scaffold",
"appBar": {
"type": "appBar",
"title": {
"type": "text",
"data": "Container"
}
},
"body": {
"type": "listView",
"physics": "never",
"shrinkWrap": true,
"children": [
{
"type": "sizedBox",
"height": 52
},
{
"type": "animatedContainer",
"duration": 1736886463,
"color": "#672BFF",
"height": 250,
"width": 200
},
{
"type": "sizedBox",
"height": 52
},
{
"type": "animatedContainer",
"duration": 1736886463,
"color": "#FC5632",
"height": 250,
"width": 200,
"child": {
"type": "align",
"alignment": "bottomCenter",
"child": {
"type": "text",
"data": "Flutter",
"align": "center",
"style": {
"fontSize": 23,
"fontWeight": "w600"
}
}
}
}
]
}
}
32 changes: 31 additions & 1 deletion examples/mirai_gallery/assets/json/home_screen.json
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,6 @@
"iconType": "material",
"icon": "navigation"
},

"title": {
"type": "text",
"data": "Mirai Opacity",
Expand All @@ -1555,6 +1554,37 @@
}
}
},
{
"type": "listTile",
"leading": {
"type": "icon",
"iconType": "material",
"icon": "radio"
},
"title": {
"type": "text",
"data": "Mirai Animated Container",
"style": {
"fontSize": 21
}
},
"subtitle": {
"type": "text",
"data": "A Material Design Mirai Opacity widget",
"style": {
"fontSize": 12
}
},
"isThreeLine": true,
"onTap": {
"actionType": "navigate",
"navigationStyle": "push",
"widgetJson": {
"type": "exampleScreen",
"assetPath": "assets/json/animated_container.json"
}
}
},
{
"type": "sizedBox",
"height": 24.0
Expand Down
2 changes: 2 additions & 0 deletions packages/mirai/lib/src/framework/mirai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter/services.dart';
import 'package:mirai/src/action_parsers/action_parsers.dart';
import 'package:mirai/src/action_parsers/mirai_network_request/mirai_network_request_parser.dart';
import 'package:mirai/src/framework/mirai_registry.dart';
import 'package:mirai/src/parsers/mirai_animated_container/mirai_animated_animated_container_parser.dart';
import 'package:mirai/src/parsers/mirai_divider/mirai_divider_parser.dart';
import 'package:mirai/src/parsers/parsers.dart';
import 'package:mirai/src/services/mirai_network_service.dart';
Expand Down Expand Up @@ -91,6 +92,7 @@ class Mirai {
const MiraiRadioGroupParser(),
const MiraiSliderParser(),
const MiraiOpacityParser(),
const MiraiAnimatedContainerParser(),
];

static final _actionParsers = <MiraiActionParser>[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/cupertino.dart';
import 'package:mirai/mirai.dart';
import 'package:mirai/src/parsers/mirai_box_constraints/mirai_box_constraints.dart';
import 'package:mirai/src/utils/widget_type.dart';

import 'mirai_animated_container.dart';

class MiraiAnimatedContainerParser extends MiraiParser<MiraiAnimatedContainer> {
const MiraiAnimatedContainerParser();

@override
String get type => WidgetType.animatedContainer.name;

@override
MiraiAnimatedContainer getModel(Map<String, dynamic> json) =>
MiraiAnimatedContainer.fromJson(json);

@override
Widget parse(BuildContext context, MiraiAnimatedContainer model) {
return AnimatedContainer(
duration: model.duration,
alignment: model.alignment?.value,
padding: model.padding?.parse,
color: model.color.toColor(context),
decoration: model.decoration?.parse(context),
foregroundDecoration: model.foregroundDecoration?.parse(context),
width: model.width,
height: model.height,
constraints: model.constraints?.parse,
margin: model.margin?.parse,
clipBehavior: model.clipBehavior,
child: Mirai.fromJson(model.child, context),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'dart:ui';

import 'package:freezed_annotation/freezed_annotation.dart';

import '../../../mirai.dart';
import '../mirai_box_constraints/mirai_box_constraints.dart';

part 'mirai_animated_container.freezed.dart';
part 'mirai_animated_container.g.dart';

@freezed
class MiraiAnimatedContainer with _$MiraiAnimatedContainer {
const factory MiraiAnimatedContainer({
required Duration duration,
MiraiAlignment? alignment,
MiraiEdgeInsets? padding,
MiraiBoxDecoration? decoration,
MiraiBoxDecoration? foregroundDecoration,
String? color,
double? width,
double? height,
MiraiBoxConstraints? constraints,
MiraiEdgeInsets? margin,
Map<String, dynamic>? child,
@Default(Clip.none) Clip clipBehavior,
}) = _MiraiAnimatedContainer;

factory MiraiAnimatedContainer.fromJson(Map<String, dynamic> json) =>
_$MiraiAnimatedContainerFromJson(json);
}
Loading