Aman-Malhotra / animate_icons

Use this plugin to animate any two icons like built in AnimatedIcons
MIT License
20 stars 16 forks source link

Feature Request: Allow manually specifying whether to show start vs end icon #2

Closed nareddyt closed 4 years ago

nareddyt commented 4 years ago

Currently, the widget only switches between start and end icons when a user taps on it. But there are 2 cases where I want more control over it. Ideally, the parent widget which includes the icon can specify exactly when to transition between the start vs end icons.

When there are multiple icons

Let's say there are 4 AnimateIcons in a bottom app bar. When the user taps on the first one, it will go from start to end, which is expected.

But when a user taps on any other icon, I expect the first one to revert back to start. Currently, there is no way to force this to happen. The first icon will be stuck in end until a user taps on it again.

When user input needs to be validated

Let's say there is a FAB with an AnimateIcon to switch between edit and save. When a user is in edit mode and clicks the FAB, I want it to animate to the save icon. This works as expected.

But I want to validate user input before transitioning the icon. If the user input is invalid, I want to keep the user in edit mode and prevent transitioning the icon to the save icon.

Currently, there is no way to prevent the transition before I can do some validation. The icon will transition as soon as the user taps on it.

Aman-Malhotra commented 4 years ago

Hey @nareddyt thanks for this Feature Request. It has been added and been released in version 0.0.4. You can check it here https://pub.dev/packages/animate_icons/versions/0.0.4

When input needs to be validated

Both the onStartIconPress and onEndIconPress functions need to return a bool value.

If the bool value is :

  1. true, the animation will happen
  2. null or false, the animation will not happen.

When there are multiple icons

You can use AnimateIconController to do that. Initialize the controller and pass it to the widget like this :

AnimateIconController controller = AnimateIconController();
AnimateIcons(
    controller: controller,
    .
    .
    .
)

The AnimateIconController has the following functions:

controller.animateToStart() // will animate to endIcon without calling onEndIconPress

controller.animateToEnd() // will animate to endIcon without calling onStartIconPress

controller.isStart() // returns true if the current visible icon is the startIcon else false

controller.isEnd() // returns true if the current visible icon is the endIcon else false

I am closing the issues. If ther are any issues, feedback is always welcome.

nareddyt commented 4 years ago

Thanks for the quick update! This addresses both use cases I have. I just tested out the second one, and it works as expected.