Skip to content

Commit

Permalink
feat: add modal folder (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-tbd authored Jun 4, 2024
1 parent a36b8ce commit 187767d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 33 deletions.
17 changes: 13 additions & 4 deletions lib/features/account/account_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:didpay/features/account/account_did_page.dart';
import 'package:didpay/features/account/account_management_modal.dart';
import 'package:didpay/features/did/did_provider.dart';
import 'package:didpay/features/modals/modal_remove_item.dart';
import 'package:didpay/features/pfis/add_pfi_page.dart';
import 'package:didpay/features/pfis/pfi.dart';
import 'package:didpay/features/pfis/pfis_notifier.dart';
Expand Down Expand Up @@ -149,7 +149,12 @@ class AccountPage extends HookConsumerWidget {
),
child: const Center(child: Icon(Icons.attach_money)),
),
onTap: () => AccountManagementModal.show(context, ref, pfi: pfi),
onTap: () => ModalRemoveItem.show(
context,
pfi.did,
Loc.of(context).removePfi,
() async => ref.read(pfisProvider.notifier).remove(pfi),
),
);

Widget _buildAddPfiTile(BuildContext context) => ListTile(
Expand Down Expand Up @@ -226,8 +231,12 @@ class AccountPage extends HookConsumerWidget {
),
child: const Center(child: Icon(Icons.gpp_good)),
),
onTap: () =>
AccountManagementModal.show(context, ref, credential: credential),
onTap: () => ModalRemoveItem.show(
context,
credential,
Loc.of(context).removeCredential,
() async => ref.read(vcsProvider.notifier).remove(credential),
),
);

Widget _buildNoCredentialsTile(BuildContext context) => ListTile(
Expand Down
4 changes: 2 additions & 2 deletions lib/features/currency/currency_dropdown.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:didpay/features/currency/currency_modal.dart';
import 'package:didpay/features/modals/modal_select_currency.dart';
import 'package:didpay/features/pfis/pfi.dart';
import 'package:didpay/features/transaction/transaction.dart';
import 'package:didpay/shared/theme/grid.dart';
Expand Down Expand Up @@ -31,7 +31,7 @@ class CurrencyDropdown extends HookConsumerWidget {
backgroundColor: Colors.transparent,
elevation: 0,
),
onPressed: () => CurrencyModal.show(
onPressed: () => ModalSelectCurrency.show(
context,
transactionType,
selectedPfi,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:didpay/features/pfis/pfi.dart';
import 'package:didpay/features/pfis/pfis_notifier.dart';
import 'package:didpay/features/vcs/vcs_notifier.dart';
import 'package:didpay/l10n/app_localizations.dart';
import 'package:didpay/shared/theme/grid.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class AccountManagementModal {
class ModalRemoveItem {
static Future<dynamic> show(
BuildContext context,
WidgetRef ref, {
Pfi? pfi,
String? credential,
}) =>
String title,
String removeText,
Future<void> Function() onRemove,
) =>
showModalBottomSheet(
useSafeArea: true,
isScrollControlled: true,
Expand All @@ -34,7 +30,7 @@ class AccountManagementModal {
children: [
Flexible(
child: AutoSizeText(
pfi != null ? pfi.did : credential!,
title,
style: Theme.of(context).textTheme.titleMedium,
maxLines: 2,
),
Expand All @@ -51,26 +47,15 @@ class AccountManagementModal {
ListTile(
title: Center(
child: Text(
pfi != null
? Loc.of(context).removePfi
: Loc.of(context).removeCredential,
removeText,
style: TextStyle(color: Theme.of(context).colorScheme.error)
.copyWith(
fontWeight: FontWeight.bold,
),
),
),
onTap: () async {
pfi != null
? await ref
.read(pfisProvider.notifier)
.remove(pfi)
.then((_) => Navigator.pop(context))
: await ref
.read(vcsProvider.notifier)
.remove(credential!)
.then((_) => Navigator.pop(context));
},
onTap: () async =>
onRemove().then((_) => Navigator.pop(context)),
),
Divider(
color: Theme.of(context)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:didpay/features/pfis/pfi.dart';
import 'package:didpay/features/transaction/transaction.dart';
import 'package:didpay/l10n/app_localizations.dart';
import 'package:didpay/shared/theme/grid.dart';
import 'package:flutter/material.dart';
import 'package:tbdex/tbdex.dart';

class CurrencyModal {
class ModalSelectCurrency {
static Future<dynamic> show(
BuildContext context,
TransactionType transactionType,
Expand Down Expand Up @@ -35,7 +36,7 @@ class CurrencyModal {
Padding(
padding: const EdgeInsets.symmetric(vertical: Grid.xs),
child: Text(
'Select currency',
Loc.of(context).selectCurrency,
style: Theme.of(context).textTheme.titleMedium,
textAlign: TextAlign.center,
),
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,6 @@
"identityVerificationComplete": "Identity verification complete!",
"issuedCredentials": "Issued credentials",
"removeCredential": "Remove credential",
"noCredentialsIssuedYet": "No credentials issued yet"
"noCredentialsIssuedYet": "No credentials issued yet",
"selectCurrency": "Select currency"
}
6 changes: 6 additions & 0 deletions lib/l10n/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,12 @@ abstract class Loc {
/// In en, this message translates to:
/// **'No credentials issued yet'**
String get noCredentialsIssuedYet;

/// No description provided for @selectCurrency.
///
/// In en, this message translates to:
/// **'Select currency'**
String get selectCurrency;
}

class _LocDelegate extends LocalizationsDelegate<Loc> {
Expand Down
3 changes: 3 additions & 0 deletions lib/l10n/app_localizations_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,7 @@ class LocEn extends Loc {

@override
String get noCredentialsIssuedYet => 'No credentials issued yet';

@override
String get selectCurrency => 'Select currency';
}

0 comments on commit 187767d

Please sign in to comment.