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

87 lines
2.3 KiB
Dart
Raw Normal View History

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