96 lines
3.0 KiB
Dart
96 lines
3.0 KiB
Dart
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,
|
|
),
|
|
body: Column(
|
|
children: [
|
|
TextField(
|
|
key: _formKey,
|
|
controller: _playerController,
|
|
decoration: InputDecoration(
|
|
errorText: _errorMessage == "" ? null : _errorMessage,
|
|
labelText: 'Spielername',
|
|
labelStyle: const TextStyle(
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
style: const TextStyle(color: Colors.white),
|
|
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);
|
|
}
|
|
});
|
|
},
|
|
),
|
|
Expanded(
|
|
child: ListView.builder(
|
|
itemCount: playernames.length,
|
|
itemBuilder: (context, index) {
|
|
return ListTile(
|
|
title: Text(
|
|
playernames[index],
|
|
style: const TextStyle(color: Colors.white),
|
|
),
|
|
tileColor: Colors.grey,
|
|
trailing: IconButton(
|
|
onPressed: () {
|
|
setState(() {
|
|
playernames.remove(playernames[index]);
|
|
});
|
|
},
|
|
icon: const Icon(Icons.remove, color: Colors.white)),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () {
|
|
if (playernames.length >= 6) {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => GameSettings(
|
|
playernames: playernames,
|
|
),
|
|
));
|
|
} else {
|
|
setState(() {
|
|
_errorMessage = "Es müssen mindestens 6 Spieler sein!";
|
|
});
|
|
}
|
|
},
|
|
child: const Text('Spiel einstellen'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|