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: [DX-2168] Improve password StatusBar transition animation #677

Merged
merged 1 commit into from
Oct 1, 2024
Merged
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
54 changes: 45 additions & 9 deletions optimus/lib/src/common/field_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -460,19 +460,55 @@ class _StatusBar extends StatelessWidget {
padding: EdgeInsets.only(top: tokens.spacing50),
child: SizedBox(
height: tokens.sizing50,
child: AnimatedFractionallySizedBox(
duration: _kAnimationDuration,
alignment: Alignment.centerLeft,
heightFactor: 1,
widthFactor: state.progress,
curve: Curves.fastOutSlowIn,
child: ColoredBox(color: state.getStatusBarColor(tokens)),
),
child: _ColoredTransition(state),
),
);
}
}

class _ColoredTransition extends StatefulWidget {
const _ColoredTransition(this.state);

final OptimusStatusBarState state;

@override
State<_ColoredTransition> createState() => _ColoredTransitionState();
}

class _ColoredTransitionState extends State<_ColoredTransition> {
late OptimusStatusBarState _previousState;

@override
void initState() {
super.initState();
_previousState = widget.state;
}

@override
void didUpdateWidget(covariant _ColoredTransition oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.state != oldWidget.state) {
_previousState = oldWidget.state;
}
}

@override
Widget build(BuildContext context) => AnimatedFractionallySizedBox(
duration: _kAnimationDuration,
alignment: Alignment.centerLeft,
heightFactor: 1,
widthFactor: widget.state.progress,
curve: Curves.fastOutSlowIn,
child: ColoredBox(
color: widget.state == OptimusStatusBarState.empty
? _previousState
.getStatusBarColor(context.tokens)
.withOpacity(0.5)
: widget.state.getStatusBarColor(context.tokens),
),
);
}

extension on OptimusStatusBarState {
Color getStatusBarColor(OptimusTokens tokens) => switch (this) {
OptimusStatusBarState.empty ||
Expand Down Expand Up @@ -537,4 +573,4 @@ extension on OptimusWidgetSize {
};
}

const _kAnimationDuration = Duration(milliseconds: 200);
const Duration _kAnimationDuration = Duration(milliseconds: 200);
Loading