Skip to content
Snippets Groups Projects
Commit ce697ef0 authored by vjrj's avatar vjrj
Browse files

Added connectivity status to send btn

parent cd3e9afe
No related branches found
No related tags found
No related merge requests found
import 'package:connectivity_wrapper/connectivity_wrapper.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
...@@ -35,6 +36,20 @@ class _PayFormState extends State<PayForm> { ...@@ -35,6 +36,20 @@ class _PayFormState extends State<PayForm> {
if (state.comment != null && _commentController.text != state.comment) { if (state.comment != null && _commentController.text != state.comment) {
_commentController.text = state.comment; _commentController.text = state.comment;
} }
final ButtonStyle payBtnStyle = ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 25),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
foregroundColor: Colors.white,
backgroundColor: Theme.of(context).colorScheme.primary,
textStyle: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
),
);
final Widget payBtnText = Text(tr('g1_form_pay_send') +
(!kReleaseMode ? ' ${state.amount} ${state.comment}' : ''));
return Form( return Form(
key: _formKey, key: _formKey,
child: Column( child: Column(
...@@ -70,51 +85,47 @@ class _PayFormState extends State<PayForm> { ...@@ -70,51 +85,47 @@ class _PayFormState extends State<PayForm> {
}, },
), ),
const SizedBox(height: 10.0), const SizedBox(height: 10.0),
ElevatedButton( ConnectivityWidgetWrapper(
onPressed: (!state.canBeSent() || stacked: false,
state.amount == null || offlineWidget: ElevatedButton(
!_commentValidate() || onPressed: null,
!_weHaveBalance(context, state.amount!)) style: payBtnStyle,
? null child: _buildBtn(Text(tr('offline'))),
: () async {
try {
await payWithRetry(context, state, false);
} on RetryException {
// Here the transactions can be lost, so we must implement some manual retry use
await payWithRetry(context, state, true);
}
},
style: ElevatedButton.styleFrom(
padding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 25),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
), ),
foregroundColor: Colors.white, child: ElevatedButton(
backgroundColor: Theme.of(context).colorScheme.primary, onPressed: (!state.canBeSent() ||
textStyle: const TextStyle( state.amount == null ||
fontWeight: FontWeight.bold, !_commentValidate() ||
fontSize: 16, !_weHaveBalance(context, state.amount!))
), ? null
), : () async {
child: Row( try {
mainAxisAlignment: MainAxisAlignment.center, await payWithRetry(context, state, false);
children: <Widget>[ } on RetryException {
const Icon(Icons.send), // Here the transactions can be lost, so we must implement some manual retry use
const SizedBox(width: 10), await payWithRetry(context, state, true);
Text(tr('g1_form_pay_send') + }
(!kReleaseMode },
? ' ${state.amount} ${state.comment}' style: payBtnStyle,
: '')), child: _buildBtn(payBtnText),
], ))
),
)
], ],
), ),
); );
}); });
} }
Row _buildBtn(Widget payBtnText) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Icon(Icons.send),
const SizedBox(width: 10),
payBtnText,
],
);
}
bool _commentValidate() { bool _commentValidate() {
final bool? val = _formKey.currentState?.validate(); final bool? val = _formKey.currentState?.validate();
logger('Validating comment: $val'); logger('Validating comment: $val');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment