2023-05-26 21:21:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Stack Wallet.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2023 Cypher Stack
|
|
|
|
* All Rights Reserved.
|
|
|
|
* The code is distributed under GPLv3 license, see LICENSE file for details.
|
|
|
|
* Generated by Cypher Stack on 2023-05-26
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter/gestures.dart';
|
2022-09-22 23:48:50 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-05-09 21:57:40 +00:00
|
|
|
import 'package:stackwallet/themes/stack_colors.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2022-11-29 18:08:10 +00:00
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
|
|
|
import 'package:stackwallet/widgets/conditional_parent.dart';
|
|
|
|
import 'package:stackwallet/widgets/rounded_container.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
|
2023-01-30 21:34:21 +00:00
|
|
|
class _CustomTextButton extends StatefulWidget {
|
|
|
|
const _CustomTextButton({
|
2022-11-02 21:03:14 +00:00
|
|
|
Key? key,
|
|
|
|
required this.text,
|
2023-01-30 21:34:21 +00:00
|
|
|
required this.enabledColor,
|
|
|
|
required this.disabledColor,
|
2022-11-02 21:03:14 +00:00
|
|
|
this.onTap,
|
|
|
|
this.enabled = true,
|
2022-11-08 19:50:53 +00:00
|
|
|
this.textSize,
|
2022-11-02 21:03:14 +00:00
|
|
|
}) : super(key: key);
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
final String text;
|
|
|
|
final VoidCallback? onTap;
|
2022-11-02 21:03:14 +00:00
|
|
|
final bool enabled;
|
2022-11-08 19:50:53 +00:00
|
|
|
final double? textSize;
|
2023-01-30 21:34:21 +00:00
|
|
|
final Color enabledColor;
|
|
|
|
final Color disabledColor;
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
@override
|
2023-01-30 21:34:21 +00:00
|
|
|
State<_CustomTextButton> createState() => _CustomTextButtonState();
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|
|
|
|
|
2023-01-30 21:34:21 +00:00
|
|
|
class _CustomTextButtonState extends State<_CustomTextButton>
|
2022-08-26 08:11:35 +00:00
|
|
|
with SingleTickerProviderStateMixin {
|
2022-11-02 21:03:14 +00:00
|
|
|
AnimationController? controller;
|
|
|
|
Animation<dynamic>? animation;
|
2022-08-26 08:11:35 +00:00
|
|
|
late Color color;
|
|
|
|
|
2022-11-29 18:08:10 +00:00
|
|
|
bool _hovering = false;
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
2022-11-02 21:03:14 +00:00
|
|
|
if (widget.enabled) {
|
2023-01-30 21:34:21 +00:00
|
|
|
color = widget.enabledColor;
|
2022-11-02 21:03:14 +00:00
|
|
|
controller = AnimationController(
|
|
|
|
vsync: this,
|
|
|
|
duration: const Duration(milliseconds: 100),
|
|
|
|
);
|
|
|
|
animation = ColorTween(
|
2023-01-30 21:34:21 +00:00
|
|
|
begin: widget.enabledColor,
|
|
|
|
end: widget.enabledColor.withOpacity(0.4),
|
2022-11-02 21:03:14 +00:00
|
|
|
).animate(controller!);
|
2022-08-26 08:11:35 +00:00
|
|
|
|
2022-11-02 21:03:14 +00:00
|
|
|
animation!.addListener(() {
|
|
|
|
setState(() {
|
|
|
|
color = animation!.value as Color;
|
|
|
|
});
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
2022-11-02 21:03:14 +00:00
|
|
|
} else {
|
2023-01-30 21:34:21 +00:00
|
|
|
color = widget.disabledColor;
|
2022-11-02 21:03:14 +00:00
|
|
|
}
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
2022-11-02 21:03:14 +00:00
|
|
|
controller?.dispose();
|
2023-04-11 16:12:26 +00:00
|
|
|
controller = null;
|
2022-08-26 08:11:35 +00:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-11-29 18:08:10 +00:00
|
|
|
return ConditionalParent(
|
|
|
|
condition: Util.isDesktop,
|
|
|
|
builder: (child) {
|
|
|
|
return MouseRegion(
|
|
|
|
cursor: SystemMouseCursors.click,
|
|
|
|
onEnter: (_) => setState(() => _hovering = true),
|
|
|
|
onExit: (_) => setState(() => _hovering = false),
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: widget.onTap,
|
|
|
|
child: RoundedContainer(
|
|
|
|
radiusMultiplier: 20,
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 10),
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.highlight
|
|
|
|
.withOpacity(_hovering ? 0.3 : 0),
|
|
|
|
child: child,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: RichText(
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
text: TextSpan(
|
|
|
|
text: widget.text,
|
|
|
|
style: widget.textSize == null
|
|
|
|
? STextStyles.link2(context).copyWith(
|
|
|
|
color: color,
|
|
|
|
)
|
|
|
|
: STextStyles.link2(context).copyWith(
|
|
|
|
color: color,
|
|
|
|
fontSize: widget.textSize,
|
|
|
|
),
|
|
|
|
recognizer: widget.enabled
|
|
|
|
? (TapGestureRecognizer()
|
|
|
|
..onTap = () {
|
|
|
|
widget.onTap?.call();
|
|
|
|
controller?.forward().then((value) => controller?.reverse());
|
|
|
|
})
|
|
|
|
: null,
|
|
|
|
),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-01-30 21:34:21 +00:00
|
|
|
|
|
|
|
class CustomTextButton extends StatelessWidget {
|
|
|
|
const CustomTextButton({
|
|
|
|
Key? key,
|
|
|
|
required this.text,
|
|
|
|
this.onTap,
|
|
|
|
this.enabled = true,
|
|
|
|
this.textSize,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final String text;
|
|
|
|
final VoidCallback? onTap;
|
|
|
|
final bool enabled;
|
|
|
|
final double? textSize;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return _CustomTextButton(
|
|
|
|
key: UniqueKey(),
|
|
|
|
text: text,
|
2023-02-10 21:16:32 +00:00
|
|
|
enabledColor: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.customTextButtonEnabledText,
|
|
|
|
disabledColor: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.customTextButtonDisabledText,
|
2023-01-30 21:34:21 +00:00
|
|
|
enabled: enabled,
|
|
|
|
textSize: textSize,
|
|
|
|
onTap: onTap,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|