-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
game_route.dart
133 lines (116 loc) · 4.81 KB
/
game_route.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:shots/src/components/core/buttons/button.dart';
import 'package:shots/src/components/core/buttons/close_button.dart';
import 'package:shots/src/components/game/end_alert.dart';
import 'package:shots/src/components/game/shot_card/next_card.dart';
import 'package:shots/src/components/game/shot_card/parent.dart';
import 'package:shots/src/components/game/sliding_panel/sections/options.dart';
import 'package:shots/src/components/game/sliding_panel/sections/stats.dart';
import 'package:shots/src/components/game/sliding_panel/sliding_panel.dart';
import 'package:shots/src/models/card_model.dart';
import 'package:shots/src/providers/card_provider.dart';
import 'package:shots/src/providers/game_provider.dart';
import 'package:shots/src/services/tutorial_service.dart';
import 'package:shots/src/styles/values.dart';
import 'package:shots/src/constants/strings.dart';
import 'package:sliding_up_panel/sliding_up_panel.dart';
class GameRoute extends StatelessWidget {
// controller required to programmatically open sliding panel
final PanelController _panelController = PanelController();
@override
Widget build(BuildContext context) {
// tell game provider if this is a tutorial "game" or not
final GameProvider gameProvider = Provider.of<GameProvider>(context, listen: false);
// including this here to change the background color
final CardProvider cardProvider = Provider.of<CardProvider>(context, listen: true);
// when all cards are over, this will be null
ShotCard currentCard;
// If there is no top card, this returns null
bool currentCardExists;
try {
currentCard = cardProvider.cards[cardProvider.currentCardIndex];
currentCardExists = true;
} catch (e) {
currentCard = null;
currentCardExists = false;
}
int cardsLeft = cardProvider.cards.length - cardProvider.currentCardIndex;
// if the cards left is 0 and it's a tutorial, leave!
if (gameProvider.isTutorial && cardsLeft <= 1) {
TutorialService.endTutorial(context);
}
return Scaffold(
backgroundColor: Colors.black,
// see [_slidingUpPanel] to see how the sliding up panel is coming about
body: SlidingPanel(
// if there no cards left, hide the sliding panel because all of its contents
// (options and stats) are already being shown by _endFfDeck()
showSlidingPanel: currentCardExists,
panelController: _panelController,
// actual page body
body: AnimatedContainer(
color: currentCard == null
? Colors.black
: currentCard.color.withOpacity(Values.containerOpacity),
// nice non-distracing color changing effect
duration: Duration(seconds: 6),
child: SafeArea(
child: Stack(
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
// mainAxisSize: MainAxisSize.min,
children: <Widget>[
// un comment to easily swipe cards on an emulator
// Button(text: "Next", onTap: () => cardProvider.nextCard()),
if (currentCardExists) ...[
// placeholder shot cards
ShotCardParent(
shotCard: currentCard,
nextCards: [
for (var i = cardProvider.nextCardsNo; i >= 1; i--)
_nextCard(i),
],
)
],
// show end of deck menu
if (!currentCardExists)
_endOfDeck(),
],
),
// show x button
// don't show it when the end of deck menu is showing
// because there are two buttons (End game and X) that do the
// same thing
if (currentCardExists)
Align(
alignment: Alignment.topLeft,
child: Padding(
padding: EdgeInsets.all(Values.mainPadding),
child: AppCloseButton(
overrideOnTap: () => showEndDialog(context),
),
),
)
],
),
),
),
),
);
}
Widget _nextCard(int index) => Align(
alignment: Alignment.center,
child: NextShotCard(index: index),
);
Widget _endOfDeck() => Padding(
padding: EdgeInsets.all(Values.mainPadding),
child: Column(
children: <Widget>[
OptionsSection(overrideTitle: AppStrings.endOfDeck),
StatsSection(),
],
),
);
}