mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-31 06:55:59 +00:00
refactore send card
This commit is contained in:
parent
8e3e8f7d42
commit
92e1c3a4c1
2 changed files with 98 additions and 107 deletions
|
@ -258,32 +258,7 @@ class SendPage extends BasePage {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onRemove: () {
|
onRemove: () {
|
||||||
showPopUp<void>(
|
showDeleteTemplateAlert(context, template, sendViewModel);
|
||||||
context: context,
|
|
||||||
builder: (dialogContext) {
|
|
||||||
return AlertWithTwoActions(
|
|
||||||
alertTitle:
|
|
||||||
S.of(context).template,
|
|
||||||
alertContent: S
|
|
||||||
.of(context)
|
|
||||||
.confirm_delete_template,
|
|
||||||
rightButtonText:
|
|
||||||
S.of(context).delete,
|
|
||||||
leftButtonText:
|
|
||||||
S.of(context).cancel,
|
|
||||||
actionRightButton: () {
|
|
||||||
Navigator.of(dialogContext)
|
|
||||||
.pop();
|
|
||||||
sendViewModel
|
|
||||||
.sendTemplateViewModel
|
|
||||||
.removeTemplate(
|
|
||||||
template: template);
|
|
||||||
},
|
|
||||||
actionLeftButton: () =>
|
|
||||||
Navigator.of(dialogContext)
|
|
||||||
.pop());
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -505,6 +480,25 @@ class SendPage extends BasePage {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void showDeleteTemplateAlert(BuildContext context, Template template, SendViewModel sendViewModel) {
|
||||||
|
showPopUp<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (dialogContext) {
|
||||||
|
return AlertWithTwoActions(
|
||||||
|
alertTitle: S.of(context).template,
|
||||||
|
alertContent: S.of(context).confirm_delete_template,
|
||||||
|
rightButtonText: S.of(context).delete,
|
||||||
|
leftButtonText: S.of(context).cancel,
|
||||||
|
actionRightButton: () {
|
||||||
|
Navigator.of(dialogContext).pop();
|
||||||
|
sendViewModel.sendTemplateViewModel.removeTemplate(template: template);
|
||||||
|
},
|
||||||
|
actionLeftButton: () => Navigator.of(dialogContext).pop(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void presentCurrencyPicker(BuildContext context) async {
|
void presentCurrencyPicker(BuildContext context) async {
|
||||||
await showPopUp<CryptoCurrency>(
|
await showPopUp<CryptoCurrency>(
|
||||||
builder: (_) => Picker(
|
builder: (_) => Picker(
|
||||||
|
|
|
@ -102,12 +102,11 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
}
|
}
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
if (mounted) {
|
_checkWalletCurrency();
|
||||||
final RenderBox renderBox = _containerKey.currentContext!.findRenderObject() as RenderBox;
|
_updateGenericHeight(
|
||||||
_containerHeight = renderBox.size.height;
|
containerKey: _containerKey,
|
||||||
widget.heightNotifier.value = _containerHeight!;
|
dynamicElementKey: _dynamicElementKey,
|
||||||
setState(() {});
|
);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +164,11 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
child: Observer(
|
child: Observer(
|
||||||
builder: (_)
|
builder: (_)
|
||||||
{
|
{
|
||||||
WidgetsBinding.instance!.addPostFrameCallback((_) => _updateHeight());
|
WidgetsBinding.instance!.addPostFrameCallback((_) => _updateGenericHeight(
|
||||||
|
containerKey: _containerKey,
|
||||||
|
dynamicElementKey: _dynamicElementKey,
|
||||||
|
additionalPadding: parsedAddressTopPadding,
|
||||||
|
));
|
||||||
final validator = output.isParsedAddress
|
final validator = output.isParsedAddress
|
||||||
? sendViewModel.textValidator
|
? sendViewModel.textValidator
|
||||||
: sendViewModel.addressValidator;
|
: sendViewModel.addressValidator;
|
||||||
|
@ -192,13 +195,9 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
Theme.of(context).extension<SendPageTheme>()!.textFieldButtonColor,
|
Theme.of(context).extension<SendPageTheme>()!.textFieldButtonColor,
|
||||||
borderColor:
|
borderColor:
|
||||||
Theme.of(context).extension<SendPageTheme>()!.textFieldBorderColor,
|
Theme.of(context).extension<SendPageTheme>()!.textFieldBorderColor,
|
||||||
textStyle: TextStyle(
|
textStyle: genericTextStyle(fontWeight: FontWeight.w500),
|
||||||
fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white),
|
hintStyle: genericTextStyle(fontWeight: FontWeight.w500,
|
||||||
hintStyle: TextStyle(
|
color: Theme.of(context).extension<SendPageTheme>()!.textFieldHintColor),
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
color:
|
|
||||||
Theme.of(context).extension<SendPageTheme>()!.textFieldHintColor),
|
|
||||||
onPushPasteButton: (context) async {
|
onPushPasteButton: (context) async {
|
||||||
output.resetParsedAddress();
|
output.resetParsedAddress();
|
||||||
await output.fetchParsedAddress(context);
|
await output.fetchParsedAddress(context);
|
||||||
|
@ -223,8 +222,7 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
borderColor: Theme.of(context)
|
borderColor: Theme.of(context)
|
||||||
.extension<SendPageTheme>()!
|
.extension<SendPageTheme>()!
|
||||||
.textFieldBorderColor,
|
.textFieldBorderColor,
|
||||||
textStyle: TextStyle(
|
textStyle: genericTextStyle(fontWeight: FontWeight.w500),
|
||||||
fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white),
|
|
||||||
validator: sendViewModel.addressValidator)),
|
validator: sendViewModel.addressValidator)),
|
||||||
Observer(
|
Observer(
|
||||||
builder: (_) => Padding(
|
builder: (_) => Padding(
|
||||||
|
@ -255,10 +253,7 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
sendViewModel.selectedCryptoCurrency.title,
|
sendViewModel.selectedCryptoCurrency.title,
|
||||||
style: TextStyle(
|
style: genericTextStyle(fontSize: 16),
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
fontSize: 16,
|
|
||||||
color: Colors.white),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -266,10 +261,7 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
)
|
)
|
||||||
: Text(
|
: Text(
|
||||||
sendViewModel.selectedCryptoCurrency.title,
|
sendViewModel.selectedCryptoCurrency.title,
|
||||||
style: TextStyle(
|
style: genericTextStyle(fontSize: 16),
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
fontSize: 16,
|
|
||||||
color: Colors.white),
|
|
||||||
),
|
),
|
||||||
sendViewModel.selectedCryptoCurrency.tag != null
|
sendViewModel.selectedCryptoCurrency.tag != null
|
||||||
? Padding(
|
? Padding(
|
||||||
|
@ -288,9 +280,8 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
padding: const EdgeInsets.all(6.0),
|
padding: const EdgeInsets.all(6.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
sendViewModel.selectedCryptoCurrency.tag!,
|
sendViewModel.selectedCryptoCurrency.tag!,
|
||||||
style: TextStyle(
|
style: genericTextStyle(
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.extension<SendPageTheme>()!
|
.extension<SendPageTheme>()!
|
||||||
.textFieldButtonIconColor),
|
.textFieldButtonIconColor),
|
||||||
|
@ -304,10 +295,7 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
padding: const EdgeInsets.only(right: 10.0),
|
padding: const EdgeInsets.only(right: 10.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
':',
|
':',
|
||||||
style: TextStyle(
|
style: genericTextStyle(fontSize: 16),
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
fontSize: 16,
|
|
||||||
color: Colors.white),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -329,16 +317,12 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
),
|
),
|
||||||
hintText: '0.0000',
|
hintText: '0.0000',
|
||||||
borderColor: Colors.transparent,
|
borderColor: Colors.transparent,
|
||||||
textStyle: TextStyle(
|
textStyle: genericTextStyle(fontWeight: FontWeight.w500),
|
||||||
fontSize: 14,
|
placeholderTextStyle: genericTextStyle(
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
color: Colors.white),
|
|
||||||
placeholderTextStyle: TextStyle(
|
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.extension<SendPageTheme>()!
|
.extension<SendPageTheme>()!
|
||||||
.textFieldHintColor,
|
.textFieldHintColor),
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
fontSize: 14),
|
|
||||||
validator: output.sendAll
|
validator: output.sendAll
|
||||||
? sendViewModel.allAmountValidator
|
? sendViewModel.allAmountValidator
|
||||||
: sendViewModel.amountValidator,
|
: sendViewModel.amountValidator,
|
||||||
|
@ -365,9 +349,8 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
child: Text(
|
child: Text(
|
||||||
S.of(context).all,
|
S.of(context).all,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: TextStyle(
|
style: genericTextStyle(
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.extension<SendPageTheme>()!
|
.extension<SendPageTheme>()!
|
||||||
.textFieldButtonIconColor,
|
.textFieldButtonIconColor,
|
||||||
|
@ -397,9 +380,8 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
S.of(context).available_balance + ':',
|
S.of(context).available_balance + ':',
|
||||||
style: TextStyle(
|
style: genericTextStyle(
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.extension<SendPageTheme>()!
|
.extension<SendPageTheme>()!
|
||||||
.textFieldHintColor),
|
.textFieldHintColor),
|
||||||
|
@ -407,9 +389,8 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
sendViewModel.balance,
|
sendViewModel.balance,
|
||||||
style: TextStyle(
|
style: genericTextStyle(
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.extension<SendPageTheme>()!
|
.extension<SendPageTheme>()!
|
||||||
.textFieldHintColor),
|
.textFieldHintColor),
|
||||||
|
@ -435,23 +416,16 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
padding: EdgeInsets.only(top: 9),
|
padding: EdgeInsets.only(top: 9),
|
||||||
child: Text(
|
child: Text(
|
||||||
sendViewModel.fiat.title + ':',
|
sendViewModel.fiat.title + ':',
|
||||||
style: TextStyle(
|
style: genericTextStyle(fontSize: 16),
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
hintText: '0.00',
|
hintText: '0.00',
|
||||||
borderColor:
|
borderColor:
|
||||||
Theme.of(context).extension<SendPageTheme>()!.textFieldBorderColor,
|
Theme.of(context).extension<SendPageTheme>()!.textFieldBorderColor,
|
||||||
textStyle: TextStyle(
|
textStyle: genericTextStyle(fontWeight: FontWeight.w500),
|
||||||
fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white),
|
placeholderTextStyle: genericTextStyle(fontWeight: FontWeight.w500,
|
||||||
placeholderTextStyle: TextStyle(
|
|
||||||
color:
|
color:
|
||||||
Theme.of(context).extension<SendPageTheme>()!.textFieldHintColor,
|
Theme.of(context).extension<SendPageTheme>()!.textFieldHintColor),
|
||||||
fontWeight: FontWeight.w500,
|
|
||||||
fontSize: 14),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
|
@ -462,11 +436,9 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
maxLines: null,
|
maxLines: null,
|
||||||
borderColor:
|
borderColor:
|
||||||
Theme.of(context).extension<SendPageTheme>()!.textFieldBorderColor,
|
Theme.of(context).extension<SendPageTheme>()!.textFieldBorderColor,
|
||||||
textStyle: TextStyle(
|
textStyle: genericTextStyle(fontWeight: FontWeight.w500),
|
||||||
fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white),
|
|
||||||
hintText: S.of(context).note_optional,
|
hintText: S.of(context).note_optional,
|
||||||
placeholderTextStyle: TextStyle(
|
placeholderTextStyle: genericTextStyle(
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
color:
|
color:
|
||||||
Theme.of(context).extension<SendPageTheme>()!.textFieldHintColor),
|
Theme.of(context).extension<SendPageTheme>()!.textFieldHintColor),
|
||||||
|
@ -483,8 +455,8 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text(
|
Text(
|
||||||
S.of(context).send_estimated_fee,
|
S.of(context).send_estimated_fee,
|
||||||
style: TextStyle(
|
style: genericTextStyle(
|
||||||
fontSize: 12, fontWeight: FontWeight.w500, color: Colors.white),
|
fontSize: 12, fontWeight: FontWeight.w500),
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
child: Row(
|
child: Row(
|
||||||
|
@ -498,11 +470,7 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
output.estimatedFee.toString() +
|
output.estimatedFee.toString() +
|
||||||
' ' +
|
' ' +
|
||||||
sendViewModel.selectedCryptoCurrency.toString(),
|
sendViewModel.selectedCryptoCurrency.toString(),
|
||||||
style: TextStyle(
|
style: genericTextStyle(fontSize: 12),
|
||||||
fontSize: 12,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.only(top: 5),
|
padding: EdgeInsets.only(top: 5),
|
||||||
|
@ -512,9 +480,8 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
output.estimatedFeeFiatAmount +
|
output.estimatedFeeFiatAmount +
|
||||||
' ' +
|
' ' +
|
||||||
sendViewModel.fiat.title,
|
sendViewModel.fiat.title,
|
||||||
style: TextStyle(
|
style: genericTextStyle(
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Theme.of(context)
|
color: Theme.of(context)
|
||||||
.extension<SendPageTheme>()!
|
.extension<SendPageTheme>()!
|
||||||
.textFieldHintColor,
|
.textFieldHintColor,
|
||||||
|
@ -551,10 +518,7 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
S.of(context).coin_control,
|
S.of(context).coin_control,
|
||||||
style: TextStyle(
|
style: genericTextStyle(fontSize: 12),
|
||||||
fontSize: 12,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Colors.white),
|
|
||||||
),
|
),
|
||||||
Icon(
|
Icon(
|
||||||
Icons.arrow_forward_ios,
|
Icons.arrow_forward_ios,
|
||||||
|
@ -715,24 +679,57 @@ class SendCardState extends State<SendCard> with AutomaticKeepAliveClientMixin<S
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _updateHeight() {
|
void _checkWalletCurrency() {
|
||||||
|
if (initialPaymentRequest != null &&
|
||||||
|
sendViewModel.walletCurrencyName != initialPaymentRequest!.scheme.toLowerCase()) {
|
||||||
|
showPopUp<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertWithOneAction(
|
||||||
|
alertTitle: S.of(context).error,
|
||||||
|
alertContent: S.of(context).unmatched_currencies,
|
||||||
|
buttonText: S.of(context).ok,
|
||||||
|
buttonAction: () => Navigator.of(context).pop());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _updateGenericHeight({
|
||||||
|
required GlobalKey containerKey,
|
||||||
|
required GlobalKey dynamicElementKey,
|
||||||
|
double additionalPadding = 0.0,
|
||||||
|
}) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
final RenderBox containerBox = _containerKey.currentContext!.findRenderObject() as RenderBox;
|
final RenderBox containerBox = containerKey.currentContext!.findRenderObject() as RenderBox;
|
||||||
final RenderBox dynamicElementBox = _dynamicElementKey.currentContext!.findRenderObject() as RenderBox;
|
final RenderBox dynamicElementBox = dynamicElementKey.currentContext!.findRenderObject() as RenderBox;
|
||||||
|
|
||||||
if (_previousContainerHeight != containerBox.size.height || _previousDynamicElementHeight != dynamicElementBox.size.height) {
|
final newContainerHeight = containerBox.size.height;
|
||||||
_previousContainerHeight = containerBox.size.height;
|
final newDynamicElementHeight = dynamicElementBox.size.height;
|
||||||
_previousDynamicElementHeight = dynamicElementBox.size.height;
|
|
||||||
|
|
||||||
_containerHeight = containerBox.size.height + dynamicElementBox.size.height + parsedAddressTopPadding;
|
if (_previousContainerHeight != newContainerHeight || _previousDynamicElementHeight != newDynamicElementHeight) {
|
||||||
|
_previousContainerHeight = newContainerHeight;
|
||||||
|
_previousDynamicElementHeight = newDynamicElementHeight;
|
||||||
|
|
||||||
|
_containerHeight = newContainerHeight + newDynamicElementHeight + additionalPadding;
|
||||||
widget.heightNotifier.value = _containerHeight!;
|
widget.heightNotifier.value = _containerHeight!;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get wantKeepAlive => true;
|
bool get wantKeepAlive => true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TextStyle genericTextStyle({
|
||||||
|
double fontSize = 14,
|
||||||
|
FontWeight fontWeight = FontWeight.w600,
|
||||||
|
Color color = Colors.white,
|
||||||
|
}) {
|
||||||
|
return TextStyle(
|
||||||
|
fontSize: fontSize,
|
||||||
|
fontWeight: fontWeight,
|
||||||
|
color: color,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue