File tree Expand file tree Collapse file tree
pages/signing/sub_widgets Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ class _SignMessageFormState extends ConsumerState<SignMessageForm> {
9090
9191 messageController.text = ref.read (_pSignState).message;
9292
93- _chooseAddress = IfNotAlreadyAsync (() async {
93+ _chooseAddress = IfNotAlreadyAsync < void > (() async {
9494 final Address ? address;
9595
9696 if (Util .isDesktop) {
@@ -166,7 +166,7 @@ class _SignMessageFormState extends ConsumerState<SignMessageForm> {
166166 }
167167 }).execute;
168168
169- _sign = IfNotAlreadyAsync (() async {
169+ _sign = IfNotAlreadyAsync < void > (() async {
170170 Exception ? ex;
171171
172172 final state = ref.read (_pSignState);
Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ class _VerifyMessageFormState extends ConsumerState<VerifyMessageForm> {
8282 messageController.text = ref.read (_pVerifyState).message;
8383 signatureController.text = ref.read (_pVerifyState).signature;
8484
85- _verify = IfNotAlreadyAsync (() async {
85+ _verify = IfNotAlreadyAsync < void > (() async {
8686 Exception ? ex;
8787
8888 final verified = await showLoading (
Original file line number Diff line number Diff line change @@ -18,18 +18,24 @@ class IfNotAlready {
1818 }
1919}
2020
21- class IfNotAlreadyAsync {
22- final Future <void > Function () _function;
21+ class IfNotAlreadyAsync <T > {
22+ final Future <void > Function ()? _function;
23+ final Future <void > Function (T ? args)? _functionWithArgs;
2324
2425 bool _locked = false ;
2526
26- IfNotAlreadyAsync (this ._function);
27+ IfNotAlreadyAsync (this ._function) : _functionWithArgs = null ;
28+ IfNotAlreadyAsync .withArgs (this ._functionWithArgs) : _function = null ;
2729
28- Future <void > execute () async {
30+ Future <void > execute ([ T ? args] ) async {
2931 if (! _locked) {
3032 _locked = true ;
3133 try {
32- await _function ();
34+ if (_function == null ) {
35+ await _function !();
36+ } else {
37+ await _functionWithArgs !(args);
38+ }
3339 } finally {
3440 _locked = false ;
3541 }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
55import 'package:qr_code_scanner_plus/qr_code_scanner_plus.dart' ;
66
77import '../themes/stack_colors.dart' ;
8+ import '../utilities/if_not_already.dart' ;
89import '../utilities/text_styles.dart' ;
910import 'background.dart' ;
1011import 'custom_buttons/app_bar_icon_button.dart' ;
@@ -23,10 +24,18 @@ class _QrScannerState extends State<QrScanner> {
2324
2425 StreamSubscription <Barcode >? sub;
2526
26- void _onScanned (String ? data) {
27- if (data != null && mounted) {
28- Navigator .of (context).pop (data);
29- }
27+ late final Future <void > Function (String ? ) _onScanned;
28+
29+ @override
30+ void initState () {
31+ super .initState ();
32+
33+ _onScanned = IfNotAlreadyAsync <String >.withArgs ((data) async {
34+ await sub? .cancel ();
35+ if (mounted) {
36+ Navigator .of (context).pop (data);
37+ }
38+ }).execute;
3039 }
3140
3241 // In order to get hot reload to work we need to pause the camera if the platform
You can’t perform that action at this time.
0 commit comments