Fixed keyboard behaviour

This commit is contained in:
2025-07-20 19:28:38 +02:00
parent 68a1a5052e
commit 59ff4df83c
2 changed files with 90 additions and 73 deletions

View File

@@ -8,6 +8,7 @@ import 'package:cabo_counter/presentation/widgets/custom_button.dart';
import 'package:cabo_counter/services/config_service.dart'; import 'package:cabo_counter/services/config_service.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
enum CreateStatus { enum CreateStatus {
noGameTitle, noGameTitle,
@@ -66,12 +67,13 @@ class _CreateGameViewState extends State<CreateGameView> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoPageScaffold( return CupertinoPageScaffold(
resizeToAvoidBottomInset: false,
navigationBar: CupertinoNavigationBar( navigationBar: CupertinoNavigationBar(
previousPageTitle: AppLocalizations.of(context).overview, previousPageTitle: AppLocalizations.of(context).overview,
middle: Text(AppLocalizations.of(context).new_game), middle: Text(AppLocalizations.of(context).new_game),
), ),
child: SafeArea( child: SafeArea(
child: Center( child: SingleChildScrollView(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@@ -102,13 +104,7 @@ class _CreateGameViewState extends State<CreateGameView> {
prefix: Text(AppLocalizations.of(context).mode), prefix: Text(AppLocalizations.of(context).mode),
suffix: Row( suffix: Row(
children: [ children: [
Text( _getDisplayedGameMode(),
gameMode == GameMode.none
? AppLocalizations.of(context).no_mode_selected
: (gameMode == GameMode.pointLimit
? '${ConfigService.getPointLimit()} ${AppLocalizations.of(context).points}'
: AppLocalizations.of(context).unlimited),
),
const SizedBox(width: 3), const SizedBox(width: 3),
const CupertinoListTileChevron(), const CupertinoListTileChevron(),
], ],
@@ -137,75 +133,73 @@ class _CreateGameViewState extends State<CreateGameView> {
style: CustomTheme.rowTitle, style: CustomTheme.rowTitle,
), ),
), ),
Flexible( ReorderableListView.builder(
child: ReorderableListView.builder( shrinkWrap: true,
shrinkWrap: true, physics: const BouncingScrollPhysics(),
physics: const NeverScrollableScrollPhysics(), padding: const EdgeInsets.all(8),
padding: const EdgeInsets.all(8), itemCount: _playerNameTextControllers.length,
itemCount: _playerNameTextControllers.length, onReorder: (oldIndex, newIndex) {
onReorder: (oldIndex, newIndex) { setState(() {
setState(() { if (oldIndex < _playerNameTextControllers.length &&
if (oldIndex < _playerNameTextControllers.length && newIndex <= _playerNameTextControllers.length) {
newIndex <= _playerNameTextControllers.length) { if (newIndex > oldIndex) newIndex--;
if (newIndex > oldIndex) newIndex--; final item =
final item = _playerNameTextControllers.removeAt(oldIndex);
_playerNameTextControllers.removeAt(oldIndex); _playerNameTextControllers.insert(newIndex, item);
_playerNameTextControllers.insert(newIndex, item); }
} });
}); },
}, itemBuilder: (context, index) {
itemBuilder: (context, index) { return Padding(
return Padding( key: ValueKey(
key: ValueKey( 'player_${_playerNameTextControllers[index].hashCode}'),
'player_${_playerNameTextControllers[index].hashCode}'), padding: const EdgeInsets.symmetric(vertical: 8.0),
padding: const EdgeInsets.symmetric(vertical: 8.0), child: Row(
child: Row( children: [
children: [ CupertinoButton(
CupertinoButton( padding: EdgeInsets.zero,
padding: EdgeInsets.zero, child: const Icon(
child: const Icon( CupertinoIcons.minus_circle_fill,
CupertinoIcons.minus_circle_fill, color: CupertinoColors.destructiveRed,
color: CupertinoColors.destructiveRed, size: 25,
size: 25,
),
onPressed: () {
setState(() {
_playerNameTextControllers[index].dispose();
_playerNameTextControllers.removeAt(index);
});
},
), ),
Expanded( onPressed: () {
child: CupertinoTextField( setState(() {
controller: _playerNameTextControllers[index], _playerNameTextControllers[index].dispose();
maxLength: 12, _playerNameTextControllers.removeAt(index);
placeholder: });
'${AppLocalizations.of(context).player} ${index + 1}', },
padding: const EdgeInsets.all(12), ),
decoration: const BoxDecoration(), Expanded(
), child: CupertinoTextField(
controller: _playerNameTextControllers[index],
maxLength: 12,
placeholder:
'${AppLocalizations.of(context).player} ${index + 1}',
padding: const EdgeInsets.all(12),
decoration: const BoxDecoration(),
), ),
AnimatedOpacity( ),
opacity: _playerNameTextControllers.length > 1 AnimatedOpacity(
? 1.0 opacity: _playerNameTextControllers.length > 1
: 0.0, ? 1.0
duration: const Duration(milliseconds: 300), : 0.0,
child: Padding( duration: const Duration(milliseconds: 300),
padding: const EdgeInsets.only(right: 8.0), child: Padding(
child: ReorderableDragStartListener( padding: const EdgeInsets.only(right: 8.0),
index: index, child: ReorderableDragStartListener(
child: const Icon( index: index,
CupertinoIcons.line_horizontal_3, child: const Icon(
color: CupertinoColors.systemGrey, CupertinoIcons.line_horizontal_3,
), color: CupertinoColors.systemGrey,
), ),
), ),
) ),
], )
), ],
); ),
}), );
), }),
Padding( Padding(
padding: const EdgeInsets.fromLTRB(8, 0, 8, 50), padding: const EdgeInsets.fromLTRB(8, 0, 8, 50),
child: Center( child: Center(
@@ -259,6 +253,15 @@ class _CreateGameViewState extends State<CreateGameView> {
), ),
), ),
), ),
KeyboardVisibilityBuilder(builder: (context, visible) {
if (visible) {
return const SizedBox(
height: 250,
);
} else {
return const SizedBox.shrink();
}
})
], ],
), ),
))); )));
@@ -412,6 +415,19 @@ class _CreateGameViewState extends State<CreateGameView> {
return true; return true;
} }
Text _getDisplayedGameMode() {
if (gameMode == GameMode.none) {
return Text(AppLocalizations.of(context).no_mode_selected);
} else if (gameMode == GameMode.pointLimit) {
return Text(
'${ConfigService.getPointLimit()} ${AppLocalizations.of(context).points}',
style: TextStyle(color: CustomTheme.primaryColor));
} else {
return Text(AppLocalizations.of(context).unlimited,
style: TextStyle(color: CustomTheme.primaryColor));
}
}
@override @override
void dispose() { void dispose() {
_gameTitleTextController.dispose(); _gameTitleTextController.dispose();

View File

@@ -16,6 +16,7 @@ class _TabViewState extends State<TabView> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CupertinoTabScaffold( return CupertinoTabScaffold(
resizeToAvoidBottomInset: false,
tabBar: CupertinoTabBar( tabBar: CupertinoTabBar(
backgroundColor: CustomTheme.mainElementBackgroundColor, backgroundColor: CustomTheme.mainElementBackgroundColor,
iconSize: 27, iconSize: 27,