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: Add Mirai parser for hero widget #82

Merged
merged 7 commits into from
Jan 8, 2025

Conversation

Yash-Khattar
Copy link
Contributor

@Yash-Khattar Yash-Khattar commented Jan 4, 2025

Added Hero Animation support

  1. Build Hero Parser with all the properties mentioned in https://api.flutter.dev/flutter/widgets/Hero-class.html?_gl=1*1lhsiin*_ga*MzAxNjY0MTI4LjE3MjA4NzczODU.*_ga_04YGWK0175*MTczNTc1MDM4OC45My4xLjE3MzU3NTA2MzguMC4wLjA
  2. created util for create_rect_tween prop.
  3. Added example for the hero animation

Related Issues

close #16

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Code refactor
  • Build configuration change
  • Documentation
  • Chore

Demo video of the changes
screen-capture.webm

Copy link
Member

@divyanshub024 divyanshub024 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this amazing PR!! 💯

Please check my suggestions.

@@ -53,5 +53,6 @@ enum WidgetType {
tableCell,
carouselView,
coloredBox,
divider
divider,
hero
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the comma , at the end.

@@ -0,0 +1,19 @@
import 'package:flutter/widgets.dart';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this import.

Comment on lines 4 to 19
CreateRectTween? parseCreateRectTween(Map<String, dynamic> json) {
final type = json['type'] as String?;

switch (type) {
case 'materialRectArcTween':
return (Rect? begin, Rect? end) =>
MaterialRectArcTween(begin: begin, end: end);
case 'materialRectCenterArcTween':
return (Rect? begin, Rect? end) =>
MaterialRectCenterArcTween(begin: begin, end: end);
case 'rectTween':
return (Rect? begin, Rect? end) => RectTween(begin: begin, end: end);
default:
return null;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this into a freezed class like other parsers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, how can a user pass the begin and end values from JSON?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey, understood !!

  1. I'll create a proper parser for it and move it from utils to the parsers folder
  2. just saw the repo has a parser already made for Rect (mirai_rect.dart) I'll use that to implement this functionality

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, Thank you so much!! 🙌🏻

@divyanshub024 divyanshub024 changed the title Feature/hero issue #16 feat: Add Mirai parser for hero widget Jan 4, 2025
@Yash-Khattar
Copy link
Contributor Author

hey, lemme know if there are any more changes

Copy link
Member

@divyanshub024 divyanshub024 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Yash-Khattar,

Thanks for the previous changes. Here is one last change suggestion. Please check it out.

Comment on lines 1 to 24
import 'package:flutter/material.dart';
import 'package:mirai/src/parsers/mirai_rect_tween/mirai_rect_tween.dart';
import 'package:mirai/src/parsers/mirai_rect/mirai_rect.dart';

class MiraiRectTweenParser {
const MiraiRectTweenParser();

MiraiRectTween getModel(Map<String, dynamic> json) =>
MiraiRectTween.fromJson(json);

RectTween parse(BuildContext context, MiraiRectTween model) {
final begin = model.begin?.parse;
final end = model.end?.parse;

switch (model.type) {
case 'materialRectArcTween':
return MaterialRectArcTween(begin: begin, end: end);
case 'materialRectCenterArcTween':
return MaterialRectCenterArcTween(begin: begin, end: end);
default:
return RectTween(begin: begin, end: end);
}
}
}
Copy link
Member

@divyanshub024 divyanshub024 Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this as an extension method in mirai_rect_tweetn.dart. Just how it's done in mirai dialog theme

This makes it easier to use MiraiRectTween just by calling model.rectTween.parse. Also we can avoid the getModel method as it's not used anywhere.

@divyanshub024 divyanshub024 added this to the v0.9 milestone Jan 8, 2025
Copy link
Member

@divyanshub024 divyanshub024 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for such a great PR @Yash-Khattar 🎉

@divyanshub024 divyanshub024 merged commit 7e07861 into BuildMirai:dev Jan 8, 2025
3 checks passed
@Yash-Khattar
Copy link
Contributor Author

thanks a lot, @divyanshub024 !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Add support for hero widget
2 participants