add auto-size-text for installCard button

Signed-off-by: 21pages <pages21@163.com>
This commit is contained in:
21pages 2022-10-24 15:58:24 +08:00
parent a2cb295a11
commit 1249776a21
4 changed files with 121 additions and 25 deletions

View File

@ -377,7 +377,8 @@ class _DesktopHomePageState extends State<DesktopHomePage>
fontSize: 13),
).marginOnly(bottom: 20),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Button(
FixedWidthButton(
width: 150,
padding: 8,
isOutline: true,
text: translate(btnText),

View File

@ -1,18 +1,19 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../common.dart';
class Button extends StatefulWidget {
GestureTapCallback onTap;
String text;
double? textSize;
double? minWidth;
bool isOutline;
double? padding;
Color? textColor;
double? radius;
Color? borderColor;
final GestureTapCallback onTap;
final String text;
final double? textSize;
final double? minWidth;
final bool isOutline;
final double? padding;
final Color? textColor;
final double? radius;
final Color? borderColor;
Button({
Key? key,
@ -82,3 +83,89 @@ class _ButtonState extends State<Button> {
));
}
}
class FixedWidthButton extends StatefulWidget {
final GestureTapCallback onTap;
final String text;
final double? textSize;
final double width;
final bool isOutline;
final double? padding;
final Color? textColor;
final double? radius;
final Color? borderColor;
final int? maxLines;
FixedWidthButton({
Key? key,
required this.width,
this.maxLines,
this.isOutline = false,
this.textSize,
this.padding,
this.textColor,
this.radius,
this.borderColor,
required this.onTap,
required this.text,
}) : super(key: key);
@override
State<FixedWidthButton> createState() => _FixedWidthButtonState();
}
class _FixedWidthButtonState extends State<FixedWidthButton> {
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: Container(
width: widget.width,
padding: EdgeInsets.all(widget.padding ?? 4.5),
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
? widget.borderColor ?? MyTheme.border
: MyTheme.button),
),
borderRadius: BorderRadius.circular(widget.radius ?? 5),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: AutoSizeText(
translate(
widget.text,
),
maxLines: widget.maxLines ?? 1,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: widget.textSize ?? 12.0,
color: widget.isOutline
? widget.textColor ??
Theme.of(context).textTheme.titleLarge?.color
: Colors.white),
).marginSymmetric(horizontal: 12),
),
],
),
),
));
}
}

View File

@ -50,6 +50,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.9.0"
auto_size_text:
dependency: "direct main"
description:
name: auto_size_text
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
back_button_interceptor:
dependency: "direct main"
description:
@ -119,28 +126,28 @@ packages:
name: cached_network_image
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.2"
version: "3.2.1"
cached_network_image_platform_interface:
dependency: transitive
description:
name: cached_network_image_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "1.0.0"
cached_network_image_web:
dependency: transitive
description:
name: cached_network_image_web
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
version: "1.0.1"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
version: "1.2.0"
charcode:
dependency: transitive
description:
@ -161,7 +168,7 @@ packages:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1"
version: "1.1.0"
code_builder:
dependency: transitive
description:
@ -243,8 +250,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "318ebd0a70cc5868911591c04f84bf1541f1bf4e"
resolved-ref: "318ebd0a70cc5868911591c04f84bf1541f1bf4e"
ref: "541f05f766c3f72984ff40b70dd3c7d061f2ce61"
resolved-ref: "541f05f766c3f72984ff40b70dd3c7d061f2ce61"
url: "https://github.com/Kingtous/rustdesk_desktop_multi_window"
source: git
version: "0.1.0"
@ -504,7 +511,7 @@ packages:
name: icons_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
version: "2.0.4"
image:
dependency: "direct main"
description:
@ -602,7 +609,7 @@ packages:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5"
version: "0.1.4"
menu_base:
dependency: transitive
description:
@ -616,7 +623,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.7.0"
mime:
dependency: transitive
description:
@ -693,7 +700,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
version: "1.8.1"
path_drawing:
dependency: transitive
description:
@ -959,7 +966,7 @@ packages:
name: sqflite
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0+1"
version: "2.0.3+1"
sqflite_common:
dependency: transitive
description:
@ -1301,7 +1308,7 @@ packages:
name: zxing2
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1"
version: "0.1.0"
sdks:
dart: ">=2.18.0 <3.0.0"
flutter: ">=3.3.0"
dart: ">=2.17.1 <3.0.0"
flutter: ">=3.0.0"

View File

@ -98,6 +98,7 @@ dependencies:
uni_links: ^0.5.1
uni_links_desktop: ^0.1.3
path: ^1.8.1
auto_size_text: ^3.0.0
dev_dependencies:
icons_launcher: ^2.0.4