cpd_David_und_Yusuf/lib/screens/settings.dart

132 lines
3.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:werwolf/screens/flippingcards.dart';
import '../models/game.dart';
import '../models/role.dart';
class GameSettings extends StatefulWidget {
final List<String> playernames;
const GameSettings({required this.playernames, super.key});
@override
State<GameSettings> createState() => _GameSettingsState();
}
class _GameSettingsState extends State<GameSettings> {
late Game game;
@override
void initState() {
game = Game(playernames: widget.playernames);
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Werwolf",
style: Theme.of(context).textTheme.titleLarge,
),
centerTitle: true,
),
body: Padding(
padding: const EdgeInsets.fromLTRB(30.0, 40.0, 30.0, 8.0),
child: Column(
children: [
Text(
"Anzahl der Spieler ${widget.playernames.length}",
style: Theme.of(context).textTheme.titleLarge,
),
const Divider(
height: 60,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"Anzahl der Werwölfe ${game.getWolves()}",
style:
Theme.of(context).textTheme.bodyLarge,
),
IconButton(
onPressed: () {
setState(() {
game.decrementWolves();
});
},
icon: const Icon(Icons.remove, color: Colors.white),
),
IconButton(
onPressed: () {
setState(() {
game.incrementWolves();
});
},
icon: const Icon(Icons.add, color: Colors.white),
),
],
),
const Divider(
height: 60,
),
Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 20),
child: Text(
"Spezielle Rollen",
style:
Theme.of(context).textTheme.titleLarge,
),
),
Expanded(
child: ListView.builder(
itemCount: Role.values.length,
itemBuilder: (context, index) {
if (Role.values[index] != Role.dorfbewohner &&
Role.values[index] != Role.werwolf) {
Role role = Role.values[index];
return ListTile(
title: Text(
role.stringValue,
style: Theme.of(context)
.textTheme
.bodyLarge,
),
trailing: Switch(
value: game.specialRoles[role],
onChanged: (bool value) {
setState(() {
game.specialRoles[role] = value;
});
},
),
);
}
return Container();
},
),
),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
FlipingCard(players: game.getAllPlayers()),
),
);
},
child: const Text(
'Spiel starten!',
),
),
const Padding(padding: EdgeInsets.all(30)),
],
),
),
);
}
}