Updated keyboard behaviour in round view
This commit is contained in:
@@ -42,6 +42,8 @@ class _RoundViewState extends State<RoundView> {
|
|||||||
(index) => FocusNode(),
|
(index) => FocusNode(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
late List<GlobalKey> _textFieldKeys;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
print('=== Runde ${widget.roundNumber} geöffnet ===');
|
print('=== Runde ${widget.roundNumber} geöffnet ===');
|
||||||
@@ -62,6 +64,11 @@ class _RoundViewState extends State<RoundView> {
|
|||||||
gameSession.roundList[widget.roundNumber - 1].kamikazePlayerIndex;
|
gameSession.roundList[widget.roundNumber - 1].kamikazePlayerIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_textFieldKeys = List.generate(
|
||||||
|
widget.gameSession.players.length,
|
||||||
|
(index) => GlobalKey(),
|
||||||
|
);
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +82,6 @@ class _RoundViewState extends State<RoundView> {
|
|||||||
return CupertinoPageScaffold(
|
return CupertinoPageScaffold(
|
||||||
resizeToAvoidBottomInset: false,
|
resizeToAvoidBottomInset: false,
|
||||||
navigationBar: CupertinoNavigationBar(
|
navigationBar: CupertinoNavigationBar(
|
||||||
transitionBetweenRoutes: true,
|
|
||||||
leading: CupertinoButton(
|
leading: CupertinoButton(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
onPressed: () => {
|
onPressed: () => {
|
||||||
@@ -91,11 +97,11 @@ class _RoundViewState extends State<RoundView> {
|
|||||||
CupertinoIcons.lock,
|
CupertinoIcons.lock,
|
||||||
size: 25,
|
size: 25,
|
||||||
))),
|
))),
|
||||||
child: Stack(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Positioned.fill(
|
Expanded(
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
padding: EdgeInsets.only(bottom: 100 + bottomInset),
|
padding: EdgeInsets.only(bottom: 20 + bottomInset),
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
@@ -195,6 +201,7 @@ class _RoundViewState extends State<RoundView> {
|
|||||||
' ${AppLocalizations.of(context).points}'),
|
' ${AppLocalizations.of(context).points}'),
|
||||||
trailing: SizedBox(
|
trailing: SizedBox(
|
||||||
width: 100,
|
width: 100,
|
||||||
|
key: _textFieldKeys[originalIndex],
|
||||||
child: CupertinoTextField(
|
child: CupertinoTextField(
|
||||||
maxLength: 3,
|
maxLength: 3,
|
||||||
focusNode: _focusNodeList[originalIndex],
|
focusNode: _focusNodeList[originalIndex],
|
||||||
@@ -248,11 +255,8 @@ class _RoundViewState extends State<RoundView> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Positioned(
|
KeyboardVisibilityBuilder(
|
||||||
left: 0,
|
builder: (context, visible) {
|
||||||
right: 0,
|
|
||||||
bottom: bottomInset,
|
|
||||||
child: KeyboardVisibilityBuilder(builder: (context, visible) {
|
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 80,
|
height: 80,
|
||||||
@@ -284,8 +288,8 @@ class _RoundViewState extends State<RoundView> {
|
|||||||
} else {
|
} else {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
}),
|
},
|
||||||
)
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -371,8 +375,18 @@ class _RoundViewState extends State<RoundView> {
|
|||||||
final currentPos = originalIndices.indexOf(index);
|
final currentPos = originalIndices.indexOf(index);
|
||||||
|
|
||||||
if (currentPos < originalIndices.length - 1) {
|
if (currentPos < originalIndices.length - 1) {
|
||||||
|
final nextIndex = originalIndices[currentPos + 1];
|
||||||
FocusScope.of(context)
|
FocusScope.of(context)
|
||||||
.requestFocus(_focusNodeList[originalIndices[currentPos + 1]]);
|
.requestFocus(_focusNodeList[originalIndices[currentPos + 1]]);
|
||||||
|
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
Scrollable.ensureVisible(
|
||||||
|
_textFieldKeys[nextIndex].currentContext!,
|
||||||
|
duration: const Duration(milliseconds: 300),
|
||||||
|
curve: Curves.easeOut,
|
||||||
|
alignment: 0.55,
|
||||||
|
);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
_focusNodeList[index].unfocus();
|
_focusNodeList[index].unfocus();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user