logic for game card

This commit is contained in:
Carlos Lopez-Rosario
2020-05-01 02:45:54 -04:00
parent f71bd6ad21
commit a2950f6997
4 changed files with 228 additions and 146 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

View File

@@ -1,49 +1,27 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:table_calendar/table_calendar.dart';
import '../screens/sport_schedule.dart'; import '../screens/sport_schedule.dart';
import 'dart:convert'; import 'dart:convert';
class GameCard extends StatefulWidget { class GameCardFeed{
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 = static final sportUrl =
'https://charlotte49ers.com/services/adaptive_components.ashx?type=scoreboard&start=0&count=80'; 'https://charlotte49ers.com/services/adaptive_components.ashx?type=scoreboard&start=0&count=80';
Future<List<sport_schedule>> getEvents(int sportID) async {
Future<List<sport_schedule>> getEvents() async {
var url = '$sportUrl&sport_id=$sportID&name=&extra=%7B%7D'; var url = '$sportUrl&sport_id=$sportID&name=&extra=%7B%7D';
http.Response response = await http.get(url); http.Response response = await http.get(url);
Iterable games = json.decode(response.body); Iterable games = json.decode(response.body);
return games return games
.map<sport_schedule>((json) => sport_schedule.fromJson(json)) .map<sport_schedule>((json) => sport_schedule.fromJson(json))
.toList(); .toList();
//return games.map((e) => sport_schedule.fromJson(e)).toList(); //return games.map((e) => sport_schedule.fromJson(e)).toList();
} }
Future<List<ScheduleObject>> getGames(int sportID) async {
Future<Map<DateTime, List<sport_schedule>>> getGames() async {
Map<DateTime, List<sport_schedule>> mapGrab = {}; Map<DateTime, List<sport_schedule>> mapGrab = {};
List<sport_schedule> eventInfo = await getEvents(); List<sport_schedule> eventInfo = await getEvents(sportID);
for (int i = 0; i < eventInfo.length; i++) { for (int i = 0; i < eventInfo.length; i++) {
var sportEvent = DateTime(eventInfo[i].date.year, eventInfo[i].date.month, var sportEvent = DateTime(eventInfo[i].date.year, eventInfo[i].date.month,
@@ -55,127 +33,114 @@ class _SportsCard extends State<GameCard> with TickerProviderStateMixin {
mapGrab[sportEvent] = [eventInfo[i]]; mapGrab[sportEvent] = [eventInfo[i]];
} else { } else {
//print(eventInfo[i].date); //print(eventInfo[i].date);
mapGrab[sportEvent] = List.from(original)..addAll([eventInfo[i]]); mapGrab[sportEvent] = List.from(original)
..addAll([eventInfo[i]]);
} }
} }
return mapGrab; List<ScheduleObject> list = [];
mapGrab.forEach((k, v) => list.add(ScheduleObject(k, v)));
return list;
}
} }
@override class HorizontalGameCards extends StatelessWidget {
void initState() { final GameCardFeed gameCard;
//final _selectedDay = DateTime.now(); final double numCards;
final int sportID;
//_selectedEvents = _events[_selectedDay] ?? []; const HorizontalGameCards({
_selectedEvents = []; Key key,
_animationController = AnimationController( @required this.gameCard,
vsync: this, this.numCards = 8,
duration: const Duration(milliseconds: 400), this.sportID,
); }) : super(key: key);
_animationController.forward(); double heightIn(BuildContext context) {
return MediaQuery.of(context).size.height / numCards;
WidgetsBinding.instance.addPostFrameCallback((_) {
getGames().then((val) => setState(() {
_events = val;
}));
});
super.initState();
} }
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
//----- Builds event Lister -----
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Center( var card = gameCard.getGames(sportID);
child: Container( var events = [];
child: Expanded(child: _eventLister()), return SizedBox(
height: heightIn(context),//heightIn(context),
child: FutureBuilder(
future: card,
// ignore: missing_return
builder: (ctx, snapshot) {
print(snapshot);
if (!snapshot.hasData) {
return Center(child: CircularProgressIndicator());
} else {
events = snapshot.data;
return ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: events.length,
itemBuilder: (context, index) {
return GameCard(
gameCard: events[index].sportSched[0],
);
},
);
}
},
), ),
); );
} }
//----- 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) { class ScheduleObject {
if ((h == "H") == l) { DateTime d;
return (Image( List<sport_schedule> sportSched;
image: AssetImage('assets/school_logos/uncc.png'), ScheduleObject(this.d, this.sportSched);
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( class GameCardTest extends StatelessWidget{
children: _selectedEvents final int sportID;
.map((event) => Container( GameCardTest(this.sportID);
decoration: BoxDecoration(
border: Border.all( @override
color: Color.fromRGBO(0, 112, 60, 1), //UNCC Green Widget build(BuildContext context) {
width: 0.8, final feed = GameCardFeed();
return StatefulBuilder(
builder: (context, StateSetter setState) => Scaffold(
appBar: AppBar(
centerTitle: false,
title: Text("49ers"),
backgroundColor: Colors.green,
), ),
borderRadius: BorderRadius.circular(12.0), body: HorizontalGameCards(gameCard: feed, sportID: sportID,),
), drawer: Drawer(
height: 70.0, child: ListView(
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>[ children: <Widget>[
if (event.status.toString() == "null") // no game yet DrawerHeader(
Text( child: Text(
'${_months[event.date.month]} ${event.date.day.toString()}') 'Drawer Header',
else style: TextStyle(
_pastGameScore( color: Colors.white,
event.location_indicator.toString(), fontSize: 24,
event.status.toString(), ),
event.team_score.toString(), ),
event.opponent_score.toString()), decoration: BoxDecoration(
color: Colors.green,
),
),
ListTile(
title: IconButton(
icon: Icon(Icons.home),
onPressed: () => Navigator.pushNamed(context, '/'),
),
),
], ],
), ),
)
//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(),
),
);
} }
} }

View File

@@ -1,3 +1,4 @@
import 'package:capstone_hungry_hippos/models/game_cards.dart';
import 'package:capstone_hungry_hippos/screens/chat.dart'; import 'package:capstone_hungry_hippos/screens/chat.dart';
import 'package:capstone_hungry_hippos/screens/schedule.dart'; import 'package:capstone_hungry_hippos/screens/schedule.dart';
import 'package:capstone_hungry_hippos/screens/standing.dart'; import 'package:capstone_hungry_hippos/screens/standing.dart';
@@ -31,6 +32,8 @@ class RouteGenerator {
return MaterialPageRoute(builder: (_) => FavoritesManager()); return MaterialPageRoute(builder: (_) => FavoritesManager());
case '/Twitter': case '/Twitter':
return MaterialPageRoute(builder: (_) => TwitterFeed()); return MaterialPageRoute(builder: (_) => TwitterFeed());
case '/gamecardtest':
return MaterialPageRoute(builder: (_) => GameCardTest(args));
default: default:
return _errorRoute(); return _errorRoute();
} }

View File

@@ -62,3 +62,117 @@ class sport_schedule {
); );
} }
} }
class GameCard extends StatelessWidget {
const GameCard({
Key key,
@required this.gameCard,
this.numCards = 1.75,
}) : super(key: key);
final sport_schedule gameCard;
final double numCards;
double widthIn(BuildContext context) {
return MediaQuery.of(context).size.width / numCards;
}
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, BuildContext ctx) {
if ((h == "H") == l) {
return (Image.network(
'https://fiusports.com/images/logos/UNC-Charlotte.png?width=80&height=80&mode=max'
));
} else {
return (Image.network(
'https://charlotte49ers.com' + opposingTeam,
));
}
}
@override
Widget build(BuildContext ctx) {
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'
};
var decoration = BoxDecoration(
border: Border.all(
color: Color.fromRGBO(0, 112, 60, 1), //UNCC Green
width: .5,
),
borderRadius: BorderRadius.circular(12.0),
);
var body = Column(
verticalDirection: VerticalDirection.up,
children: <Widget>[
Container(
color: Colors.white,
child: ListTile(
leading: SizedBox(
//width: widthIn(ctx)/3 - 5,
child: Container(decoration: decoration,child: _homeAwayImageOrder(
gameCard.location_indicator,
gameCard.image,
true, ctx))),
title: SizedBox(
//width: widthIn(ctx)/3 - 5,
child: Container(decoration: decoration,child: Wrap(
children: <Widget>[
if (gameCard.status == "null") // no game yet
Text(
'${_months[gameCard.date.month]} ${gameCard.date.day}')
else
_pastGameScore(
gameCard.location_indicator,
gameCard.status,
gameCard.team_score,
gameCard.opponent_score,),
],
))
),
trailing: SizedBox(
//width: widthIn(ctx)/3 - 5,
child: Container(decoration: decoration,child: _homeAwayImageOrder(
gameCard.location_indicator,
gameCard.image,
false, ctx))),
onTap: () => print('${gameCard.date}'),
),
),
],
);
return SizedBox(
width: widthIn(ctx),
child: Card(
semanticContainer: true,
clipBehavior: Clip.antiAliasWithSaveLayer,
child: Container(
decoration: decoration,
child: body,
),
),
);
}
}