selfprivacy.org.app/lib/ui/components/pre_styled_buttons/flash.dart

88 lines
2.4 KiB
Dart
Raw Normal View History

2021-05-26 00:53:54 +03:00
part of 'pre_styled_buttons.dart';
class _BrandFlashButton extends StatefulWidget {
@override
_BrandFlashButtonState createState() => _BrandFlashButtonState();
}
class _BrandFlashButtonState extends State<_BrandFlashButton>
with SingleTickerProviderStateMixin {
late AnimationController _animationController;
late Animation _colorTween;
@override
void initState() {
2022-05-24 21:55:39 +03:00
_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 800),
);
2021-05-26 00:53:54 +03:00
_colorTween = ColorTween(
begin: BrandColors.black,
end: BrandColors.primary,
).animate(_animationController);
2021-06-21 00:08:52 +03:00
2021-05-26 00:53:54 +03:00
super.initState();
2022-05-16 23:30:14 +03:00
WidgetsBinding.instance.addPostFrameCallback(_afterLayout);
2021-06-21 00:08:52 +03:00
}
2022-06-05 22:36:32 +03:00
void _afterLayout(final _) {
2021-06-21 00:08:52 +03:00
if (Theme.of(context).brightness == Brightness.dark) {
setState(() {
_colorTween = ColorTween(
begin: BrandColors.white,
end: BrandColors.primary,
).animate(_animationController);
});
}
2021-05-26 00:53:54 +03:00
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
2021-07-29 08:24:42 +03:00
bool wasPrevStateIsEmpty = true;
2021-05-26 00:53:54 +03:00
@override
Widget build(final BuildContext context) =>
BlocListener<JobsCubit, JobsState>(
listener: (final context, final state) {
if (wasPrevStateIsEmpty && state is! JobsStateEmpty) {
wasPrevStateIsEmpty = false;
_animationController.forward();
} else if (!wasPrevStateIsEmpty && state is JobsStateEmpty) {
wasPrevStateIsEmpty = true;
2021-07-29 08:24:42 +03:00
_animationController.reverse();
}
2021-05-26 00:53:54 +03:00
},
child: IconButton(
onPressed: () {
showBrandBottomSheet(
context: context,
builder: (final context) => const BrandBottomSheet(
isExpended: true,
child: JobsContent(),
),
);
},
icon: AnimatedBuilder(
2021-05-26 00:53:54 +03:00
animation: _colorTween,
2022-06-05 22:36:32 +03:00
builder: (final context, final child) {
final double v = _animationController.value;
final IconData icon =
v > 0.5 ? Ionicons.flash : Ionicons.flash_outline;
2021-06-21 00:08:52 +03:00
return Transform.scale(
scale: 1 + (v < 0.5 ? v : 1 - v) * 2,
child: Icon(
icon,
color: _colorTween.value,
),
2021-05-26 00:53:54 +03:00
);
},
),
),
);
2021-05-26 00:53:54 +03:00
}