haptic feedback / lock animation when clicking on disabled toolbar buttons (#992)

pull/1490/head
ggurdin 1 year ago committed by GitHub
parent 2ddd07791d
commit f4da4ac4bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -9,6 +9,7 @@ import 'package:fluffychat/pangea/widgets/chat/message_selection_overlay.dart';
import 'package:fluffychat/pangea/widgets/pressable_button.dart'; import 'package:fluffychat/pangea/widgets/pressable_button.dart';
import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class ToolbarButtons extends StatelessWidget { class ToolbarButtons extends StatelessWidget {
final MessageOverlayController overlayController; final MessageOverlayController overlayController;
@ -93,30 +94,37 @@ class ToolbarButtons extends StatelessWidget {
); );
return Tooltip( return Tooltip(
message: mode.tooltip(context), message: mode.tooltip(context),
child: PressableButton( child: Stack(
borderRadius: BorderRadius.circular(20), alignment: Alignment.center,
enabled: enabled, children: [
depressed: !enabled || mode == overlayController.toolbarMode, PressableButton(
color: color, borderRadius: BorderRadius.circular(20),
onPressed: enabled enabled: enabled,
? () => overlayController.updateToolbarMode(mode) depressed:
: null, !enabled || mode == overlayController.toolbarMode,
child: AnimatedContainer(
duration: FluffyThemes.animationDuration,
height: buttonSize,
width: buttonSize,
decoration: BoxDecoration(
color: color, color: color,
shape: BoxShape.circle, onPressed: enabled
), ? () => overlayController.updateToolbarMode(mode)
child: Icon(
mode.icon,
size: 20,
color: mode == overlayController.toolbarMode
? Colors.white
: null, : null,
child: AnimatedContainer(
duration: FluffyThemes.animationDuration,
height: buttonSize,
width: buttonSize,
decoration: BoxDecoration(
color: color,
shape: BoxShape.circle,
),
child: Icon(
mode.icon,
size: 20,
color: mode == overlayController.toolbarMode
? Colors.white
: null,
),
),
), ),
), if (!enabled) const DisabledAnimation(),
],
), ),
); );
}).toList(), }).toList(),
@ -126,3 +134,78 @@ class ToolbarButtons extends StatelessWidget {
); );
} }
} }
class DisabledAnimation extends StatefulWidget {
final double size;
const DisabledAnimation({
this.size = 40.0,
super.key,
});
@override
DisabledAnimationState createState() => DisabledAnimationState();
}
class DisabledAnimationState extends State<DisabledAnimation>
with SingleTickerProviderStateMixin {
late final AnimationController _controller;
late final Animation<double> _animation;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(milliseconds: 750),
vsync: this,
);
_animation = TweenSequence<double>([
TweenSequenceItem<double>(
tween: Tween<double>(begin: 0, end: 1),
weight: 1.0,
),
TweenSequenceItem<double>(
tween: Tween<double>(begin: 1, end: 1),
weight: 1.0,
),
TweenSequenceItem<double>(
tween: Tween<double>(begin: 1, end: 0),
weight: 1.0,
),
]).animate(_controller);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _animation,
builder: (context, _) {
return GestureDetector(
onTap: () {
_controller.forward().then((_) => _controller.reset());
HapticFeedback.mediumImpact();
},
child: SizedBox(
width: widget.size,
height: widget.size,
child: Opacity(
opacity: _animation.value,
child: const Icon(
Icons.lock,
color: Colors.red,
size: 28,
),
),
),
);
},
);
}
}

Loading…
Cancel
Save