Skip to content

Commit 0503a27

Browse files
committed
Finished stats screen
1 parent 215a048 commit 0503a27

File tree

6 files changed

+62
-36
lines changed

6 files changed

+62
-36
lines changed

lib/screens/stats_screen.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,25 @@ import 'package:arena/views/stats_screen/goal_averages.dart';
1010
import 'package:arena/views/stats_screen/scorers.dart';
1111

1212
class StatsScreen extends StatelessWidget {
13-
Widget get _extraInfo {
13+
Widget _extraInfo(comparison) {
1414
return Container(
1515
color: Colors.white,
1616
padding: EdgeInsets.symmetric(horizontal: 32, vertical: 8),
1717
child: Column(
1818
children: [
19-
PreviousGamesView(),
19+
PreviousGamesView(
20+
homeTeamGames:
21+
comparison != null ? comparison[0]['latest_games'] : [],
22+
oppTeamGames:
23+
comparison != null ? comparison[1]['latest_games'] : [],
24+
),
2025
Divider(thickness: 2.0),
2126
GoalAverages(),
2227
Divider(thickness: 2.0),
23-
Scorers(),
28+
Scorers(
29+
homeGoalie: comparison[0]['goalie'],
30+
oppGoalie: comparison[1]['goalie'],
31+
),
2432
],
2533
),
2634
);
@@ -36,8 +44,9 @@ class StatsScreen extends StatelessWidget {
3644
child: Column(
3745
children: [
3846
InformationListView(),
39-
ComparisonView(comparison: result.data['compareTeams']),
40-
_extraInfo,
47+
if (result.data != null)
48+
ComparisonView(comparison: result.data['compareTeams']),
49+
if (result.data != null) _extraInfo(result?.data['compareTeams']),
4150
SizedBox(height: 16),
4251
],
4352
),

lib/views/stats_screen/comparison_view.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ class ComparisonView extends StatelessWidget {
1010
Container(
1111
height: 50,
1212
width: 50,
13-
child: Image.network(comparison[which]['logo']),
13+
child: comparison != null
14+
? Image.network(comparison[which]['logo'])
15+
: null,
1416
),
1517
SizedBox(height: 8),
1618
],
@@ -52,10 +54,12 @@ class ComparisonView extends StatelessWidget {
5254
width: 'Position in League'.length * 8.0,
5355
child: Row(
5456
mainAxisAlignment: MainAxisAlignment.spaceBetween,
55-
children: [
56-
Text('${comparison[0]['rank']}'),
57-
Text('${comparison[1]['rank']}')
58-
],
57+
children: comparison != null
58+
? [
59+
Text('${comparison[0]['rank']}'),
60+
Text('${comparison[1]['rank']}')
61+
]
62+
: null,
5963
),
6064
),
6165
Text(

lib/views/stats_screen/previous_games_view.dart

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ import 'package:arena/widgets/previous_game.dart';
55
class PreviousGamesView extends StatelessWidget {
66
const PreviousGamesView({
77
Key key,
8+
this.homeTeamGames,
9+
this.oppTeamGames,
810
}) : super(key: key);
911

12+
final List<dynamic> homeTeamGames;
13+
final List<dynamic> oppTeamGames;
14+
1015
@override
1116
Widget build(BuildContext context) {
1217
return Container(
@@ -21,24 +26,16 @@ class PreviousGamesView extends StatelessWidget {
2126
children: [
2227
Expanded(
2328
child: Column(
24-
children: [
25-
PreviousGame(),
26-
PreviousGame(),
27-
PreviousGame(),
28-
PreviousGame(),
29-
PreviousGame(),
30-
],
29+
children: homeTeamGames
30+
.map((game) => PreviousGame(game: game))
31+
.toList(),
3132
),
3233
),
3334
Expanded(
3435
child: Column(
35-
children: [
36-
PreviousGame(),
37-
PreviousGame(),
38-
PreviousGame(),
39-
PreviousGame(),
40-
PreviousGame(),
41-
],
36+
children: oppTeamGames
37+
.map((game) => PreviousGame(game: game))
38+
.toList(),
4239
),
4340
),
4441
],

lib/views/stats_screen/scorers.dart

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ import 'package:flutter/material.dart';
33
class Scorers extends StatelessWidget {
44
const Scorers({
55
Key key,
6+
this.homeGoalie,
7+
this.oppGoalie,
68
}) : super(key: key);
79

10+
final homeGoalie;
11+
final oppGoalie;
12+
813
@override
914
Widget build(BuildContext context) {
1015
return Container(
11-
// height: 150,
1216
child: Column(
1317
children: [
1418
Text(
@@ -18,28 +22,32 @@ class Scorers extends StatelessWidget {
1822
Row(
1923
mainAxisAlignment: MainAxisAlignment.spaceBetween,
2024
children: [
21-
_playerInfo(),
22-
_playerInfo(),
25+
_playerInfo(true),
26+
_playerInfo(false),
2327
],
2428
)
2529
],
2630
),
2731
);
2832
}
2933

30-
Widget _playerInfo() {
34+
Widget _playerInfo(bool isHomeTeam) {
3135
return Container(
3236
child: Column(
3337
mainAxisAlignment: MainAxisAlignment.spaceAround,
3438
children: [
35-
Image.asset(
36-
'assets/images/player_face.jpg',
37-
width: 50,
39+
Image.network(
40+
isHomeTeam
41+
? '${homeGoalie['urlToImage']}'
42+
: '${oppGoalie['urlToImage']}',
43+
width: 100,
3844
),
3945
SizedBox(height: 8),
40-
Text('Player Name'),
46+
Text(isHomeTeam
47+
? '${homeGoalie['player_name']}'
48+
: '${oppGoalie['player_name']}'),
4149
SizedBox(height: 8),
42-
Text('11'),
50+
// Text('11'),
4351
SizedBox(height: 16),
4452
],
4553
),

lib/widgets/previous_game.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import 'package:flutter/material.dart';
33
class PreviousGame extends StatelessWidget {
44
const PreviousGame({
55
Key key,
6+
this.game,
67
}) : super(key: key);
78

9+
final game;
10+
811
Text get _flagText {
912
return Text(
1013
'G',
@@ -30,9 +33,13 @@ class PreviousGame extends StatelessWidget {
3033
}
3134

3235
Widget get _label {
33-
return Text(
34-
'vs Team Name 0:0',
35-
style: TextStyle(color: Colors.grey),
36+
return Expanded(
37+
child: Text(
38+
game != null
39+
? 'vs ${game['homeTeam']['name']} ${game['score']}'
40+
: ' vs Team Name 0-0',
41+
style: TextStyle(color: Colors.grey),
42+
),
3643
);
3744
}
3845

server/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ const resolvers = {
117117
const parsed = await response.json();
118118

119119
// Filter to just the 2 teams requested
120+
if(parsed.api.standings == null) return null;
120121
const teamsToCompare = parsed.api.standings[0].filter((element, index, array) => {
121122
return teamNames.includes(element.teamName);
122123
});

0 commit comments

Comments
 (0)