fix button enabled state bug

This commit is contained in:
julian 2024-05-01 16:30:37 -06:00
parent 2de96f15e0
commit 7f0585d4f9
2 changed files with 26 additions and 24 deletions

View file

@ -37,6 +37,7 @@ import 'package:stackwallet/widgets/background.dart';
import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/conditional_parent.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart'; import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
import 'package:stackwallet/widgets/desktop/primary_button.dart';
import 'package:stackwallet/widgets/desktop/secondary_button.dart'; import 'package:stackwallet/widgets/desktop/secondary_button.dart';
import 'package:stackwallet/widgets/fee_slider.dart'; import 'package:stackwallet/widgets/fee_slider.dart';
import 'package:stackwallet/widgets/frost_scaffold.dart'; import 'package:stackwallet/widgets/frost_scaffold.dart';
@ -187,16 +188,24 @@ class _FrostSendViewState extends ConsumerState<FrostSendView> {
int customFeeRate = 1; int customFeeRate = 1;
void _validateRecipientFormStates() { bool _buttonEnabled = false;
bool _validateRecipientFormStatesHelper() {
for (final i in recipientWidgetIndexes) { for (final i in recipientWidgetIndexes) {
final state = ref.read(pRecipient(i).state).state; final state = ref.read(pRecipient(i));
if (state?.amount == null || state?.address == null) { if (state?.amount == null ||
ref.read(_previewTxButtonStateProvider.notifier).state = false; state?.address == null ||
return; state!.address.isEmpty) {
return false;
} }
} }
ref.read(_previewTxButtonStateProvider.notifier).state = true; return true;
return; }
void _validateRecipientFormStates() {
setState(() {
_buttonEnabled = _validateRecipientFormStatesHelper();
});
} }
@override @override
@ -389,12 +398,14 @@ class _FrostSendViewState extends ConsumerState<FrostSendView> {
.state = null; .state = null;
recipientWidgetIndexes.removeAt(i); recipientWidgetIndexes.removeAt(i);
setState(() {}); setState(() {});
_validateRecipientFormStates();
}, },
addAnotherRecipientTapped: () { addAnotherRecipientTapped: () {
// used for tracking recipient forms // used for tracking recipient forms
_greatestWidgetIndex++; _greatestWidgetIndex++;
recipientWidgetIndexes.add(_greatestWidgetIndex); recipientWidgetIndexes.add(_greatestWidgetIndex);
setState(() {}); setState(() {});
_validateRecipientFormStates();
}, },
sendAllTapped: () { sendAllTapped: () {
return ref.read(pAmountFormatter(coin)).format( return ref.read(pAmountFormatter(coin)).format(
@ -549,21 +560,10 @@ class _FrostSendViewState extends ConsumerState<FrostSendView> {
const SizedBox( const SizedBox(
height: 12, height: 12,
), ),
TextButton( PrimaryButton(
onPressed: ref.watch(_previewTxButtonStateProvider.state).state label: "Create multisig transaction",
? _createSignConfig enabled: _buttonEnabled,
: null, onPressed: _createSignConfig,
style: ref.watch(_previewTxButtonStateProvider.state).state
? Theme.of(context)
.extension<StackColors>()!
.getPrimaryEnabledButtonStyle(context)
: Theme.of(context)
.extension<StackColors>()!
.getPrimaryDisabledButtonStyle(context),
child: Text(
"Create config",
style: STextStyles.button(context),
),
), ),
const SizedBox( const SizedBox(
height: 16, height: 16,
@ -574,5 +574,3 @@ class _FrostSendViewState extends ConsumerState<FrostSendView> {
); );
} }
} }
final _previewTxButtonStateProvider = StateProvider((_) => false);

View file

@ -204,6 +204,7 @@ class _RecipientState extends ConsumerState<Recipient> {
focusNode: addressFocusNode, focusNode: addressFocusNode,
style: STextStyles.field(context), style: STextStyles.field(context),
onChanged: (_) { onChanged: (_) {
_updateRecipientData();
setState(() { setState(() {
_addressIsEmpty = addressController.text.isEmpty; _addressIsEmpty = addressController.text.isEmpty;
}); });
@ -394,6 +395,9 @@ class _RecipientState extends ConsumerState<Recipient> {
key: const Key("amountInputFieldCryptoTextFieldKey"), key: const Key("amountInputFieldCryptoTextFieldKey"),
controller: amountController, controller: amountController,
focusNode: amountFocusNode, focusNode: amountFocusNode,
onChanged: (_) {
_updateRecipientData();
},
keyboardType: Util.isDesktop keyboardType: Util.isDesktop
? null ? null
: const TextInputType.numberWithOptions( : const TextInputType.numberWithOptions(