generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
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
14 changed files
with
196 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import 'package:dap/dap.dart'; | ||
import 'package:didpay/features/did/did_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 DapForm extends HookConsumerWidget { | ||
final String buttonTitle; | ||
final void Function(String) onSubmit; | ||
|
||
DapForm({required this.buttonTitle, required this.onSubmit, super.key}); | ||
|
||
final _formKey = GlobalKey<FormState>(); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final dap = useState<Dap?>(null); | ||
final errorText = useState<String?>(null); | ||
final focusNode = useFocusNode(); | ||
|
||
final textController = useTextEditingController(); | ||
final errorMessage = Loc.of(context).invalidDap; | ||
|
||
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, | ||
onTap: () => errorText.value = null, | ||
onTapOutside: (_) async => _updateErrorText( | ||
textController.text, | ||
errorMessage, | ||
dap, | ||
errorText, | ||
).then((_) => focusNode.unfocus()), | ||
onFieldSubmitted: (_) async => _updateErrorText( | ||
textController.text, | ||
errorMessage, | ||
dap, | ||
errorText, | ||
), | ||
enableSuggestions: false, | ||
autocorrect: false, | ||
decoration: InputDecoration( | ||
labelText: Loc.of(context).dapHint, | ||
errorText: errorText.value, | ||
), | ||
validator: (value) => value == null || value.isEmpty | ||
? Loc.of(context).thisFieldCannotBeEmpty | ||
: null, | ||
), | ||
], | ||
), | ||
), | ||
), | ||
DidQrTile( | ||
title: Loc.of(context).dontKnowTheirDap, | ||
didTextController: textController, | ||
errorText: errorText, | ||
), | ||
NextButton( | ||
onPressed: () async => _updateErrorText( | ||
textController.text, | ||
errorMessage, | ||
dap, | ||
errorText, | ||
).then( | ||
(_) => errorText.value == null | ||
? onSubmit(textController.text) | ||
: null, | ||
), | ||
title: buttonTitle, | ||
), | ||
], | ||
), | ||
); | ||
} | ||
|
||
Future<void> _updateErrorText( | ||
String inputText, | ||
String errorMessage, | ||
ValueNotifier<Dap?> dap, | ||
ValueNotifier<String?> errorText, | ||
) async { | ||
try { | ||
dap.value = Dap.parse(inputText); | ||
errorText.value = null; | ||
} on Exception { | ||
errorText.value = errorMessage; | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.