Skip to content

Commit d94da61

Browse files
committed
[Launcher] refactor: move interactive button widget into a separate file
1 parent 0346303 commit d94da61

2 files changed

Lines changed: 77 additions & 72 deletions

File tree

Launcher/lib/features/server_browser/dialogs/join_server_dialog.dart

Lines changed: 5 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import 'package:kyber_launcher/gen/assets.gen.dart';
1919
import 'package:kyber_launcher/gen/fonts.gen.dart';
2020
import 'package:kyber_launcher/injection_container.dart';
2121
import 'package:kyber_launcher/main.dart';
22+
import 'package:kyber_launcher/shared/ui/buttons/interactive_button.dart';
2223
import 'package:kyber_launcher/shared/ui/ui.dart';
2324
import 'package:local_hero/local_hero.dart';
2425
import 'package:logging/logging.dart';
25-
import 'package:vector_graphics/vector_graphics.dart';
2626

2727
const _kCardWidth = 450.0;
2828

@@ -913,7 +913,8 @@ class _ServerCardState extends State<_ServerCard> {
913913
Positioned(
914914
left: _kCardWidth / 2 - 104,
915915
top: 240 - 45 / 2,
916-
child: _PlayButton(
916+
child: InteractiveButton(
917+
child: const Text('PLAY'),
917918
onPressed: () => widget.onPlay?.call(false),
918919
),
919920
),
@@ -929,9 +930,9 @@ class _ServerCardState extends State<_ServerCard> {
929930
left: _kCardWidth / 2 - 104,
930931
top: 146 - 45 / 2,
931932
child: FadeIn(
932-
child: _PlayButton(
933+
child: InteractiveButton(
933934
onPressed: widget.onBack ?? () {},
934-
text: 'BACK',
935+
child: const Text('BACK'),
935936
),
936937
),
937938
),
@@ -990,74 +991,6 @@ class _KyberTag extends StatelessWidget {
990991
}
991992
}
992993

993-
class _PlayButton extends StatefulWidget {
994-
const _PlayButton({required this.onPressed, this.text});
995-
996-
final VoidCallback onPressed;
997-
final String? text;
998-
999-
@override
1000-
State<_PlayButton> createState() => _PlayButtonState();
1001-
}
1002-
1003-
class _PlayButtonState extends State<_PlayButton> {
1004-
bool hovered = false;
1005-
1006-
@override
1007-
Widget build(BuildContext context) {
1008-
final target = hovered ? kActiveColor : kWhiteColor;
1009-
1010-
return MouseRegion(
1011-
onEnter: (_) => setState(() => hovered = true),
1012-
onExit: (_) => setState(() => hovered = false),
1013-
cursor: SystemMouseCursors.click,
1014-
child: GestureDetector(
1015-
onTap: widget.onPressed,
1016-
child: Stack(
1017-
children: [
1018-
VectorGraphic(
1019-
loader: AssetBytesLoader(Assets.icons.kblPlayIcon.path),
1020-
height: 47,
1021-
width: 208,
1022-
),
1023-
VectorGraphic(
1024-
loader: AssetBytesLoader(Assets.icons.kblPlayIconBorder.path),
1025-
height: 47,
1026-
width: 208,
1027-
colorFilter: ColorFilter.mode(
1028-
target,
1029-
BlendMode.srcIn,
1030-
),
1031-
),
1032-
Positioned(
1033-
top: 12,
1034-
left: 72,
1035-
child: AnimatedDefaultTextStyle(
1036-
duration: const Duration(milliseconds: 150),
1037-
style: TextStyle(
1038-
color: target,
1039-
fontSize: 24,
1040-
fontWeight: FontWeight.bold,
1041-
height: 1,
1042-
shadows: hovered
1043-
? [
1044-
Shadow(
1045-
color: kActiveColor.withOpacity(.7),
1046-
blurRadius: 10,
1047-
),
1048-
]
1049-
: null,
1050-
),
1051-
child: Text(widget.text ?? 'PLAY'),
1052-
),
1053-
),
1054-
],
1055-
),
1056-
),
1057-
);
1058-
}
1059-
}
1060-
1061994
class JoinDialogResult {
1062995
JoinDialogResult({
1063996
required this.collection,
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import 'package:fluent_ui/fluent_ui.dart';
2+
import 'package:kyber_launcher/core/config/colors.dart';
3+
import 'package:kyber_launcher/gen/assets.gen.dart';
4+
import 'package:vector_graphics/vector_graphics.dart';
5+
6+
class InteractiveButton extends StatefulWidget {
7+
const InteractiveButton({required this.child, required this.onPressed, super.key});
8+
9+
final VoidCallback onPressed;
10+
final Widget child;
11+
12+
@override
13+
State<InteractiveButton> createState() => _InteractiveButtonState();
14+
}
15+
16+
class _InteractiveButtonState extends State<InteractiveButton> {
17+
bool hovered = false;
18+
19+
@override
20+
Widget build(BuildContext context) {
21+
final target = hovered ? kActiveColor : kWhiteColor;
22+
23+
return MouseRegion(
24+
onEnter: (_) => setState(() => hovered = true),
25+
onExit: (_) => setState(() => hovered = false),
26+
cursor: SystemMouseCursors.click,
27+
child: GestureDetector(
28+
onTap: widget.onPressed,
29+
child: Stack(
30+
children: [
31+
VectorGraphic(
32+
loader: AssetBytesLoader(Assets.icons.kblPlayIcon.path),
33+
height: 47,
34+
width: 208,
35+
),
36+
VectorGraphic(
37+
loader: AssetBytesLoader(Assets.icons.kblPlayIconBorder.path),
38+
height: 47,
39+
width: 208,
40+
colorFilter: .mode(
41+
target,
42+
BlendMode.srcIn,
43+
),
44+
),
45+
Positioned(
46+
top: 12,
47+
left: 72,
48+
child: AnimatedDefaultTextStyle(
49+
duration: const .new(milliseconds: 150),
50+
style: TextStyle(
51+
color: target,
52+
fontSize: 24,
53+
fontWeight: .bold,
54+
height: 1,
55+
shadows: hovered
56+
? [
57+
Shadow(
58+
color: kActiveColor.withOpacity(.7),
59+
blurRadius: 10,
60+
),
61+
]
62+
: null,
63+
),
64+
child: widget.child,
65+
),
66+
),
67+
],
68+
),
69+
),
70+
);
71+
}
72+
}

0 commit comments

Comments
 (0)