Skip to content

Commit

Permalink
fix: replace willPopScope with popScope, refactor
Browse files Browse the repository at this point in the history
Signed-off-by: phuoc <[email protected]>
  • Loading branch information
phuocbitmark committed Feb 27, 2024
1 parent 2effa36 commit be6a233
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 155 deletions.
10 changes: 5 additions & 5 deletions lib/screen/interactive_postcard/stamp_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ class _StampPreviewState extends State<StampPreview> with AfterLayoutMixin {
if (!isStampSuccess) {
await UIHelper.showPostcardStampFailed(context);
}
if (mounted) {
if (context.mounted) {
_onClose(context);
}
}
});
} catch (e) {
if (e is DioException) {
if (!mounted) {
if (!context.mounted) {
return;
}
if (e.isAlreadyClaimedPostcard) {
Expand All @@ -104,7 +104,7 @@ class _StampPreviewState extends State<StampPreview> with AfterLayoutMixin {
e,
);
}
if (!mounted) {
if (!context.mounted) {
return;
}
unawaited(Navigator.of(context).pushNamedAndRemoveUntil(
Expand Down Expand Up @@ -156,8 +156,8 @@ class _StampPreviewState extends State<StampPreview> with AfterLayoutMixin {
Widget build(BuildContext context) {
final theme = Theme.of(context);
const backgroundColor = AppColor.chatPrimaryColor;
return WillPopScope(
onWillPop: () async => !confirming,
return PopScope(
canPop: !confirming,
child: Scaffold(
backgroundColor: backgroundColor,
appBar: getCloseAppBar(
Expand Down
127 changes: 62 additions & 65 deletions lib/screen/irl_screen/sign_message_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,78 +161,75 @@ class _IRLSignMessageScreenState extends State<IRLSignMessageScreen> {

final theme = Theme.of(context);

return WillPopScope(
onWillPop: () async => true,
child: Scaffold(
appBar: getBackAppBar(
context,
onBack: () {
Navigator.of(context).pop();
},
title: 'signature_request'.tr(),
),
body: Container(
margin: const EdgeInsets.only(bottom: 32),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
addTitleSpace(),
Padding(
padding: ResponsiveLayout.pageHorizontalEdgeInsets,
child: _metadataInfo(widget.payload.metadata),
return Scaffold(
appBar: getBackAppBar(
context,
onBack: () {
Navigator.of(context).pop();
},
title: 'signature_request'.tr(),
),
body: Container(
margin: const EdgeInsets.only(bottom: 32),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
addTitleSpace(),
Padding(
padding: ResponsiveLayout.pageHorizontalEdgeInsets,
child: _metadataInfo(widget.payload.metadata),
),
const SizedBox(height: 60),
addOnlyDivider(),
const SizedBox(height: 30),
Padding(
padding: ResponsiveLayout.pageHorizontalEdgeInsets,
child: Text(
'message'.tr(),
style: theme.textTheme.ppMori400Black14,
),
const SizedBox(height: 60),
addOnlyDivider(),
const SizedBox(height: 30),
Padding(
padding: ResponsiveLayout.pageHorizontalEdgeInsets,
),
const SizedBox(height: 4),
Padding(
padding: ResponsiveLayout.pageHorizontalEdgeInsets,
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 20, horizontal: 22),
decoration: BoxDecoration(
color: AppColor.auLightGrey,
borderRadius: BorderRadius.circular(5),
),
child: Text(
'message'.tr(),
messageInUtf8,
style: theme.textTheme.ppMori400Black14,
),
),
const SizedBox(height: 4),
Padding(
padding: ResponsiveLayout.pageHorizontalEdgeInsets,
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 20, horizontal: 22),
decoration: BoxDecoration(
color: AppColor.auLightGrey,
borderRadius: BorderRadius.circular(5),
),
child: Text(
messageInUtf8,
style: theme.textTheme.ppMori400Black14,
),
),
),
],
),
),
),
Padding(
padding: ResponsiveLayout.pageHorizontalEdgeInsets,
child: Row(
children: [
Expanded(
child: PrimaryButton(
text: 'sign'.tr(),
onTap: _currentWallet != null
? () => withDebounce(_sign)
: null,
),
)
),
],
),
)
],
),
),
),
Padding(
padding: ResponsiveLayout.pageHorizontalEdgeInsets,
child: Row(
children: [
Expanded(
child: PrimaryButton(
text: 'sign'.tr(),
onTap: _currentWallet != null
? () => withDebounce(_sign)
: null,
),
)
],
),
)
],
),
),
);
Expand Down
108 changes: 52 additions & 56 deletions lib/screen/onboarding/view_address/name_view_only_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ class NameViewOnlyAddressPage extends StatefulWidget {
class _NameViewOnlyAddressPageState extends State<NameViewOnlyAddressPage> {
final TextEditingController _nameController = TextEditingController();

bool isSavingAliasDisabled = false;
bool canPop = false;
bool _isSavingAliasDisabled = false;

void saveAliasButtonChangedState() {
setState(() {
isSavingAliasDisabled = !isSavingAliasDisabled;
_isSavingAliasDisabled = !_isSavingAliasDisabled;
});
}

Expand All @@ -59,62 +58,59 @@ class _NameViewOnlyAddressPageState extends State<NameViewOnlyAddressPage> {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return WillPopScope(
onWillPop: () async => canPop,
child: Scaffold(
appBar: getBackAppBar(context,
title: 'view_existing_address'.tr(),
onBack: () => Navigator.of(context).pop()),
body: Container(
margin: ResponsiveLayout.pageHorizontalEdgeInsetsWithSubmitButton,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
addTitleSpace(),
Text(
'aa_you_can_add'.tr(),
style: theme.textTheme.ppMori400Black14,
),
const SizedBox(height: 15),
AuTextField(
labelSemantics: 'enter_alias_link',
title: '',
placeholder: 'enter_alias'.tr(),
controller: _nameController,
onChanged: (valueChanged) {
if (_nameController.text.trim().isEmpty !=
isSavingAliasDisabled) {
saveAliasButtonChangedState();
}
}),
],
),
return Scaffold(
appBar: getBackAppBar(context,
title: 'view_existing_address'.tr(),
onBack: () => Navigator.of(context).pop()),
body: Container(
margin: ResponsiveLayout.pageHorizontalEdgeInsetsWithSubmitButton,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
addTitleSpace(),
Text(
'aa_you_can_add'.tr(),
style: theme.textTheme.ppMori400Black14,
),
const SizedBox(height: 15),
AuTextField(
labelSemantics: 'enter_alias_link',
title: '',
placeholder: 'enter_alias'.tr(),
controller: _nameController,
onChanged: (valueChanged) {
if (_nameController.text.trim().isEmpty !=
_isSavingAliasDisabled) {
saveAliasButtonChangedState();
}
}),
],
),
),
Row(
children: [
Expanded(
child: PrimaryButton(
text: 'continue'.tr(),
onTap: isSavingAliasDisabled
? null
: () {
context.read<AccountsBloc>().add(
NameLinkedAccountEvent(
widget.connection, _nameController.text));
_doneNaming();
},
),
),
Row(
children: [
Expanded(
child: PrimaryButton(
text: 'continue'.tr(),
onTap: _isSavingAliasDisabled
? null
: () {
context.read<AccountsBloc>().add(
NameLinkedAccountEvent(
widget.connection, _nameController.text));
_doneNaming();
},
),
],
),
],
),
),
],
),
],
),
),
);
Expand Down
5 changes: 2 additions & 3 deletions lib/screen/tezos_beacon/au_sign_message_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@ class _AUSignMessagePageState extends State<AUSignMessagePage> {

final theme = Theme.of(context);

return WillPopScope(
onWillPop: () async {
return PopScope(
onPopInvoked: (_) async {
await _rejectRequest(reason: 'User reject');
return true;
},
child: Scaffold(
appBar: getBackAppBar(
Expand Down
5 changes: 2 additions & 3 deletions lib/screen/tezos_beacon/tb_send_transaction_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ class _TBSendTransactionPageState extends State<TBSendTransactionPage> {
? '- XTZ (- USD)'
: '${xtzFormatter.format(total)} XTZ '
'(${_exchangeRate?.xtzToUsd(total)} USD)';
return WillPopScope(
onWillPop: () async {
return PopScope(
onPopInvoked: (_) async {
if (wc2Topic != null) {
unawaited(_wc2Service.respondOnReject(
wc2Topic,
Expand All @@ -308,7 +308,6 @@ class _TBSendTransactionPageState extends State<TBSendTransactionPage> {
unawaited(injector<TezosBeaconService>()
.operationResponse(widget.request.id, null));
}
return true;
},
child: Scaffold(
appBar: getBackAppBar(
Expand Down
10 changes: 3 additions & 7 deletions lib/screen/tezos_beacon/tb_sign_message_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:autonomy_flutter/common/injector.dart';
import 'package:autonomy_flutter/database/cloud_database.dart';
import 'package:autonomy_flutter/model/connection_request_args.dart';
import 'package:autonomy_flutter/service/local_auth_service.dart';
import 'package:autonomy_flutter/service/metric_client_service.dart';
import 'package:autonomy_flutter/service/tezos_beacon_service.dart';
import 'package:autonomy_flutter/service/tezos_service.dart';
import 'package:autonomy_flutter/service/wc2_service.dart';
Expand Down Expand Up @@ -129,12 +128,10 @@ class _TBSignMessagePageState extends State<TBSignMessagePage> {
.signMessage(_currentPersona!.wallet, _currentPersona!.index, message);
await _approveRequest(signature: signature);
log.info('[TBSignMessagePage] _sign: $signature');
if (!mounted) {
if (!context.mounted) {
return;
}

final metricClient = injector.get<MetricClientService>();

Navigator.of(context).pop(true);
showInfoNotification(
const Key('signed'),
Expand All @@ -157,10 +154,9 @@ class _TBSignMessagePageState extends State<TBSignMessagePage> {

final theme = Theme.of(context);

return WillPopScope(
onWillPop: () async {
return PopScope(
onPopInvoked: (_) async {
await _rejectRequest(reason: 'User reject');
return true;
},
child: Scaffold(
appBar: getBackAppBar(
Expand Down
5 changes: 2 additions & 3 deletions lib/screen/wallet_connect/send/wc_send_transaction_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class _WCSendTransactionPageState extends State<WCSendTransactionPage> {
final padding = ResponsiveLayout.pageEdgeInsets.copyWith(top: 0, bottom: 0);
final divider = addDivider(height: 20);

return WillPopScope(
onWillPop: () async {
return PopScope(
onPopInvoked: (_) async {
context.read<WCSendTransactionBloc>().add(
WCSendTransactionRejectEvent(
widget.args.peerMeta,
Expand All @@ -77,7 +77,6 @@ class _WCSendTransactionPageState extends State<WCSendTransactionPage> {
isIRL: widget.args.isIRL,
),
);
return true;
},
child: Scaffold(
appBar: getBackAppBar(
Expand Down
Loading

0 comments on commit be6a233

Please sign in to comment.