Added keyboard checks
This commit is contained in:
@@ -77,7 +77,15 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return CupertinoPageScaffold(
|
return PopScope(
|
||||||
|
canPop: false,
|
||||||
|
onPopInvokedWithResult: (bool didPop, dynamic result) async {
|
||||||
|
if (!didPop) {
|
||||||
|
await _keyboardDelay();
|
||||||
|
if (context.mounted) Navigator.pop(context);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: CupertinoPageScaffold(
|
||||||
resizeToAvoidBottomInset: false,
|
resizeToAvoidBottomInset: false,
|
||||||
navigationBar: CupertinoNavigationBar(
|
navigationBar: CupertinoNavigationBar(
|
||||||
previousPageTitle: AppLocalizations.of(context).games,
|
previousPageTitle: AppLocalizations.of(context).games,
|
||||||
@@ -129,6 +137,9 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
await _keyboardDelay();
|
||||||
|
|
||||||
|
if (context.mounted) {
|
||||||
final selectedMode = await Navigator.push(
|
final selectedMode = await Navigator.push(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
@@ -142,6 +153,7 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
gameMode = selectedMode ?? gameMode;
|
gameMode = selectedMode ?? gameMode;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -197,12 +209,13 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
'${AppLocalizations.of(context).player} ${index + 1}',
|
'${AppLocalizations.of(context).player} ${index + 1}',
|
||||||
padding: const EdgeInsets.all(12),
|
padding: const EdgeInsets.all(12),
|
||||||
decoration: const BoxDecoration(),
|
decoration: const BoxDecoration(),
|
||||||
textInputAction:
|
textInputAction: index + 1 <
|
||||||
index + 1 < _playerNameTextControllers.length
|
_playerNameTextControllers.length
|
||||||
? TextInputAction.next
|
? TextInputAction.next
|
||||||
: TextInputAction.done,
|
: TextInputAction.done,
|
||||||
onSubmitted: (_) {
|
onSubmitted: (_) {
|
||||||
if (index + 1 < _playerNameFocusNodes.length) {
|
if (index + 1 <
|
||||||
|
_playerNameFocusNodes.length) {
|
||||||
_playerNameFocusNodes[index + 1]
|
_playerNameFocusNodes[index + 1]
|
||||||
.requestFocus();
|
.requestFocus();
|
||||||
} else {
|
} else {
|
||||||
@@ -268,13 +281,15 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (_playerNameTextControllers.length < maxPlayers) {
|
if (_playerNameTextControllers.length <
|
||||||
|
maxPlayers) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_playerNameTextControllers
|
_playerNameTextControllers
|
||||||
.add(TextEditingController());
|
.add(TextEditingController());
|
||||||
_playerNameFocusNodes.add(FocusNode());
|
_playerNameFocusNodes.add(FocusNode());
|
||||||
});
|
});
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance
|
||||||
|
.addPostFrameCallback((_) {
|
||||||
_playerNameFocusNodes.last.requestFocus();
|
_playerNameFocusNodes.last.requestFocus();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -296,13 +311,9 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
color: CustomTheme.primaryColor,
|
color: CustomTheme.primaryColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
FocusScope.of(context).unfocus();
|
await _keyboardDelay();
|
||||||
Future.delayed(
|
|
||||||
const Duration(
|
|
||||||
milliseconds: Constants.kKeyboardDelay), () {
|
|
||||||
_checkAllGameAttributes();
|
_checkAllGameAttributes();
|
||||||
});
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -319,7 +330,7 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
})
|
})
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)));
|
))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a widget that displays the currently selected game mode in the View.
|
/// Returns a widget that displays the currently selected game mode in the View.
|
||||||
@@ -460,8 +471,18 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _keyboardDelay() async {
|
||||||
|
if (!KeyboardVisibilityController().isVisible) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
await Future.delayed(
|
||||||
|
const Duration(milliseconds: Constants.kKeyboardDelay), () {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
Future<void> dispose() async {
|
||||||
_gameTitleTextController.dispose();
|
_gameTitleTextController.dispose();
|
||||||
for (var controller in _playerNameTextControllers) {
|
for (var controller in _playerNameTextControllers) {
|
||||||
controller.dispose();
|
controller.dispose();
|
||||||
|
|||||||
Reference in New Issue
Block a user