From 60a06577bc67af00e728b1262ef24441f7560656 Mon Sep 17 00:00:00 2001 From: Godwin Asuquo Date: Wed, 19 Oct 2022 11:07:04 +0300 Subject: [PATCH] Add done button to iOS keyboard --- .../nodes/node_create_or_edit_page.dart | 215 ++++++++++-------- lib/src/widgets/blockchain_height_widget.dart | 34 ++- 2 files changed, 147 insertions(+), 102 deletions(-) diff --git a/lib/src/screens/nodes/node_create_or_edit_page.dart b/lib/src/screens/nodes/node_create_or_edit_page.dart index bd8153226..e9d5c26c4 100644 --- a/lib/src/screens/nodes/node_create_or_edit_page.dart +++ b/lib/src/screens/nodes/node_create_or_edit_page.dart @@ -1,10 +1,11 @@ import 'package:cake_wallet/core/execution_state.dart'; import 'package:cake_wallet/src/widgets/alert_with_one_action.dart'; +import 'package:cake_wallet/src/widgets/keyboard_done_button.dart'; import 'package:cake_wallet/src/widgets/standard_checkbox.dart'; import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/cupertino.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; +import 'package:keyboard_actions/keyboard_actions.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/core/node_address_validator.dart'; @@ -68,7 +69,22 @@ class NodeCreateOrEditPage extends BasePage { String get title => S.current.node_new; final NodeCreateOrEditViewModel nodeCreateOrEditViewModel; + final _nodePortFocusNode = FocusNode(); + KeyboardActionsConfig _buildConfig(BuildContext context) { + return KeyboardActionsConfig( + keyboardActionsPlatform: KeyboardActionsPlatform.IOS, + keyboardBarColor: + Theme.of(context).accentTextTheme!.bodyText1!.backgroundColor!, + nextFocus: false, + actions: [ + KeyboardActionsItem( + focusNode: _nodePortFocusNode, + toolbarButtons: [(_) => KeyboardDoneButton()], + ), + ], + ); + } @override Widget body(BuildContext context) { @@ -104,47 +120,24 @@ class NodeCreateOrEditPage extends BasePage { } }); - return Container( - padding: EdgeInsets.only(left: 24, right: 24), - child: ScrollableWithBottomSection( - contentPadding: EdgeInsets.only(bottom: 24.0), - content: Form( - key: _formKey, - child: Column( - children: [ - Row( - children: [ - Expanded( - child: BaseTextFormField( - controller: _addressController, - hintText: S.of(context).node_address, - validator: NodeAddressValidator(), - ) - ) - ], - ), - SizedBox(height: 10.0), - Row( - children: [ - Expanded( - child: BaseTextFormField( - controller: _portController, - hintText: S.of(context).node_port, - keyboardType: TextInputType.numberWithOptions( - signed: false, decimal: false), - validator: NodePortValidator(), - ) - ) - ], - ), - SizedBox(height: 10.0), - if (nodeCreateOrEditViewModel.hasAuthCredentials) ...[ + return KeyboardActions( + autoScroll: false, + config: _buildConfig(context), + child: Container( + padding: EdgeInsets.only(left: 24, right: 24), + child: ScrollableWithBottomSection( + contentPadding: EdgeInsets.only(bottom: 24.0), + content: Form( + key: _formKey, + child: Column( + children: [ Row( children: [ Expanded( child: BaseTextFormField( - controller: _loginController, - hintText: S.of(context).login, + controller: _addressController, + hintText: S.of(context).node_address, + validator: NodeAddressValidator(), ) ) ], @@ -154,74 +147,102 @@ class NodeCreateOrEditPage extends BasePage { children: [ Expanded( child: BaseTextFormField( - controller: _passwordController, - hintText: S.of(context).password, + controller: _portController, + hintText: S.of(context).node_port, + focusNode: _nodePortFocusNode, + keyboardType: TextInputType.numberWithOptions( + signed: false, decimal: false), + validator: NodePortValidator(), ) ) ], ), - Padding( - padding: EdgeInsets.only(top: 20), - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.max, - children: [ - Observer( - builder: (_) => StandardCheckbox( - value: nodeCreateOrEditViewModel.useSSL, - onChanged: (value) => - nodeCreateOrEditViewModel.useSSL = value, - caption: S.of(context).use_ssl, - )) + SizedBox(height: 10.0), + if (nodeCreateOrEditViewModel.hasAuthCredentials) ...[ + Row( + children: [ + Expanded( + child: BaseTextFormField( + controller: _loginController, + hintText: S.of(context).login, + ) + ) ], - )) - ] - ], - )), - bottomSectionPadding: EdgeInsets.only(bottom: 24), - bottomSection: Observer( - builder: (_) => Row( - children: [ - Flexible( - child: Container( - padding: EdgeInsets.only(right: 8.0), - child: LoadingPrimaryButton( + ), + SizedBox(height: 10.0), + Row( + children: [ + Expanded( + child: BaseTextFormField( + controller: _passwordController, + hintText: S.of(context).password, + ) + ) + ], + ), + Padding( + padding: EdgeInsets.only(top: 20), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + children: [ + Observer( + builder: (_) => StandardCheckbox( + value: nodeCreateOrEditViewModel.useSSL, + onChanged: (value) => + nodeCreateOrEditViewModel.useSSL = value, + caption: S.of(context).use_ssl, + )) + ], + )) + ] + ], + )), + bottomSectionPadding: EdgeInsets.only(bottom: 24), + bottomSection: Observer( + builder: (_) => Row( + children: [ + Flexible( + child: Container( + padding: EdgeInsets.only(right: 8.0), + child: LoadingPrimaryButton( + onPressed: () async { + if (_formKey.currentState != null && !_formKey.currentState!.validate()) { + return; + } + + await nodeCreateOrEditViewModel.connect(); + }, + isLoading: nodeCreateOrEditViewModel + .connectionState is IsExecutingState, + text: S.of(context).node_test, + isDisabled: !nodeCreateOrEditViewModel.isReady, + color: Colors.orange, + textColor: Colors.white), + )), + Flexible( + child: Container( + padding: EdgeInsets.only(left: 8.0), + child: PrimaryButton( onPressed: () async { if (_formKey.currentState != null && !_formKey.currentState!.validate()) { return; } - - await nodeCreateOrEditViewModel.connect(); + + await nodeCreateOrEditViewModel.save(); + Navigator.of(context).pop(); }, - isLoading: nodeCreateOrEditViewModel - .connectionState is IsExecutingState, - text: S.of(context).node_test, - isDisabled: !nodeCreateOrEditViewModel.isReady, - color: Colors.orange, - textColor: Colors.white), - )), - Flexible( - child: Container( - padding: EdgeInsets.only(left: 8.0), - child: PrimaryButton( - onPressed: () async { - if (_formKey.currentState != null && !_formKey.currentState!.validate()) { - return; - } - - await nodeCreateOrEditViewModel.save(); - Navigator.of(context).pop(); - }, - text: S.of(context).save, - color: Theme.of(context).accentTextTheme!.bodyText1!.color!, - textColor: Colors.white, - isDisabled: (!nodeCreateOrEditViewModel.isReady)|| - (nodeCreateOrEditViewModel - .connectionState is IsExecutingState), - ), - )), - ], - )), - )); + text: S.of(context).save, + color: Theme.of(context).accentTextTheme!.bodyText1!.color!, + textColor: Colors.white, + isDisabled: (!nodeCreateOrEditViewModel.isReady)|| + (nodeCreateOrEditViewModel + .connectionState is IsExecutingState), + ), + )), + ], + )), + )), + ); } } diff --git a/lib/src/widgets/blockchain_height_widget.dart b/lib/src/widgets/blockchain_height_widget.dart index f40ef0cf1..aa0e66d08 100644 --- a/lib/src/widgets/blockchain_height_widget.dart +++ b/lib/src/widgets/blockchain_height_widget.dart @@ -1,9 +1,11 @@ +import 'package:cake_wallet/src/widgets/keyboard_done_button.dart'; import 'package:cake_wallet/utils/date_picker.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/monero/monero.dart'; import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; +import 'package:keyboard_actions/keyboard_actions.dart'; class BlockchainHeightWidget extends StatefulWidget { BlockchainHeightWidget({ @@ -29,7 +31,22 @@ class BlockchainHeightState extends State { int get height => _height; int _height = 0; - + final _restoreFocusNode = FocusNode(); + + KeyboardActionsConfig _buildConfig(BuildContext context) { + return KeyboardActionsConfig( + keyboardActionsPlatform: KeyboardActionsPlatform.IOS, + keyboardBarColor: + Theme.of(context).accentTextTheme!.bodyText1!.backgroundColor!, + nextFocus: false, + actions: [ + KeyboardActionsItem( + focusNode: _restoreFocusNode, + toolbarButtons: [(_) => KeyboardDoneButton()], + ), + ], + ); + } @override void initState() { restoreHeightController.addListener(() { @@ -55,7 +72,11 @@ class BlockchainHeightState extends State { @override Widget build(BuildContext context) { - return Column( + + return KeyboardActions( + autoScroll: false, + config: _buildConfig(context), + child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( @@ -64,12 +85,14 @@ class BlockchainHeightState extends State { child: Container( padding: EdgeInsets.only(top: 20.0, bottom: 10.0), child: BaseTextFormField( - focusNode: widget.focusNode, + focusNode: _restoreFocusNode, controller: restoreHeightController, keyboardType: TextInputType.numberWithOptions( signed: false, decimal: false), hintText: S.of(context).widgets_restore_from_blockheight, - ))) + ), + ), + ) ], ), if (widget.hasDatePicker) ...[ @@ -112,7 +135,8 @@ class BlockchainHeightState extends State { ) ] ], - ); + ), + ); } Future _selectDate(BuildContext context) async {