Added Keyboard type, input restriction and different action buttons
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:cabo_counter/data_classes/game_session.dart';
|
||||
import 'package:cabo_counter/utility/styles.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class RoundView extends StatefulWidget {
|
||||
final GameSession gameSession;
|
||||
@@ -16,13 +17,21 @@ class RoundView extends StatefulWidget {
|
||||
class _RoundViewState extends State<RoundView> {
|
||||
late final List<bool> _isKamikazeChecked =
|
||||
List.filled(widget.gameSession.players.length, false);
|
||||
late final List<TextEditingController> _pointControllers =
|
||||
List.filled(widget.gameSession.players.length, TextEditingController());
|
||||
late final List<bool> _hasSaidCabo =
|
||||
List.filled(widget.gameSession.players.length, false);
|
||||
late final List<TextEditingController> _pointControllers = List.generate(
|
||||
widget.gameSession.players.length,
|
||||
(index) => TextEditingController(),
|
||||
);
|
||||
int _caboPlayerIndex = 0;
|
||||
late GameSession gameSession = widget.gameSession;
|
||||
late final List<FocusNode> _focusNodes = List.generate(
|
||||
widget.gameSession.players.length,
|
||||
(index) => FocusNode(),
|
||||
); // Neue FocusNodes-Liste
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
print('Runde ${widget.roundNumber} geöffnet');
|
||||
}
|
||||
|
||||
@@ -40,20 +49,50 @@ class _RoundViewState extends State<RoundView> {
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 50, 0, 50),
|
||||
padding: const EdgeInsets.fromLTRB(0, 40, 0, 50),
|
||||
child: Text(
|
||||
'Runde ${widget.roundNumber}',
|
||||
style: Styles.roundTitle,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 0, 0, 5),
|
||||
child: CupertinoListTile(
|
||||
title: Row(
|
||||
children: [
|
||||
Text('Name'),
|
||||
],
|
||||
padding: const EdgeInsets.fromLTRB(0, 0, 0, 10),
|
||||
child: Text('Wer hat CABO gesagt?',
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: gameSession.players.length > 3 ? 5 : 20,
|
||||
vertical: 10),
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
child: CupertinoSegmentedControl<int>(
|
||||
groupValue: _caboPlayerIndex,
|
||||
children: Map<int, Widget>.fromIterable(
|
||||
widget.gameSession.players.asMap().keys,
|
||||
value: (index) => Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: gameSession.players.length > 3 ? 7 : 15,
|
||||
),
|
||||
child: Text(
|
||||
widget.gameSession.players[index],
|
||||
style: TextStyle(
|
||||
fontSize: gameSession.players.length > 3 ? 14 : 16),
|
||||
),
|
||||
),
|
||||
),
|
||||
onValueChanged: (int value) {
|
||||
setState(() {
|
||||
_caboPlayerIndex = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 0.0, horizontal: 20.0),
|
||||
child: CupertinoListTile(
|
||||
title: Text('Spieler:in'),
|
||||
trailing: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
@@ -69,7 +108,8 @@ class _RoundViewState extends State<RoundView> {
|
||||
),
|
||||
),
|
||||
),
|
||||
ListView.builder(
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: widget.gameSession.players.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
@@ -89,29 +129,37 @@ class _RoundViewState extends State<RoundView> {
|
||||
subtitle: Text(
|
||||
'${widget.gameSession.playerScores[index][widget.roundNumber - 1]} Punkte',
|
||||
),
|
||||
leading: CupertinoRadio(
|
||||
value: _hasSaidCabo[index],
|
||||
groupValue: _hasSaidCabo,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_hasSaidCabo[index] = true;
|
||||
});
|
||||
}),
|
||||
trailing: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 100,
|
||||
child: CupertinoTextField(
|
||||
keyboardType: TextInputType.number,
|
||||
controller: _pointControllers[index],
|
||||
placeholder: 'Punkte',
|
||||
textAlign: TextAlign.center,
|
||||
onChanged: (value) {
|
||||
widget.gameSession.playerScores[index]
|
||||
[widget.roundNumber - 1] =
|
||||
int.parse(value);
|
||||
},
|
||||
)),
|
||||
width: 100,
|
||||
child: CupertinoTextField(
|
||||
maxLength: 3,
|
||||
focusNode: _focusNodes[index],
|
||||
//keyboardType:
|
||||
// TextInputType.numberWithOptions(
|
||||
// signed: false, decimal: false),
|
||||
keyboardType:
|
||||
TextInputType.numberWithOptions(
|
||||
signed: true,
|
||||
decimal: false,
|
||||
),
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
],
|
||||
textInputAction: index ==
|
||||
widget.gameSession.players.length -
|
||||
1
|
||||
? TextInputAction.done
|
||||
: TextInputAction.next,
|
||||
controller: _pointControllers[index],
|
||||
placeholder: 'Punkte',
|
||||
textAlign: TextAlign.center,
|
||||
// 👇 Action-Typ explizit setzen
|
||||
|
||||
onSubmitted: (_) => _nextField(index),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 20),
|
||||
SizedBox(
|
||||
width: 50,
|
||||
@@ -132,8 +180,16 @@ class _RoundViewState extends State<RoundView> {
|
||||
],
|
||||
))));
|
||||
},
|
||||
),
|
||||
)),
|
||||
],
|
||||
)));
|
||||
}
|
||||
|
||||
void _nextField(int index) {
|
||||
if (index < widget.gameSession.players.length - 1) {
|
||||
FocusScope.of(context).requestFocus(_focusNodes[index + 1]);
|
||||
} else {
|
||||
_focusNodes[index].unfocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user