2024-05-10 23:20:18 +02:00
|
|
|
import 'package:flip_card/flip_card_controller.dart';
|
2024-05-10 22:00:14 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flip_card/flip_card.dart';
|
2024-06-07 20:02:06 +02:00
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
|
|
import 'package:werwolf/screens/gameboard.dart';
|
2024-05-10 22:00:14 +02:00
|
|
|
|
|
|
|
import '../models/player.dart';
|
|
|
|
import '../models/role.dart';
|
|
|
|
|
|
|
|
class FlipingCard extends StatefulWidget {
|
|
|
|
final List<Player> players;
|
|
|
|
const FlipingCard({required this.players, super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<FlipingCard> createState() => _FlipingCardState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _FlipingCardState extends State<FlipingCard> {
|
2024-06-18 02:15:30 +02:00
|
|
|
int index = 0;
|
2024-05-10 22:00:14 +02:00
|
|
|
|
2024-06-18 02:15:30 +02:00
|
|
|
late FlipCardController _controller;
|
2024-05-10 23:20:18 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2024-06-18 02:15:30 +02:00
|
|
|
_controller = FlipCardController();
|
2024-05-10 22:00:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_renderContent(context) {
|
|
|
|
return Card(
|
|
|
|
elevation: 0.0,
|
|
|
|
margin: const EdgeInsets.only(
|
|
|
|
left: 15.0, right: 15.0, top: 10.0, bottom: 10.0),
|
|
|
|
color: const Color(0x00000000),
|
|
|
|
child: FlipCard(
|
2024-05-10 23:20:18 +02:00
|
|
|
controller: _controller,
|
2024-05-10 22:00:14 +02:00
|
|
|
direction: FlipDirection.HORIZONTAL,
|
|
|
|
side: CardSide.FRONT,
|
2024-05-10 23:20:18 +02:00
|
|
|
speed: 300,
|
2024-05-10 22:00:14 +02:00
|
|
|
onFlipDone: (status) {},
|
|
|
|
front: Container(
|
2024-06-07 20:02:06 +02:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
2024-06-07 20:08:07 +02:00
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8.0)),
|
2024-05-10 22:00:14 +02:00
|
|
|
),
|
|
|
|
child: Column(
|
2024-06-07 20:02:06 +02:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
2024-05-10 22:00:14 +02:00
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
padding: const EdgeInsets.all(10),
|
|
|
|
child: Text(
|
|
|
|
widget.players[index].name,
|
2024-06-07 20:02:06 +02:00
|
|
|
style: Theme.of(context).textTheme.headlineMedium,
|
2024-05-10 22:00:14 +02:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
),
|
2024-06-07 20:08:07 +02:00
|
|
|
const Text(
|
2024-06-18 02:15:30 +02:00
|
|
|
'Klick um deine Rolle zu sehen!',
|
2024-06-07 20:02:06 +02:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
2024-05-10 22:00:14 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
back: Container(
|
2024-05-10 23:20:18 +02:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: widget.players[index].role != Role.werwolf
|
|
|
|
? const Color(0xFF006666)
|
2024-06-07 20:02:06 +02:00
|
|
|
: const Color.fromARGB(255, 100, 21, 15),
|
2024-05-10 23:20:18 +02:00
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8.0)),
|
2024-05-10 22:00:14 +02:00
|
|
|
),
|
|
|
|
child: Column(
|
2024-06-07 20:02:06 +02:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
2024-05-10 22:00:14 +02:00
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
padding: const EdgeInsets.all(10),
|
|
|
|
child: Text(
|
2024-05-10 23:20:18 +02:00
|
|
|
widget.players[index].role.stringValue,
|
2024-06-07 20:02:06 +02:00
|
|
|
style: Theme.of(context).textTheme.headlineMedium,
|
2024-05-10 22:00:14 +02:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: const Text("Werwolf"),
|
|
|
|
centerTitle: true,
|
2024-06-07 20:02:06 +02:00
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(FontAwesomeIcons.xmark),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.popUntil(context, ModalRoute.withName('/'));
|
|
|
|
},
|
|
|
|
),
|
2024-05-10 22:00:14 +02:00
|
|
|
),
|
|
|
|
body: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(child: _renderContent(context)),
|
2024-06-11 12:25:39 +02:00
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.all(15.0),
|
|
|
|
child: Divider(
|
|
|
|
height: 1,
|
|
|
|
color: Colors.grey,
|
|
|
|
),
|
2024-06-07 20:26:41 +02:00
|
|
|
),
|
2024-05-10 22:00:14 +02:00
|
|
|
Container(
|
2024-06-07 20:26:41 +02:00
|
|
|
padding: const EdgeInsets.only(top: 10, bottom: 60),
|
2024-05-10 22:00:14 +02:00
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
2024-06-07 20:49:32 +02:00
|
|
|
Flexible(
|
|
|
|
child: OutlinedButton(
|
|
|
|
onPressed: () {
|
|
|
|
setState(() {
|
|
|
|
if (index > 0 && index <= widget.players.length) {
|
2024-06-18 02:15:30 +02:00
|
|
|
index--;
|
2024-06-07 20:49:32 +02:00
|
|
|
if (!_controller.state!.isFront) {
|
|
|
|
_controller.toggleCardWithoutAnimation();
|
|
|
|
}
|
2024-05-10 23:20:18 +02:00
|
|
|
}
|
2024-06-07 20:49:32 +02:00
|
|
|
});
|
|
|
|
},
|
2024-06-18 02:15:30 +02:00
|
|
|
child: const Text("Zurück"),
|
2024-06-07 20:49:32 +02:00
|
|
|
),
|
2024-05-10 22:00:14 +02:00
|
|
|
),
|
2024-06-07 20:49:32 +02:00
|
|
|
Flexible(
|
|
|
|
child: ElevatedButton(
|
|
|
|
onPressed: () {
|
|
|
|
setState(() {
|
|
|
|
if (index >= 0 && index < widget.players.length - 1) {
|
2024-06-18 02:15:30 +02:00
|
|
|
index++;
|
2024-06-07 20:49:32 +02:00
|
|
|
if (!_controller.state!.isFront) {
|
|
|
|
_controller.toggleCardWithoutAnimation();
|
|
|
|
}
|
|
|
|
} else if (index == widget.players.length - 1) {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) =>
|
|
|
|
PlayerGridView(players: widget.players),
|
|
|
|
),
|
|
|
|
);
|
2024-05-10 23:20:18 +02:00
|
|
|
}
|
2024-06-07 20:49:32 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Text(index != widget.players.length - 1
|
2024-06-18 02:15:30 +02:00
|
|
|
? "Nächster Spieler"
|
|
|
|
: "Spiel anfangen!"),
|
2024-06-07 20:49:32 +02:00
|
|
|
),
|
2024-05-10 22:00:14 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|