Autoscroll when keyboard open on purchase screen
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user