2024-05-10 22:00:14 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:werwolf/screens/settings.dart';
|
|
|
|
|
|
|
|
class PlayerRegistry extends StatefulWidget {
|
|
|
|
const PlayerRegistry({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
_PlayerRegistryState createState() => _PlayerRegistryState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PlayerRegistryState extends State<PlayerRegistry> {
|
|
|
|
final TextEditingController _playerController = TextEditingController();
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
String _errorMessage = "";
|
|
|
|
List<String> playernames = [];
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: const Text("Werwolf"),
|
|
|
|
centerTitle: true,
|
|
|
|
),
|
2024-06-07 20:02:06 +02:00
|
|
|
body: Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(15),
|
|
|
|
child: TextField(
|
|
|
|
key: _formKey,
|
|
|
|
controller: _playerController,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
errorText: _errorMessage == "" ? null : _errorMessage,
|
|
|
|
labelText: 'Spielername',
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(
|
|
|
|
color: Theme.of(context).colorScheme.primary),
|
|
|
|
),
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(
|
|
|
|
color: Theme.of(context).colorScheme.primary),
|
|
|
|
),
|
|
|
|
errorBorder: OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(
|
|
|
|
color: Theme.of(context).colorScheme.secondary),
|
|
|
|
),
|
|
|
|
focusedErrorBorder: OutlineInputBorder(
|
|
|
|
borderSide: BorderSide(
|
|
|
|
color: Theme.of(context).colorScheme.secondary),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onSubmitted: (value) {
|
|
|
|
setState(() {
|
|
|
|
if (_playerController.text.isEmpty) {
|
|
|
|
_errorMessage = "Spielername ist leer!";
|
|
|
|
} else if (playernames.contains(value)) {
|
|
|
|
_errorMessage = "Dieser Spieler existiert bereits";
|
|
|
|
_playerController.clear();
|
|
|
|
} else {
|
|
|
|
_errorMessage = "";
|
|
|
|
_playerController.clear();
|
|
|
|
playernames.add(value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2024-05-10 22:00:14 +02:00
|
|
|
),
|
|
|
|
),
|
2024-06-07 20:02:06 +02:00
|
|
|
Expanded(
|
|
|
|
child: ListView.builder(
|
|
|
|
itemCount: playernames.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return ListTile(
|
|
|
|
title: Text(
|
|
|
|
playernames[index],
|
|
|
|
),
|
|
|
|
trailing: IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
setState(() {
|
|
|
|
playernames.remove(playernames[index]);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.remove)),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ElevatedButton(
|
|
|
|
onPressed: () {
|
|
|
|
if (playernames.length >= 6) {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => GameSettings(
|
|
|
|
playernames: playernames,
|
|
|
|
),
|
|
|
|
));
|
2024-05-10 22:00:14 +02:00
|
|
|
} else {
|
2024-06-07 20:02:06 +02:00
|
|
|
setState(() {
|
|
|
|
_errorMessage = "Es müssen mindestens 6 Spieler sein!";
|
|
|
|
});
|
2024-05-10 22:00:14 +02:00
|
|
|
}
|
|
|
|
},
|
2024-06-07 20:02:06 +02:00
|
|
|
child: const Text('Spiel einstellen'),
|
2024-05-10 22:00:14 +02:00
|
|
|
),
|
2024-06-07 20:02:06 +02:00
|
|
|
Padding(padding: EdgeInsets.all(30))
|
|
|
|
],
|
|
|
|
),
|
2024-05-10 22:00:14 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|