rustdesk/flutter/lib/desktop/widgets/button.dart

85 lines
2.6 KiB
Dart
Raw Normal View History

2022-09-23 17:28:22 +08:00
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../common.dart';
class Button extends StatefulWidget {
GestureTapCallback onTap;
String text;
2022-09-23 20:18:11 +08:00
double? textSize;
2022-09-23 17:28:22 +08:00
double? minWidth;
bool isOutline;
2022-09-23 20:18:11 +08:00
double? padding;
Color? textColor;
double? radius;
Color? borderColor;
2022-09-23 17:28:22 +08:00
Button({
Key? key,
this.minWidth,
this.isOutline = false,
2022-09-23 20:18:11 +08:00
this.textSize,
this.padding,
this.textColor,
this.radius,
this.borderColor,
2022-09-23 17:28:22 +08:00
required this.onTap,
required this.text,
}) : super(key: key);
@override
State<Button> createState() => _ButtonState();
}
class _ButtonState extends State<Button> {
RxBool hover = false.obs;
RxBool pressed = false.obs;
@override
Widget build(BuildContext context) {
return Obx(() => InkWell(
onTapDown: (_) => pressed.value = true,
onTapUp: (_) => pressed.value = false,
onTapCancel: () => pressed.value = false,
onHover: (value) => hover.value = value,
onTap: widget.onTap,
child: ConstrainedBox(
constraints: BoxConstraints(
2022-09-23 20:18:11 +08:00
minWidth: widget.minWidth ?? 70.0,
2022-09-23 17:28:22 +08:00
),
child: Container(
2022-09-23 20:18:11 +08:00
padding: EdgeInsets.all(widget.padding ?? 4.5),
2022-09-23 17:28:22 +08:00
alignment: Alignment.center,
decoration: BoxDecoration(
color: pressed.value
? MyTheme.accent
: (widget.isOutline
? Colors.transparent
: MyTheme.button),
border: Border.all(
color: pressed.value
? MyTheme.accent
: hover.value
? MyTheme.hoverBorder
: (widget.isOutline
2022-09-23 20:18:11 +08:00
? widget.borderColor ?? MyTheme.border
2022-09-23 17:28:22 +08:00
: MyTheme.button),
),
2022-09-23 20:18:11 +08:00
borderRadius: BorderRadius.circular(widget.radius ?? 5),
2022-09-23 17:28:22 +08:00
),
child: Text(
translate(
widget.text,
),
style: TextStyle(
2022-09-23 20:18:11 +08:00
fontSize: widget.textSize ?? 12.0,
2022-09-23 17:28:22 +08:00
color: pressed.value || !widget.isOutline
? Theme.of(context).backgroundColor
2022-09-23 20:18:11 +08:00
: widget.textColor ??
Theme.of(context).textTheme.titleLarge?.color),
2022-09-23 17:28:22 +08:00
).marginSymmetric(horizontal: 12),
)),
));
}
}