Added ReorderableListView

This commit is contained in:
2025-07-04 00:36:10 +02:00
parent 9897c74443
commit 7d497e17fe
2 changed files with 113 additions and 112 deletions

View File

@@ -6,6 +6,7 @@ import 'package:cabo_counter/utility/globals.dart';
import 'package:cabo_counter/views/active_game_view.dart'; import 'package:cabo_counter/views/active_game_view.dart';
import 'package:cabo_counter/views/mode_selection_view.dart'; import 'package:cabo_counter/views/mode_selection_view.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class CreateGameView extends StatefulWidget { class CreateGameView extends StatefulWidget {
final String? gameTitle; final String? gameTitle;
@@ -129,137 +130,137 @@ class _CreateGameViewState extends State<CreateGameView> {
), ),
), ),
Expanded( Expanded(
child: ListView.builder( child: ReorderableListView.builder(
physics: const NeverScrollableScrollPhysics(),
itemCount: _playerNameTextControllers.length + 2, itemCount: _playerNameTextControllers.length + 2,
itemBuilder: (context, index) { onReorder: (oldIndex, newIndex) {
if (index == _playerNameTextControllers.length + 1) { if (oldIndex < _playerNameTextControllers.length &&
return CupertinoButton( newIndex <= _playerNameTextControllers.length) {
padding: const EdgeInsets.fromLTRB(0, 50, 0, 0), setState(() {
child: Row( if (newIndex > oldIndex) newIndex--;
mainAxisAlignment: MainAxisAlignment.center, final item =
children: [ _playerNameTextControllers.removeAt(oldIndex);
Text( _playerNameTextControllers.insert(newIndex, item);
AppLocalizations.of(context).create_game, });
style: const TextStyle(
color: CupertinoColors.activeGreen,
),
),
],
),
onPressed: () {
_checkAllGameAttributes();
},
);
} }
if (index == _playerNameTextControllers.length) { },
return Padding( itemBuilder: (context, index) {
padding: const EdgeInsets.symmetric( // Create game button
vertical: 4.0, horizontal: 5), if (index == _playerNameTextControllers.length + 1) {
return Container(
key: const ValueKey('create_game_button'),
child: CupertinoButton( child: CupertinoButton(
padding: EdgeInsets.zero, padding: const EdgeInsets.fromLTRB(0, 50, 0, 0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Align( Container(
alignment: Alignment.centerLeft, decoration: BoxDecoration(
child: CupertinoButton( borderRadius: BorderRadius.circular(20),
padding: EdgeInsets.zero, color: CustomTheme.primaryColor,
onPressed: null,
child: Icon(
CupertinoIcons.add_circled_solid,
color: CustomTheme.primaryColor,
size: 25,
),
), ),
), padding: const EdgeInsets.symmetric(
Expanded( horizontal: 15, vertical: 8),
child: Align( child: Text(
alignment: Alignment.center, AppLocalizations.of(context).create_game,
child: Text( style: TextStyle(
AppLocalizations.of(context).add_player, color: CustomTheme.backgroundColor,
textAlign: TextAlign.center,
style: const TextStyle(
color: CupertinoColors.activeGreen,
),
),
),
),
const Align(
alignment: Alignment.centerLeft,
child: CupertinoButton(
padding: EdgeInsets.zero,
onPressed: null,
child: Icon(
CupertinoIcons.add_circled_solid,
color: CupertinoColors.transparent,
size: 25,
), ),
), ),
), ),
], ],
), ),
onPressed: () { onPressed: () {
if (_playerNameTextControllers.length < maxPlayers) { _checkAllGameAttributes();
setState(() {
_playerNameTextControllers
.add(TextEditingController());
});
} else {
showCupertinoDialog(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text(AppLocalizations.of(context)
.max_players_title),
content: Text(AppLocalizations.of(context)
.max_players_message),
actions: [
CupertinoDialogAction(
child:
Text(AppLocalizations.of(context).ok),
onPressed: () => Navigator.pop(context),
),
],
),
);
}
}, },
), ),
); );
} else { }
// Spieler-Einträge // Add player button
return Padding( if (index == _playerNameTextControllers.length) {
padding: const EdgeInsets.symmetric( return Container(
vertical: 4.0, horizontal: 5), key: const ValueKey('add_player_button'),
child: Row( child: Padding(
children: [ padding: const EdgeInsets.symmetric(
CupertinoButton( vertical: 4.0, horizontal: 10),
padding: EdgeInsets.zero, child: CupertinoButton(
child: const Icon( padding: EdgeInsets.zero,
CupertinoIcons.minus_circle_fill, child: Row(
color: CupertinoColors.destructiveRed, mainAxisAlignment: MainAxisAlignment.center,
size: 25, children: [
), Icon(
onPressed: () { CupertinoIcons.add_circled_solid,
color: CustomTheme.primaryColor,
),
const SizedBox(width: 6),
Text(
AppLocalizations.of(context).add_player,
style:
TextStyle(color: CustomTheme.primaryColor),
),
],
),
onPressed: () {
if (_playerNameTextControllers.length <
maxPlayers) {
setState(() { setState(() {
_playerNameTextControllers[index].dispose(); _playerNameTextControllers
_playerNameTextControllers.removeAt(index); .add(TextEditingController());
}); });
}, } else {
), _showDialog((
Expanded( AppLocalizations.of(context).max_players_title,
child: CupertinoTextField( AppLocalizations.of(context).max_players_message
controller: _playerNameTextControllers[index], ));
maxLength: 12, }
placeholder: },
'${AppLocalizations.of(context).player} ${index + 1}', ),
padding: const EdgeInsets.all(12),
decoration: const BoxDecoration(),
),
),
],
), ),
); );
} }
// Player name input field
return Padding(
key: ValueKey('player_${index + 1}'),
padding: const EdgeInsets.symmetric(
vertical: 4.0, horizontal: 5),
child: Row(
children: [
CupertinoButton(
padding: EdgeInsets.zero,
child: const Icon(
CupertinoIcons.minus_circle_fill,
color: CupertinoColors.destructiveRed,
size: 25,
),
onPressed: () {
setState(() {
_playerNameTextControllers[index].dispose();
_playerNameTextControllers.removeAt(index);
});
},
),
Expanded(
child: CupertinoTextField(
controller: _playerNameTextControllers[index],
maxLength: 12,
placeholder:
'${AppLocalizations.of(context).player} ${index + 1}',
padding: const EdgeInsets.all(12),
decoration: const BoxDecoration(),
),
),
const SizedBox(width: 8),
ReorderableDragStartListener(
index: index,
child: const Icon(
CupertinoIcons.line_horizontal_3,
size: 20,
color: CupertinoColors.systemGrey,
),
),
],
),
);
}, },
), ),
), ),

View File

@@ -2,7 +2,7 @@ name: cabo_counter
description: "Mobile app for the card game Cabo" description: "Mobile app for the card game Cabo"
publish_to: 'none' publish_to: 'none'
version: 0.3.6+321 version: 0.3.6+323
environment: environment:
sdk: ^3.5.4 sdk: ^3.5.4