logic for game card
This commit is contained in:
181
lib/models/game_cards.dart
Normal file
181
lib/models/game_cards.dart
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import '../screens/sport_schedule.dart';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
class GameCard extends StatefulWidget {
|
||||||
|
final int sportID;
|
||||||
|
|
||||||
|
GameCard(this.sportID);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_SportsCard createState() => _SportsCard(sportID);
|
||||||
|
}
|
||||||
|
|
||||||
|
//List<sport_schedule> _selectedEvents; //original that makes events work
|
||||||
|
List
|
||||||
|
_selectedEvents; //Removing the <sport_schedule> allows it to still work. Proceed with caution
|
||||||
|
DateTime selectedDay;
|
||||||
|
Map<DateTime, List<sport_schedule>> _events;
|
||||||
|
|
||||||
|
class _SportsCard extends State<GameCard> with TickerProviderStateMixin {
|
||||||
|
int sportID;
|
||||||
|
|
||||||
|
_SportsCard(this.sportID);
|
||||||
|
|
||||||
|
AnimationController _animationController;
|
||||||
|
|
||||||
|
static final sportUrl =
|
||||||
|
'https://charlotte49ers.com/services/adaptive_components.ashx?type=scoreboard&start=0&count=80';
|
||||||
|
|
||||||
|
Future<List<sport_schedule>> getEvents() async {
|
||||||
|
var url = '$sportUrl&sport_id=$sportID&name=&extra=%7B%7D';
|
||||||
|
|
||||||
|
http.Response response = await http.get(url);
|
||||||
|
Iterable games = json.decode(response.body);
|
||||||
|
|
||||||
|
return games
|
||||||
|
.map<sport_schedule>((json) => sport_schedule.fromJson(json))
|
||||||
|
.toList();
|
||||||
|
//return games.map((e) => sport_schedule.fromJson(e)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Map<DateTime, List<sport_schedule>>> getGames() async {
|
||||||
|
Map<DateTime, List<sport_schedule>> mapGrab = {};
|
||||||
|
|
||||||
|
List<sport_schedule> eventInfo = await getEvents();
|
||||||
|
|
||||||
|
for (int i = 0; i < eventInfo.length; i++) {
|
||||||
|
var sportEvent = DateTime(eventInfo[i].date.year, eventInfo[i].date.month,
|
||||||
|
eventInfo[i].date.day);
|
||||||
|
var original = mapGrab[sportEvent];
|
||||||
|
|
||||||
|
if (original == null) {
|
||||||
|
//print("null");
|
||||||
|
mapGrab[sportEvent] = [eventInfo[i]];
|
||||||
|
} else {
|
||||||
|
//print(eventInfo[i].date);
|
||||||
|
mapGrab[sportEvent] = List.from(original)..addAll([eventInfo[i]]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mapGrab;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
//final _selectedDay = DateTime.now();
|
||||||
|
|
||||||
|
//_selectedEvents = _events[_selectedDay] ?? [];
|
||||||
|
_selectedEvents = [];
|
||||||
|
_animationController = AnimationController(
|
||||||
|
vsync: this,
|
||||||
|
duration: const Duration(milliseconds: 400),
|
||||||
|
);
|
||||||
|
|
||||||
|
_animationController.forward();
|
||||||
|
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
getGames().then((val) => setState(() {
|
||||||
|
_events = val;
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_animationController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
//----- Builds event Lister -----
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Center(
|
||||||
|
child: Container(
|
||||||
|
child: Expanded(child: _eventLister()),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----- Creates event display -----
|
||||||
|
|
||||||
|
Text _pastGameScore(
|
||||||
|
String homeAway, String winLoss, String uncc, String opponent) {
|
||||||
|
if (homeAway == "H" || homeAway == "T") {
|
||||||
|
return (Text('$uncc - $opponent'));
|
||||||
|
} else {
|
||||||
|
return (Text('$opponent - $uncc'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Image _homeAwayImageOrder(String h, String opposingTeam, bool l) {
|
||||||
|
if ((h == "H") == l) {
|
||||||
|
return (Image(
|
||||||
|
image: AssetImage('assets/school_logos/uncc.png'),
|
||||||
|
width: 50,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
return (Image.network(
|
||||||
|
'https://charlotte49ers.com' + opposingTeam,
|
||||||
|
width: 50.0,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _eventLister() {
|
||||||
|
var _months = {1:'JAN', 2:'FEB', 3:'MAR', 4:'APR', 5:'MAY', 6:'JUN',
|
||||||
|
7:'JUL', 8:'AUG', 9:'SEP', 10:'OCT', 11:'NOV', 12:'DEC'};
|
||||||
|
return SizedBox(
|
||||||
|
height: 62,
|
||||||
|
child: Column(
|
||||||
|
children: _selectedEvents
|
||||||
|
.map((event) => Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(
|
||||||
|
color: Color.fromRGBO(0, 112, 60, 1), //UNCC Green
|
||||||
|
width: 0.8,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(12.0),
|
||||||
|
),
|
||||||
|
height: 70.0,
|
||||||
|
margin:
|
||||||
|
const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
|
||||||
|
child: ListTile(
|
||||||
|
leading: _homeAwayImageOrder(
|
||||||
|
event.location_indicator.toString(),
|
||||||
|
event.image.toString(), true),
|
||||||
|
title: Wrap(
|
||||||
|
children: <Widget>[
|
||||||
|
if (event.status.toString() == "null") // no game yet
|
||||||
|
Text(
|
||||||
|
'${_months[event.date.month]} ${event.date.day.toString()}')
|
||||||
|
else
|
||||||
|
_pastGameScore(
|
||||||
|
event.location_indicator.toString(),
|
||||||
|
event.status.toString(),
|
||||||
|
event.team_score.toString(),
|
||||||
|
event.opponent_score.toString()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
//Type of sport - Location
|
||||||
|
subtitle: Wrap(children: <Widget>[
|
||||||
|
//Should be either live time or time game will be, nothing for past games
|
||||||
|
]),
|
||||||
|
|
||||||
|
trailing: _homeAwayImageOrder(
|
||||||
|
event.location_indicator.toString(),
|
||||||
|
event.image.toString(), false),
|
||||||
|
onTap: () =>
|
||||||
|
print('${event.date}'), //When event display is clicked
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -115,8 +115,7 @@ class _Calendar extends State<Calendar> with TickerProviderStateMixin {
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
_buildCalendar(),
|
_buildCalendar(),
|
||||||
const SizedBox(height: 8.0),
|
_eventLister(),
|
||||||
Expanded(child: _eventLister()),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -272,119 +271,79 @@ class _Calendar extends State<Calendar> with TickerProviderStateMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//----- Creates event display -----
|
//----- Creates event display -----
|
||||||
|
Text _pastGameScore(
|
||||||
|
String homeAway, String winLoss, String uncc, String opponent) {
|
||||||
|
if (homeAway == "H" || homeAway == "T") {
|
||||||
|
return (Text('$uncc - $opponent'));
|
||||||
|
} else {
|
||||||
|
return (Text('$opponent - $uncc'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Image _homeAwayImageOrder(String h, String opposingTeam, bool l) {
|
||||||
|
if ((h == "H") == l) {
|
||||||
|
return (Image(
|
||||||
|
image: AssetImage('assets/school_logos/uncc.png'),
|
||||||
|
width: 50,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
return (Image.network(
|
||||||
|
'https://charlotte49ers.com' + opposingTeam,
|
||||||
|
width: 50.0,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Widget _eventLister() {
|
Widget _eventLister() {
|
||||||
return ListView(
|
var _months = {1:'JAN', 2:'FEB', 3:'MAR', 4:'APR', 5:'MAY', 6:'JUN',
|
||||||
children: _selectedEvents.map((event) => Container(
|
7:'JUL', 8:'AUG', 9:'SEP', 10:'OCT', 11:'NOV', 12:'DEC'};
|
||||||
decoration: BoxDecoration(
|
return SizedBox(
|
||||||
border: Border.all(
|
height: 78,
|
||||||
color: Color.fromRGBO(0, 112, 60, 1), //UNCC Green
|
child: Column(
|
||||||
width: 0.8,
|
children: _selectedEvents
|
||||||
),
|
.map((event) => Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(12.0),
|
border: Border.all(
|
||||||
),
|
color: Color.fromRGBO(0, 112, 60, 1), //UNCC Green
|
||||||
|
width: 0.8,
|
||||||
height: 70.0,
|
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
|
|
||||||
|
|
||||||
child: ListTile(
|
|
||||||
leading: Image.network(
|
|
||||||
'https://charlotte49ers.com' + event.image.toString(),
|
|
||||||
width: 50.0,
|
|
||||||
),
|
|
||||||
title: Wrap(
|
|
||||||
children: <Widget>[
|
|
||||||
if (event.location_indicator.toString() == "H")
|
|
||||||
Text(
|
|
||||||
'vs. ',
|
|
||||||
style: TextStyle( //home game
|
|
||||||
fontSize: 11.6,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
else
|
|
||||||
Text(
|
|
||||||
'at ',
|
|
||||||
style: TextStyle( //away game
|
|
||||||
fontSize: 11.6,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
Text(
|
|
||||||
event.opponentTitle.toString(),
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 11.6,
|
|
||||||
),
|
|
||||||
) //opponent name
|
|
||||||
],
|
|
||||||
),
|
|
||||||
|
|
||||||
//Type of sport - Location
|
|
||||||
subtitle: Text(
|
|
||||||
event.sportTitle.toString() + " - " + event.location.toString(),
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 10.3,
|
|
||||||
),
|
),
|
||||||
|
borderRadius: BorderRadius.circular(12.0),
|
||||||
),
|
),
|
||||||
|
height: 70.0,
|
||||||
|
margin:
|
||||||
|
const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
|
||||||
|
child: ListTile(
|
||||||
|
leading: _homeAwayImageOrder(
|
||||||
|
event.location_indicator.toString(),
|
||||||
|
event.image.toString(), true),
|
||||||
|
title: Wrap(
|
||||||
|
children: <Widget>[
|
||||||
|
if (event.status.toString() == "null") // no game yet
|
||||||
|
Text(
|
||||||
|
'${_months[event.date.month]} ${event.date.day.toString()}')
|
||||||
|
else
|
||||||
|
_pastGameScore(
|
||||||
|
event.location_indicator.toString(),
|
||||||
|
event.status.toString(),
|
||||||
|
event.team_score.toString(),
|
||||||
|
event.opponent_score.toString()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
trailing: Wrap(
|
//Type of sport - Location
|
||||||
//mainAxisSize: MainAxisSize.min,
|
subtitle: Wrap(children: <Widget>[
|
||||||
|
//Should be either live time or time game will be, nothing for past games
|
||||||
|
]),
|
||||||
|
|
||||||
children: <Widget>[
|
trailing: _homeAwayImageOrder(
|
||||||
//---Score---
|
event.location_indicator.toString(),
|
||||||
//Game hasn't occured
|
event.image.toString(), false),
|
||||||
if (event.status.toString() == "null")
|
onTap: () =>
|
||||||
Text("TBD"),
|
print('${event.date}'), //When event display is clicked
|
||||||
|
|
||||||
//---Scores---
|
|
||||||
if (event.status.toString() == "W" || event.status.toString() == "L" || event.status.toString() == "T") //Finished games
|
|
||||||
Text(event.team_score.toString() + " - " + event.opponent_score.toString() + " ")
|
|
||||||
|
|
||||||
else if (event.status.toString() == "N" && event.team_score.toString() != "null" && event.opponent_score.toString() != "null") //Games that don't count
|
|
||||||
Text(event.team_score.toString() + " - " + event.opponent_score.toString() + " "),
|
|
||||||
|
|
||||||
//---Game Status---
|
|
||||||
if (event.status.toString() == "W") //Win
|
|
||||||
Text(
|
|
||||||
(" " + event.status.toString() + " "),
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
backgroundColor: Color.fromRGBO(0, 112, 60, 1),
|
|
||||||
)
|
|
||||||
),
|
|
||||||
|
|
||||||
if (event.status.toString() == "L" || event.status.toString() == "T") //Lose-Tie
|
|
||||||
Text(
|
|
||||||
(" " + event.status.toString() + " "),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.black,
|
|
||||||
backgroundColor: Colors.grey,
|
|
||||||
)
|
|
||||||
),
|
|
||||||
|
|
||||||
if (event.status.toString() == "N" && event.postscore.toString() != "Canceled") //N
|
|
||||||
Text(
|
|
||||||
(" " + event.status.toString() + " "),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.black,
|
|
||||||
backgroundColor: Colors.grey,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else if (event.team_score.toString() == "null" && event.opponent_score.toString() == "null"
|
|
||||||
&& event.status.toString() == "N") //Game was canceled
|
|
||||||
Text(
|
|
||||||
"Canceled",
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.red,
|
|
||||||
)
|
|
||||||
),
|
|
||||||
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
onTap: () => print('$event tapped!'), //When event display is clicked
|
))
|
||||||
),
|
.toList(),
|
||||||
)).toList(),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,10 +69,10 @@ class Sport extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
body: ListView(
|
body: ListView(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
HorizontalNewsFeed(newsFeed: feed, title: Text(_curSport.name)),
|
HorizontalNewsFeed(newsFeed: feed, title: Text(_curSport.name), sportFilter: _curSport.name,),
|
||||||
HorizontalNewsFeed(newsFeed: feed, title: Text(_curSport.name)),
|
HorizontalNewsFeed(newsFeed: feed, title: Text(_curSport.name), sportFilter: _curSport.name),
|
||||||
HorizontalNewsFeed(newsFeed: feed, title: Text(_curSport.name)),
|
HorizontalNewsFeed(newsFeed: feed, title: Text(_curSport.name), sportFilter: _curSport.name),
|
||||||
HorizontalNewsFeed(newsFeed: feed, title: Text(_curSport.name)),
|
HorizontalNewsFeed(newsFeed: feed, title: Text(_curSport.name), sportFilter: _curSport.name),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
drawer: Drawer(
|
drawer: Drawer(
|
||||||
|
|||||||
Reference in New Issue
Block a user