Open pro100svitlo opened 1 week ago
Thank you for taking the time to report this issue and provide a detailed description! I understand the concern, and your explanation of the behavior is clear. You're correct that the current implementation might feel more like an "initial state" rather than a dynamically controlled one, which could limit its usability for scenarios like a toggleable checkbox.
The following solution resolves it:
final firstButton = ChicletAnimatedButton(
key: Key(isFirstButtonPressed.toString()),
isPressed: isFirstButtonPressed,
child: const Text('1'),
onPressed: () {},
);
By assigning a Key
tied to the isFirstButtonPressed
state, we force Flutter to rebuild the ChicletAnimatedButton
whenever the state changes. This ensures the button updates dynamically to reflect the isPressed
state.
I’ve updated the example code to incorporate this solution. However, please note that this approach serves as a hotfix for the situation. A more robust solution could involve revisiting the widget’s state management or improving how the ChicletAnimatedButton
handles its internal and external states. Let me know if you'd like to discuss this further!
Hi,
thank you for the fast response 😉
Yes, you are absolutely right regarding the key
usage (this is the way I fixed it for now).
But I also agree that this is a duct taping 😄
Anyway, I appreciate the package and your time 🙏
Expected behavior:
true
and button state changed topressed
false
and button state changed todefault
Actual behavior:
true
orfalse
takes effect only during the initial build.In other words, the naming might be changed to
isInitialPressed
or something similar. This would more accurately represent the real functionality.However, the expected behavior would be very nice to have as well, since the button can be used as a kind of
checkbox
(selected and unselected states).Code to reproduce the issue: