2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-04-26 00:02:00 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
import 'package:stackwallet/utilities/assets.dart';
|
2022-09-26 17:34:41 +00:00
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2022-09-22 23:48:50 +00:00
|
|
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
class NumberKey extends StatefulWidget {
|
|
|
|
const NumberKey({
|
|
|
|
Key? key,
|
|
|
|
required this.number,
|
|
|
|
required this.onPressed,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final String number;
|
|
|
|
final ValueSetter<String> onPressed;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<NumberKey> createState() => _NumberKeyState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _NumberKeyState extends State<NumberKey> {
|
|
|
|
late final String number;
|
|
|
|
late final ValueSetter<String> onPressed;
|
|
|
|
|
2022-09-22 23:48:50 +00:00
|
|
|
Color? _color;
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
number = widget.number;
|
|
|
|
onPressed = widget.onPressed;
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-09-22 23:48:50 +00:00
|
|
|
_color ??= Theme.of(context).extension<StackColors>()!.numberBackDefault;
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
return AnimatedContainer(
|
|
|
|
duration: const Duration(milliseconds: 200),
|
|
|
|
curve: Curves.easeInOut,
|
|
|
|
height: 72,
|
|
|
|
width: 72,
|
|
|
|
decoration: ShapeDecoration(
|
|
|
|
shape: const StadiumBorder(),
|
|
|
|
color: _color,
|
|
|
|
shadows: const [],
|
|
|
|
),
|
|
|
|
child: MaterialButton(
|
2022-09-22 23:48:50 +00:00
|
|
|
// splashColor: Theme.of(context).extension<StackColors>()!.highlight,
|
2022-08-26 08:11:35 +00:00
|
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
shape: const StadiumBorder(),
|
|
|
|
onPressed: () async {
|
|
|
|
onPressed.call(number);
|
|
|
|
setState(() {
|
2022-09-22 23:48:50 +00:00
|
|
|
_color = Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.numberBackDefault
|
|
|
|
.withOpacity(0.8);
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Future<void>.delayed(const Duration(milliseconds: 200), () {
|
|
|
|
if (mounted) {
|
|
|
|
setState(() {
|
2022-09-22 23:48:50 +00:00
|
|
|
_color = Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.numberBackDefault;
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Center(
|
|
|
|
child: Text(
|
|
|
|
number,
|
2022-09-26 17:34:41 +00:00
|
|
|
style: STextStyles.numberDefault(context),
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BackspaceKey extends StatefulWidget {
|
|
|
|
const BackspaceKey({
|
|
|
|
Key? key,
|
|
|
|
required this.onPressed,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final VoidCallback onPressed;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<BackspaceKey> createState() => _BackspaceKeyState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _BackspaceKeyState extends State<BackspaceKey> {
|
|
|
|
late final VoidCallback onPressed;
|
|
|
|
|
2022-09-22 23:48:50 +00:00
|
|
|
Color? _color;
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
onPressed = widget.onPressed;
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-09-22 23:48:50 +00:00
|
|
|
_color ??= Theme.of(context).extension<StackColors>()!.numpadBackDefault;
|
2022-08-26 08:11:35 +00:00
|
|
|
return AnimatedContainer(
|
|
|
|
duration: const Duration(milliseconds: 200),
|
|
|
|
curve: Curves.easeInOut,
|
|
|
|
height: 72,
|
|
|
|
width: 72,
|
|
|
|
decoration: ShapeDecoration(
|
|
|
|
shape: const StadiumBorder(),
|
|
|
|
color: _color,
|
|
|
|
shadows: const [],
|
|
|
|
),
|
|
|
|
child: MaterialButton(
|
2022-09-22 23:48:50 +00:00
|
|
|
// splashColor: Theme.of(context).extension<StackColors>()!.highlight,
|
2022-08-26 08:11:35 +00:00
|
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
shape: const StadiumBorder(),
|
|
|
|
onPressed: () {
|
|
|
|
onPressed.call();
|
|
|
|
setState(() {
|
2022-09-22 23:48:50 +00:00
|
|
|
_color = Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.numpadBackDefault
|
|
|
|
.withOpacity(0.8);
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Future<void>.delayed(const Duration(milliseconds: 200), () {
|
|
|
|
if (mounted) {
|
|
|
|
setState(() {
|
2022-09-22 23:48:50 +00:00
|
|
|
_color = Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.numpadBackDefault;
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Center(
|
|
|
|
child: SvgPicture.asset(
|
|
|
|
Assets.svg.delete,
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
2022-09-22 23:48:50 +00:00
|
|
|
color:
|
|
|
|
Theme.of(context).extension<StackColors>()!.numpadTextDefault,
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-21 17:59:18 +00:00
|
|
|
class SubmitKey extends StatelessWidget {
|
|
|
|
const SubmitKey({
|
|
|
|
Key? key,
|
|
|
|
required this.onPressed,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final VoidCallback onPressed;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
height: 72,
|
|
|
|
width: 72,
|
|
|
|
decoration: ShapeDecoration(
|
|
|
|
shape: const StadiumBorder(),
|
2022-09-22 23:48:50 +00:00
|
|
|
color: Theme.of(context).extension<StackColors>()!.numpadBackDefault,
|
2022-09-21 17:59:18 +00:00
|
|
|
shadows: const [],
|
|
|
|
),
|
|
|
|
child: MaterialButton(
|
2022-09-22 23:48:50 +00:00
|
|
|
// splashColor: Theme.of(context).extension<StackColors>()!.highlight,
|
2022-09-21 17:59:18 +00:00
|
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
shape: const StadiumBorder(),
|
|
|
|
onPressed: () {
|
|
|
|
onPressed.call();
|
|
|
|
},
|
|
|
|
child: Center(
|
|
|
|
child: SvgPicture.asset(
|
|
|
|
Assets.svg.arrowRight,
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
2022-09-22 23:48:50 +00:00
|
|
|
color:
|
|
|
|
Theme.of(context).extension<StackColors>()!.numpadTextDefault,
|
2022-09-21 17:59:18 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-08-26 08:11:35 +00:00
|
|
|
|
2023-02-13 20:16:26 +00:00
|
|
|
class CustomKey extends StatelessWidget {
|
|
|
|
const CustomKey({
|
|
|
|
Key? key,
|
|
|
|
required this.onPressed,
|
|
|
|
this.iconAssetName,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final VoidCallback onPressed;
|
|
|
|
final String? iconAssetName;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
height: 72,
|
|
|
|
width: 72,
|
|
|
|
decoration: ShapeDecoration(
|
|
|
|
shape: const StadiumBorder(),
|
|
|
|
color: Theme.of(context).extension<StackColors>()!.numpadBackDefault,
|
|
|
|
shadows: const [],
|
|
|
|
),
|
|
|
|
child: MaterialButton(
|
|
|
|
// splashColor: Theme.of(context).extension<StackColors>()!.highlight,
|
|
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
shape: const StadiumBorder(),
|
|
|
|
onPressed: () {
|
|
|
|
onPressed.call();
|
|
|
|
},
|
|
|
|
child: Center(
|
|
|
|
child: iconAssetName == null
|
|
|
|
? null
|
|
|
|
: SvgPicture.asset(
|
|
|
|
iconAssetName!,
|
|
|
|
width: 20,
|
|
|
|
height: 20,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.numpadTextDefault,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
class PinKeyboard extends StatelessWidget {
|
|
|
|
const PinKeyboard({
|
|
|
|
Key? key,
|
|
|
|
required this.onNumberKeyPressed,
|
|
|
|
required this.onBackPressed,
|
|
|
|
required this.onSubmitPressed,
|
|
|
|
this.backgroundColor,
|
|
|
|
this.width = 264,
|
|
|
|
this.height = 360,
|
2023-02-13 20:16:26 +00:00
|
|
|
this.customKey,
|
2022-08-26 08:11:35 +00:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final ValueSetter<String> onNumberKeyPressed;
|
|
|
|
final VoidCallback onBackPressed;
|
|
|
|
final VoidCallback onSubmitPressed;
|
|
|
|
final Color? backgroundColor;
|
|
|
|
final double? width;
|
|
|
|
final double? height;
|
2023-02-13 20:16:26 +00:00
|
|
|
final CustomKey? customKey;
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
void _backHandler() {
|
|
|
|
onBackPressed.call();
|
|
|
|
}
|
|
|
|
|
2022-09-21 17:59:18 +00:00
|
|
|
void _submitHandler() {
|
|
|
|
onSubmitPressed.call();
|
|
|
|
}
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
void _numberHandler(String number) {
|
|
|
|
onNumberKeyPressed.call(number);
|
2023-04-26 00:02:00 +00:00
|
|
|
HapticFeedback.lightImpact();
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
color: backgroundColor ?? Colors.transparent,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
NumberKey(
|
|
|
|
number: "1",
|
|
|
|
onPressed: _numberHandler,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 24,
|
|
|
|
),
|
|
|
|
NumberKey(
|
|
|
|
number: "2",
|
|
|
|
onPressed: _numberHandler,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 24,
|
|
|
|
),
|
|
|
|
NumberKey(
|
|
|
|
number: "3",
|
|
|
|
onPressed: _numberHandler,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 24,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
NumberKey(
|
|
|
|
number: "4",
|
|
|
|
onPressed: _numberHandler,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 24,
|
|
|
|
),
|
|
|
|
NumberKey(
|
|
|
|
number: "5",
|
|
|
|
onPressed: _numberHandler,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 24,
|
|
|
|
),
|
|
|
|
NumberKey(
|
|
|
|
number: "6",
|
|
|
|
onPressed: _numberHandler,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 24,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
NumberKey(
|
|
|
|
number: "7",
|
|
|
|
onPressed: _numberHandler,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 24,
|
|
|
|
),
|
|
|
|
NumberKey(
|
|
|
|
number: "8",
|
|
|
|
onPressed: _numberHandler,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 24,
|
|
|
|
),
|
|
|
|
NumberKey(
|
|
|
|
number: "9",
|
|
|
|
onPressed: _numberHandler,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 24,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
2023-02-13 20:16:26 +00:00
|
|
|
customKey == null
|
|
|
|
? const SizedBox(
|
|
|
|
height: 72,
|
|
|
|
width: 72,
|
|
|
|
)
|
|
|
|
: customKey!,
|
2022-08-26 08:11:35 +00:00
|
|
|
const SizedBox(
|
|
|
|
width: 24,
|
|
|
|
),
|
|
|
|
NumberKey(
|
|
|
|
number: "0",
|
|
|
|
onPressed: _numberHandler,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 24,
|
|
|
|
),
|
2022-09-23 00:12:39 +00:00
|
|
|
BackspaceKey(
|
|
|
|
onPressed: _backHandler,
|
2022-08-26 08:11:35 +00:00
|
|
|
),
|
2022-09-23 00:12:39 +00:00
|
|
|
// SubmitKey(
|
|
|
|
// onPressed: _submitHandler,
|
|
|
|
// ),
|
2022-08-26 08:11:35 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|