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,19 +130,42 @@ class _CreateGameViewState extends State<CreateGameView> {
), ),
), ),
Expanded( Expanded(
child: ListView.builder( child: ReorderableListView.builder(
physics: const NeverScrollableScrollPhysics(),
itemCount: _playerNameTextControllers.length + 2, itemCount: _playerNameTextControllers.length + 2,
onReorder: (oldIndex, newIndex) {
if (oldIndex < _playerNameTextControllers.length &&
newIndex <= _playerNameTextControllers.length) {
setState(() {
if (newIndex > oldIndex) newIndex--;
final item =
_playerNameTextControllers.removeAt(oldIndex);
_playerNameTextControllers.insert(newIndex, item);
});
}
},
itemBuilder: (context, index) { itemBuilder: (context, index) {
// Create game button
if (index == _playerNameTextControllers.length + 1) { if (index == _playerNameTextControllers.length + 1) {
return CupertinoButton( return Container(
key: const ValueKey('create_game_button'),
child: CupertinoButton(
padding: const EdgeInsets.fromLTRB(0, 50, 0, 0), padding: const EdgeInsets.fromLTRB(0, 50, 0, 0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Text( Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: CustomTheme.primaryColor,
),
padding: const EdgeInsets.symmetric(
horizontal: 15, vertical: 8),
child: Text(
AppLocalizations.of(context).create_game, AppLocalizations.of(context).create_game,
style: const TextStyle( style: TextStyle(
color: CupertinoColors.activeGreen, color: CustomTheme.backgroundColor,
),
), ),
), ),
], ],
@@ -149,85 +173,54 @@ class _CreateGameViewState extends State<CreateGameView> {
onPressed: () { onPressed: () {
_checkAllGameAttributes(); _checkAllGameAttributes();
}, },
),
); );
} }
// Add player button
if (index == _playerNameTextControllers.length) { if (index == _playerNameTextControllers.length) {
return Padding( return Container(
key: const ValueKey('add_player_button'),
child: Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: 4.0, horizontal: 5), vertical: 4.0, horizontal: 10),
child: CupertinoButton( child: CupertinoButton(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Align( Icon(
alignment: Alignment.centerLeft,
child: CupertinoButton(
padding: EdgeInsets.zero,
onPressed: null,
child: Icon(
CupertinoIcons.add_circled_solid, CupertinoIcons.add_circled_solid,
color: CustomTheme.primaryColor, color: CustomTheme.primaryColor,
size: 25,
), ),
), const SizedBox(width: 6),
), Text(
Expanded(
child: Align(
alignment: Alignment.center,
child: Text(
AppLocalizations.of(context).add_player, AppLocalizations.of(context).add_player,
textAlign: TextAlign.center, style:
style: const TextStyle( TextStyle(color: CustomTheme.primaryColor),
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) { if (_playerNameTextControllers.length <
maxPlayers) {
setState(() { setState(() {
_playerNameTextControllers _playerNameTextControllers
.add(TextEditingController()); .add(TextEditingController());
}); });
} else { } else {
showCupertinoDialog( _showDialog((
context: context, AppLocalizations.of(context).max_players_title,
builder: (context) => CupertinoAlertDialog( AppLocalizations.of(context).max_players_message
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 // Player name input field
return Padding( return Padding(
key: ValueKey('player_${index + 1}'),
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: 4.0, horizontal: 5), vertical: 4.0, horizontal: 5),
child: Row( child: Row(
@@ -256,10 +249,18 @@ class _CreateGameViewState extends State<CreateGameView> {
decoration: const BoxDecoration(), 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