generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
349 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import 'package:didpay/features/vcs/vcs_form.dart'; | ||
import 'package:didpay/features/vcs/vcs_notifier.dart'; | ||
import 'package:didpay/l10n/app_localizations.dart'; | ||
import 'package:didpay/shared/confirmation_message.dart'; | ||
import 'package:didpay/shared/error_message.dart'; | ||
import 'package:didpay/shared/header.dart'; | ||
import 'package:didpay/shared/loading_message.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_hooks/flutter_hooks.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
|
||
class VcsAddPage extends HookConsumerWidget { | ||
const VcsAddPage({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final vc = useState<AsyncValue<String>?>(null); | ||
|
||
return Scaffold( | ||
appBar: AppBar(), | ||
body: SafeArea( | ||
child: vc.value != null | ||
? vc.value!.when( | ||
data: (_) => ConfirmationMessage( | ||
message: Loc.of(context).credentialAdded, | ||
), | ||
loading: () => | ||
LoadingMessage(message: Loc.of(context).addingCredential), | ||
error: (error, _) => ErrorMessage( | ||
message: error.toString(), | ||
onRetry: () => vc.value = null, | ||
), | ||
) | ||
: Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
Header( | ||
title: Loc.of(context).addACredential, | ||
subtitle: Loc.of(context).enterACredentialJwt, | ||
), | ||
Expanded( | ||
child: VcsForm( | ||
buttonTitle: Loc.of(context).add, | ||
onSubmit: (vcJwt) async => | ||
_addCredential(context, ref, vcJwt, vc), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
|
||
Future<void> _addCredential( | ||
BuildContext context, | ||
WidgetRef ref, | ||
String vcJwt, | ||
ValueNotifier<AsyncValue<String>?> state, | ||
) async { | ||
state.value = const AsyncLoading(); | ||
try { | ||
final credential = await ref.read(vcsProvider.notifier).addJwt(vcJwt); | ||
|
||
if (context.mounted) { | ||
state.value = AsyncData(credential); | ||
} | ||
} on Exception catch (e) { | ||
state.value = AsyncError(e, StackTrace.current); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import 'package:didpay/features/vcs/vcs_qr_tile.dart'; | ||
import 'package:didpay/l10n/app_localizations.dart'; | ||
import 'package:didpay/shared/next_button.dart'; | ||
import 'package:didpay/shared/theme/grid.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_hooks/flutter_hooks.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
|
||
class VcsForm extends HookConsumerWidget { | ||
final String buttonTitle; | ||
final Future<void> Function(String) onSubmit; | ||
|
||
VcsForm({required this.buttonTitle, required this.onSubmit, super.key}); | ||
|
||
final _formKey = GlobalKey<FormState>(); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final focusNode = useFocusNode(); | ||
|
||
final textController = useTextEditingController(); | ||
|
||
return Form( | ||
key: _formKey, | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
Expanded( | ||
child: SingleChildScrollView( | ||
physics: const BouncingScrollPhysics(), | ||
padding: const EdgeInsets.symmetric(horizontal: Grid.side), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
TextFormField( | ||
focusNode: focusNode, | ||
controller: textController, | ||
onTapOutside: (_) => focusNode.unfocus(), | ||
enableSuggestions: false, | ||
autocorrect: false, | ||
decoration: InputDecoration( | ||
labelText: Loc.of(context).credentialHint, | ||
), | ||
validator: (value) => value == null || value.isEmpty | ||
? Loc.of(context).thisFieldCannotBeEmpty | ||
: null, | ||
), | ||
], | ||
), | ||
), | ||
), | ||
VcsQrTile(credentialTextController: textController), | ||
NextButton( | ||
onPressed: () async => onSubmit(textController.text), | ||
title: buttonTitle, | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import 'package:didpay/features/device/device_info_service.dart'; | ||
import 'package:didpay/features/qr/qr_scan_page.dart'; | ||
import 'package:didpay/l10n/app_localizations.dart'; | ||
import 'package:didpay/shared/snackbar/snackbar_service.dart'; | ||
import 'package:didpay/shared/theme/grid.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_hooks/flutter_hooks.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
|
||
class VcsQrTile extends HookConsumerWidget { | ||
final TextEditingController credentialTextController; | ||
|
||
const VcsQrTile({ | ||
required this.credentialTextController, | ||
super.key, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final isPhysicalDevice = useState(true); | ||
final snackbarService = SnackbarService(); | ||
|
||
useEffect( | ||
() { | ||
Future.delayed( | ||
Duration.zero, | ||
() async => isPhysicalDevice.value = | ||
await ref.read(deviceInfoServiceProvider).isPhysicalDevice(), | ||
); | ||
return null; | ||
}, | ||
[], | ||
); | ||
|
||
return Padding( | ||
padding: const EdgeInsets.symmetric(vertical: Grid.xxs), | ||
child: ListTile( | ||
leading: const Icon(Icons.qr_code), | ||
title: Text( | ||
Loc.of(context).scanACredentialJwt, | ||
style: Theme.of(context).textTheme.bodyMedium, | ||
), | ||
trailing: const Icon(Icons.chevron_right), | ||
onTap: () => isPhysicalDevice.value | ||
? _scanQrCode( | ||
context, | ||
credentialTextController, | ||
) | ||
: _simulateScanQrCode( | ||
context, | ||
credentialTextController, | ||
snackbarService, | ||
), | ||
), | ||
); | ||
} | ||
|
||
Future<void> _scanQrCode( | ||
BuildContext context, | ||
TextEditingController credentialTextController, | ||
) async { | ||
final qrValue = await Navigator.of(context).push<String>( | ||
MaterialPageRoute( | ||
builder: (context) => const QrScanPage(), | ||
), | ||
); | ||
|
||
credentialTextController.text = qrValue ?? ''; | ||
} | ||
|
||
Future<void> _simulateScanQrCode( | ||
BuildContext context, | ||
TextEditingController credentialTextController, | ||
SnackbarService snackbarService, | ||
) async { | ||
snackbarService.showSnackBar( | ||
context, | ||
Loc.of(context).credentialScanUnavailable, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.