Skip to content

Commit

Permalink
[UnregisterParticipant] fix potential dialog popping error while unre…
Browse files Browse the repository at this point in the history
…gistering (#1526)

* fix potential dialog popping error while unregistering

* fmt
  • Loading branch information
clangenb authored Oct 22, 2023
1 parent aa01557 commit 65b893f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:ew_test_keys/ew_test_keys.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

Expand All @@ -9,9 +10,26 @@ import 'package:encointer_wallet/l10n/l10.dart';
import 'package:encointer_wallet/service/tx/lib/tx.dart';
import 'package:encointer_wallet/store/app.dart';

class UnregisteredLinkButton extends StatelessWidget {
class UnregisteredLinkButton extends StatefulWidget {
const UnregisteredLinkButton({super.key});

@override
State<UnregisteredLinkButton> createState() => _UnregisteredLinkButtonState();
}

class _UnregisteredLinkButtonState extends State<UnregisteredLinkButton> {
bool _submitting = false;

Future<void> _onPressed() async {
setState(() {
_submitting = true;
});
await submitUnRegisterParticipant(context, context.read<AppStore>(), webApi);
setState(() {
_submitting = false;
});
}

@override
Widget build(BuildContext context) {
final l10n = context.l10n;
Expand All @@ -25,15 +43,15 @@ class UnregisteredLinkButton extends StatelessWidget {
onOK: () => Navigator.pop(context, true),
);
if (shouldUnregister ?? false) {
AppAlert.showLoadingDialog(context, l10n.loading);
await submitUnRegisterParticipant(context, context.read<AppStore>(), webApi);
Navigator.pop(context);
await _onPressed();
}
},
child: Text(
l10n.unregister,
style: context.bodyMedium.copyWith(color: AppColors.encointerGrey, decoration: TextDecoration.underline),
),
child: !_submitting
? Text(
l10n.unregister,
style: context.bodyMedium.copyWith(color: AppColors.encointerGrey, decoration: TextDecoration.underline),
)
: const CupertinoActivityIndicator(),
);
}
}
12 changes: 0 additions & 12 deletions app/lib/utils/alerts/app_alert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ class AppAlert {
);
}

static void showLoadingDialog(BuildContext context, String title) {
showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text(title),
content: const SizedBox(height: 64, child: CupertinoActivityIndicator()),
);
},
);
}

static Future<T?> showConfirmDialog<T>({
required BuildContext context,
required VoidCallback onOK,
Expand Down

0 comments on commit 65b893f

Please sign in to comment.