Added keyboard checks
This commit is contained in:
@@ -77,7 +77,15 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
|
||||
@override
|
||||
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,
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
previousPageTitle: AppLocalizations.of(context).games,
|
||||
@@ -129,6 +137,9 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
],
|
||||
),
|
||||
onTap: () async {
|
||||
await _keyboardDelay();
|
||||
|
||||
if (context.mounted) {
|
||||
final selectedMode = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
@@ -142,6 +153,7 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
setState(() {
|
||||
gameMode = selectedMode ?? gameMode;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -197,12 +209,13 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
'${AppLocalizations.of(context).player} ${index + 1}',
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: const BoxDecoration(),
|
||||
textInputAction:
|
||||
index + 1 < _playerNameTextControllers.length
|
||||
textInputAction: index + 1 <
|
||||
_playerNameTextControllers.length
|
||||
? TextInputAction.next
|
||||
: TextInputAction.done,
|
||||
onSubmitted: (_) {
|
||||
if (index + 1 < _playerNameFocusNodes.length) {
|
||||
if (index + 1 <
|
||||
_playerNameFocusNodes.length) {
|
||||
_playerNameFocusNodes[index + 1]
|
||||
.requestFocus();
|
||||
} else {
|
||||
@@ -268,13 +281,15 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
if (_playerNameTextControllers.length < maxPlayers) {
|
||||
if (_playerNameTextControllers.length <
|
||||
maxPlayers) {
|
||||
setState(() {
|
||||
_playerNameTextControllers
|
||||
.add(TextEditingController());
|
||||
_playerNameFocusNodes.add(FocusNode());
|
||||
});
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
WidgetsBinding.instance
|
||||
.addPostFrameCallback((_) {
|
||||
_playerNameFocusNodes.last.requestFocus();
|
||||
});
|
||||
} else {
|
||||
@@ -296,13 +311,9 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
color: CustomTheme.primaryColor,
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
FocusScope.of(context).unfocus();
|
||||
Future.delayed(
|
||||
const Duration(
|
||||
milliseconds: Constants.kKeyboardDelay), () {
|
||||
onPressed: () async {
|
||||
await _keyboardDelay();
|
||||
_checkAllGameAttributes();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -319,7 +330,7 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
})
|
||||
],
|
||||
),
|
||||
)));
|
||||
))));
|
||||
}
|
||||
|
||||
/// 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
|
||||
void dispose() {
|
||||
Future<void> dispose() async {
|
||||
_gameTitleTextController.dispose();
|
||||
for (var controller in _playerNameTextControllers) {
|
||||
controller.dispose();
|
||||
|
||||
Reference in New Issue
Block a user