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-11-22 20:42:24 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-06-16 22:47:03 +00:00
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
2022-11-22 20:42:24 +00:00
|
|
|
import 'package:flutter_svg/svg.dart';
|
2023-02-08 19:06:26 +00:00
|
|
|
import 'package:stackwallet/models/exchange/aggregate_currency.dart';
|
2023-02-05 20:32:39 +00:00
|
|
|
import 'package:stackwallet/pages/buy_view/sub_widgets/crypto_selection_view.dart';
|
2023-06-16 22:47:03 +00:00
|
|
|
import 'package:stackwallet/providers/global/locale_provider.dart';
|
2023-05-09 21:57:40 +00:00
|
|
|
import 'package:stackwallet/themes/stack_colors.dart';
|
2023-06-16 22:47:03 +00:00
|
|
|
import 'package:stackwallet/utilities/amount/amount_input_formatter.dart';
|
2022-11-22 20:42:24 +00:00
|
|
|
import 'package:stackwallet/utilities/assets.dart';
|
|
|
|
import 'package:stackwallet/utilities/text_styles.dart';
|
2022-12-30 23:10:25 +00:00
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
2022-11-22 20:42:24 +00:00
|
|
|
import 'package:stackwallet/widgets/loading_indicator.dart';
|
|
|
|
|
2023-06-16 22:47:03 +00:00
|
|
|
class ExchangeTextField extends ConsumerStatefulWidget {
|
2022-11-22 20:42:24 +00:00
|
|
|
const ExchangeTextField({
|
|
|
|
Key? key,
|
|
|
|
this.borderRadius = 0,
|
|
|
|
this.background,
|
|
|
|
required this.controller,
|
|
|
|
this.buttonColor,
|
|
|
|
required this.focusNode,
|
|
|
|
this.buttonContent,
|
|
|
|
required this.textStyle,
|
|
|
|
this.onButtonTap,
|
|
|
|
this.onChanged,
|
|
|
|
this.onSubmitted,
|
|
|
|
this.onTap,
|
|
|
|
required this.isWalletCoin,
|
2023-02-08 17:25:31 +00:00
|
|
|
this.currency,
|
2022-11-22 20:42:24 +00:00
|
|
|
this.readOnly = false,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final double borderRadius;
|
|
|
|
final Color? background;
|
|
|
|
final Color? buttonColor;
|
|
|
|
final Widget? buttonContent;
|
|
|
|
final TextEditingController controller;
|
|
|
|
final FocusNode focusNode;
|
|
|
|
final TextStyle textStyle;
|
|
|
|
final VoidCallback? onTap;
|
|
|
|
final VoidCallback? onButtonTap;
|
|
|
|
final void Function(String)? onChanged;
|
|
|
|
final void Function(String)? onSubmitted;
|
|
|
|
|
|
|
|
final bool isWalletCoin;
|
|
|
|
final bool readOnly;
|
2023-02-08 19:06:26 +00:00
|
|
|
final AggregateCurrency? currency;
|
2022-11-22 20:42:24 +00:00
|
|
|
|
|
|
|
@override
|
2023-06-16 22:47:03 +00:00
|
|
|
ConsumerState<ExchangeTextField> createState() => _ExchangeTextFieldState();
|
2022-11-22 20:42:24 +00:00
|
|
|
}
|
|
|
|
|
2023-06-16 22:47:03 +00:00
|
|
|
class _ExchangeTextFieldState extends ConsumerState<ExchangeTextField> {
|
2022-11-22 20:42:24 +00:00
|
|
|
late final TextEditingController controller;
|
|
|
|
late final FocusNode focusNode;
|
|
|
|
late final TextStyle textStyle;
|
|
|
|
|
|
|
|
late final double borderRadius;
|
|
|
|
|
|
|
|
late final Color? background;
|
|
|
|
late final Color? buttonColor;
|
|
|
|
late final Widget? buttonContent;
|
|
|
|
late final VoidCallback? onButtonTap;
|
|
|
|
late final VoidCallback? onTap;
|
|
|
|
late final void Function(String)? onChanged;
|
|
|
|
late final void Function(String)? onSubmitted;
|
|
|
|
|
2022-12-30 23:10:25 +00:00
|
|
|
final isDesktop = Util.isDesktop;
|
|
|
|
|
2022-11-22 20:42:24 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
borderRadius = widget.borderRadius;
|
|
|
|
background = widget.background;
|
|
|
|
buttonColor = widget.buttonColor;
|
|
|
|
controller = widget.controller;
|
|
|
|
focusNode = widget.focusNode;
|
|
|
|
buttonContent = widget.buttonContent;
|
|
|
|
textStyle = widget.textStyle;
|
|
|
|
onButtonTap = widget.onButtonTap;
|
|
|
|
onChanged = widget.onChanged;
|
|
|
|
onSubmitted = widget.onSubmitted;
|
|
|
|
onTap = widget.onTap;
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: background,
|
|
|
|
borderRadius: BorderRadius.circular(borderRadius),
|
|
|
|
),
|
|
|
|
child: IntrinsicHeight(
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
style: textStyle,
|
|
|
|
controller: controller,
|
|
|
|
focusNode: focusNode,
|
|
|
|
onChanged: onChanged,
|
|
|
|
onTap: onTap,
|
|
|
|
enableSuggestions: false,
|
|
|
|
autocorrect: false,
|
|
|
|
readOnly: widget.readOnly,
|
2022-12-30 23:10:25 +00:00
|
|
|
keyboardType: isDesktop
|
|
|
|
? null
|
|
|
|
: const TextInputType.numberWithOptions(
|
|
|
|
signed: false,
|
|
|
|
decimal: true,
|
|
|
|
),
|
2022-11-22 20:42:24 +00:00
|
|
|
decoration: InputDecoration(
|
|
|
|
contentPadding: const EdgeInsets.only(
|
|
|
|
top: 12,
|
|
|
|
left: 12,
|
|
|
|
),
|
2023-02-08 17:25:31 +00:00
|
|
|
hintText: widget.currency == null ? "select currency" : "0",
|
2022-11-22 20:42:24 +00:00
|
|
|
hintStyle: STextStyles.fieldLabel(context).copyWith(
|
|
|
|
fontSize: 14,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
inputFormatters: [
|
2023-06-16 22:47:03 +00:00
|
|
|
AmountInputFormatter(
|
|
|
|
decimals: 8, // todo change this
|
|
|
|
locale: ref.watch(localeServiceChangeNotifierProvider
|
|
|
|
.select((value) => value.locale)),
|
|
|
|
),
|
|
|
|
// // regex to validate a crypto amount with 8 decimal places
|
|
|
|
// TextInputFormatter.withFunction((oldValue, newValue) =>
|
|
|
|
// RegExp(r'^([0-9]*[,.]?[0-9]{0,8}|[,.][0-9]{0,8})$')
|
|
|
|
// .hasMatch(newValue.text)
|
|
|
|
// ? newValue
|
|
|
|
// : oldValue),
|
2022-11-22 20:42:24 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
MouseRegion(
|
|
|
|
cursor: SystemMouseCursors.click,
|
|
|
|
child: GestureDetector(
|
|
|
|
onTap: () => onButtonTap?.call(),
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: buttonColor,
|
|
|
|
borderRadius: BorderRadius.horizontal(
|
|
|
|
right: Radius.circular(
|
|
|
|
borderRadius,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 16,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: 18,
|
|
|
|
height: 18,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(18),
|
|
|
|
),
|
|
|
|
child: Builder(
|
|
|
|
builder: (context) {
|
2023-02-08 17:25:31 +00:00
|
|
|
if (isStackCoin(widget.currency?.ticker)) {
|
2023-02-05 20:32:39 +00:00
|
|
|
return Center(
|
2023-05-04 19:26:46 +00:00
|
|
|
child: CoinIconForTicker(
|
2023-02-05 20:32:39 +00:00
|
|
|
size: 18,
|
2023-05-04 19:26:46 +00:00
|
|
|
ticker: widget.currency!.ticker,
|
2023-02-05 20:32:39 +00:00
|
|
|
),
|
2023-05-04 19:26:46 +00:00
|
|
|
// child: getIconForTicker(
|
|
|
|
// widget.currency!.ticker,
|
|
|
|
// size: 18,
|
|
|
|
// ),
|
2023-02-05 20:32:39 +00:00
|
|
|
);
|
2023-02-08 17:25:31 +00:00
|
|
|
} else if (widget.currency != null &&
|
|
|
|
widget.currency!.image.isNotEmpty) {
|
2022-11-22 20:42:24 +00:00
|
|
|
return Center(
|
|
|
|
child: SvgPicture.network(
|
2023-02-08 17:25:31 +00:00
|
|
|
widget.currency!.image,
|
2022-11-22 20:42:24 +00:00
|
|
|
height: 18,
|
|
|
|
placeholderBuilder: (_) => Container(
|
|
|
|
width: 18,
|
|
|
|
height: 18,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textFieldDefaultBG,
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
18,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
18,
|
|
|
|
),
|
|
|
|
child: const LoadingIndicator(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Container(
|
|
|
|
width: 18,
|
|
|
|
height: 18,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
// color: Theme.of(context).extension<StackColors>()!.accentColorDark
|
|
|
|
borderRadius: BorderRadius.circular(18),
|
|
|
|
),
|
|
|
|
child: SvgPicture.asset(
|
|
|
|
Assets.svg.circleQuestion,
|
|
|
|
width: 18,
|
|
|
|
height: 18,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textFieldDefaultBG,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 6,
|
|
|
|
),
|
|
|
|
Text(
|
2023-02-08 17:25:31 +00:00
|
|
|
widget.currency?.ticker.toUpperCase() ?? "n/a",
|
2022-11-22 20:42:24 +00:00
|
|
|
style: STextStyles.smallMed14(context).copyWith(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textDark,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (!widget.isWalletCoin)
|
|
|
|
const SizedBox(
|
|
|
|
width: 6,
|
|
|
|
),
|
|
|
|
if (!widget.isWalletCoin)
|
|
|
|
SvgPicture.asset(
|
|
|
|
Assets.svg.chevronDown,
|
|
|
|
width: 5,
|
|
|
|
height: 2.5,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.extension<StackColors>()!
|
|
|
|
.textDark,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|