Add done button to iOS keyboard

This commit is contained in:
Godwin Asuquo 2022-10-19 11:07:04 +03:00
parent da6fd9a9ff
commit 60a06577bc
2 changed files with 147 additions and 102 deletions

View file

@ -1,10 +1,11 @@
import 'package:cake_wallet/core/execution_state.dart'; 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/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/src/widgets/standard_checkbox.dart';
import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:keyboard_actions/keyboard_actions.dart';
import 'package:mobx/mobx.dart'; import 'package:mobx/mobx.dart';
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/core/node_address_validator.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; String get title => S.current.node_new;
final NodeCreateOrEditViewModel nodeCreateOrEditViewModel; 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 @override
Widget body(BuildContext context) { Widget body(BuildContext context) {
@ -104,7 +120,10 @@ class NodeCreateOrEditPage extends BasePage {
} }
}); });
return Container( return KeyboardActions(
autoScroll: false,
config: _buildConfig(context),
child: Container(
padding: EdgeInsets.only(left: 24, right: 24), padding: EdgeInsets.only(left: 24, right: 24),
child: ScrollableWithBottomSection( child: ScrollableWithBottomSection(
contentPadding: EdgeInsets.only(bottom: 24.0), contentPadding: EdgeInsets.only(bottom: 24.0),
@ -130,6 +149,7 @@ class NodeCreateOrEditPage extends BasePage {
child: BaseTextFormField( child: BaseTextFormField(
controller: _portController, controller: _portController,
hintText: S.of(context).node_port, hintText: S.of(context).node_port,
focusNode: _nodePortFocusNode,
keyboardType: TextInputType.numberWithOptions( keyboardType: TextInputType.numberWithOptions(
signed: false, decimal: false), signed: false, decimal: false),
validator: NodePortValidator(), validator: NodePortValidator(),
@ -222,6 +242,7 @@ class NodeCreateOrEditPage extends BasePage {
)), )),
], ],
)), )),
)); )),
);
} }
} }

View file

@ -1,9 +1,11 @@
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
import 'package:cake_wallet/utils/date_picker.dart'; import 'package:cake_wallet/utils/date_picker.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/monero/monero.dart'; import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
import 'package:keyboard_actions/keyboard_actions.dart';
class BlockchainHeightWidget extends StatefulWidget { class BlockchainHeightWidget extends StatefulWidget {
BlockchainHeightWidget({ BlockchainHeightWidget({
@ -29,7 +31,22 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
int get height => _height; int get height => _height;
int _height = 0; 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 @override
void initState() { void initState() {
restoreHeightController.addListener(() { restoreHeightController.addListener(() {
@ -55,7 +72,11 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column(
return KeyboardActions(
autoScroll: false,
config: _buildConfig(context),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Row( Row(
@ -64,12 +85,14 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
child: Container( child: Container(
padding: EdgeInsets.only(top: 20.0, bottom: 10.0), padding: EdgeInsets.only(top: 20.0, bottom: 10.0),
child: BaseTextFormField( child: BaseTextFormField(
focusNode: widget.focusNode, focusNode: _restoreFocusNode,
controller: restoreHeightController, controller: restoreHeightController,
keyboardType: TextInputType.numberWithOptions( keyboardType: TextInputType.numberWithOptions(
signed: false, decimal: false), signed: false, decimal: false),
hintText: S.of(context).widgets_restore_from_blockheight, hintText: S.of(context).widgets_restore_from_blockheight,
))) ),
),
)
], ],
), ),
if (widget.hasDatePicker) ...[ if (widget.hasDatePicker) ...[
@ -112,6 +135,7 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
) )
] ]
], ],
),
); );
} }