Autoscroll when keyboard open on purchase screen

This commit is contained in:
Ivan Murashov
2018-03-26 00:33:24 +03:00
parent b6abdac78b
commit 1f5838ce16
4 changed files with 49 additions and 96 deletions

View File

@@ -45,6 +45,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
void initState() {
loading = true;
requestAsyncData(user);
buildFocusNode();
scrollController = new ScrollController();
super.initState();
}
@@ -54,12 +56,14 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
}
bool purchaseInProgress = false;
ScrollController scrollController;
Map user;
String card = '';
String loyalityType = '';
String loyalty = '';
String bonus = '';
List<Map> coupons = [];
ListView listView;
@override
Widget getScreenContent() {
@@ -119,8 +123,8 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
)
));
return new Container(child: new ListView(reverse: true,
children: <Widget>[new Column(children: widgetList)].reversed.toList()));
listView = new ListView(children: widgetList, controller: scrollController);
return listView;
}
getBonusInputField() {
@@ -130,6 +134,7 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
hintText: (app != 'crypto') ? StringsLocalization.bonusHint() : StringsLocalization.joysHint(),
hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)
),
focusNode: bonusFocusNode,
controller: bonusController,
onSubmitted: (String text) {
setState(() {
@@ -206,13 +211,13 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
hintText: getHintString(),
hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)),
controller: controller,
focusNode: sumFocusNode,
onSubmitted: (String text) {
setState(() {
controller.text = _parseSum(text);
});
},
textAlign: TextAlign.center,
autofocus: true);
textAlign: TextAlign.center);
}
requestAsyncData(Map user) async {
@@ -436,4 +441,39 @@ class PurchaseScreenState<T> extends BaseState<PurchaseScreen> {
Navigator.of(context).pop(token);
});
}
FocusNode bonusFocusNode = new FocusNode();
FocusNode sumFocusNode = new FocusNode();
// TODO: Удалить дублирующийся код.
void buildFocusNode() {
sumFocusNode.addListener(() {
setState(() {
if (sumFocusNode.hasFocus && bonusFocusNode.hasFocus) {
bonusFocusNode.unfocus();
}
if (sumFocusNode.hasFocus) {
scrollController.animateTo(100.0, duration: new Duration(seconds: 1), curve: Curves.ease);
}
});
});
bonusFocusNode.addListener(() {
setState(() {
if (bonusFocusNode.hasFocus && sumFocusNode.hasFocus) {
sumFocusNode.unfocus();
}
if (bonusFocusNode.hasFocus) {
scrollController.animateTo(120.0, duration: new Duration(seconds: 1), curve: Curves.ease);
}
});
});
}
}

View File

@@ -57,15 +57,13 @@ class RegistrationScreenState extends BaseState<RegistrationScreen> {
@override
getTextWidget() {
return new EnsureVisibleWhenFocused(
focusNode: _focusNode,
child: new TextField(
return new TextField(
focusNode: _focusNode,
keyboardType: TextInputType.number,
decoration: new InputDecoration.collapsed(
hintText: getHintString(),
hintStyle: new TextStyle(color: greyTextColor, fontSize: 16.0)),
onChanged: (text) => handleUserInput(text)));
onChanged: (text) => handleUserInput(text));
}
/// Возвращает кнопку регистрации.