Merge pull request #924 from pangeachat/clickable-messages

added buttonHeight as parameter of pressable button and added complet…
pull/1476/head
ggurdin 1 year ago committed by GitHub
commit 3980073e40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -77,6 +77,7 @@ class ToolbarButtons extends StatelessWidget {
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: modes.mapIndexed((index, mode) { children: modes.mapIndexed((index, mode) {
final enabled = mode.isUnlocked( final enabled = mode.isUnlocked(
index, index,

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@ -5,6 +7,7 @@ class PressableButton extends StatefulWidget {
final double width; final double width;
final double height; final double height;
final BorderRadius borderRadius; final BorderRadius borderRadius;
final double buttonHeight;
final bool enabled; final bool enabled;
final bool depressed; final bool depressed;
@ -20,6 +23,7 @@ class PressableButton extends StatefulWidget {
required this.child, required this.child,
required this.onPressed, required this.onPressed,
required this.color, required this.color,
this.buttonHeight = 5,
this.enabled = true, this.enabled = true,
this.depressed = false, this.depressed = false,
super.key, super.key,
@ -33,6 +37,7 @@ class PressableButtonState extends State<PressableButton>
with SingleTickerProviderStateMixin { with SingleTickerProviderStateMixin {
late AnimationController _controller; late AnimationController _controller;
late Animation<double> _tweenAnimation; late Animation<double> _tweenAnimation;
Completer<void>? _animationCompleter;
@override @override
void initState() { void initState() {
@ -41,16 +46,24 @@ class PressableButtonState extends State<PressableButton>
duration: const Duration(milliseconds: 100), duration: const Duration(milliseconds: 100),
vsync: this, vsync: this,
); );
_tweenAnimation = Tween<double>(begin: 5, end: 0).animate(_controller); _tweenAnimation =
Tween<double>(begin: widget.buttonHeight, end: 0).animate(_controller);
} }
void _onTapDown(TapDownDetails details) { void _onTapDown(TapDownDetails details) {
if (!widget.enabled) return; if (!widget.enabled) return;
_controller.forward(); _animationCompleter = Completer<void>();
_controller.forward().then((_) {
_animationCompleter?.complete();
_animationCompleter = null;
});
} }
void _onTapUp(TapUpDetails details) { Future<void> _onTapUp(TapUpDetails details) async {
if (!widget.enabled) return; if (!widget.enabled) return;
if (_animationCompleter != null) {
await _animationCompleter!.future;
}
_controller.reverse(); _controller.reverse();
widget.onPressed?.call(); widget.onPressed?.call();
HapticFeedback.mediumImpact(); HapticFeedback.mediumImpact();
@ -73,33 +86,30 @@ class PressableButtonState extends State<PressableButton>
onTapDown: _onTapDown, onTapDown: _onTapDown,
onTapUp: _onTapUp, onTapUp: _onTapUp,
onTapCancel: _onTapCancel, onTapCancel: _onTapCancel,
child: SizedBox( child: Stack(
height: 45, alignment: Alignment.bottomCenter,
child: Stack( children: [
alignment: Alignment.bottomCenter, Container(
children: [ width: widget.width,
Container( height: widget.height,
width: widget.width, decoration: BoxDecoration(
height: widget.height, color: Color.alphaBlend(
decoration: BoxDecoration( Colors.black.withOpacity(0.25),
color: Color.alphaBlend( widget.color,
Colors.black.withOpacity(0.25),
widget.color,
),
borderRadius: widget.borderRadius,
), ),
borderRadius: widget.borderRadius,
), ),
AnimatedBuilder( ),
animation: _tweenAnimation, AnimatedBuilder(
builder: (context, _) { animation: _tweenAnimation,
return Positioned( builder: (context, _) {
bottom: widget.depressed ? 0 : _tweenAnimation.value, return Positioned(
child: widget.child, bottom: widget.depressed ? 0 : _tweenAnimation.value,
); child: widget.child,
}, );
), },
], ),
), ],
), ),
); );
} }

Loading…
Cancel
Save