diff --git a/assets/school_logos/UNC-Charlotte (1).png b/assets/school_logos/UNC-Charlotte (1).png new file mode 100644 index 0000000..bd01193 Binary files /dev/null and b/assets/school_logos/UNC-Charlotte (1).png differ diff --git a/ios/Podfile b/ios/Podfile new file mode 100644 index 0000000..0ee4a53 --- /dev/null +++ b/ios/Podfile @@ -0,0 +1,90 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '9.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def parse_KV_file(file, separator='=') + file_abs_path = File.expand_path(file) + if !File.exists? file_abs_path + return []; + end + generated_key_values = {} + skip_line_start_symbols = ["#", "/"] + File.foreach(file_abs_path) do |line| + next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ } + plugin = line.split(pattern=separator) + if plugin.length == 2 + podname = plugin[0].strip() + path = plugin[1].strip() + podpath = File.expand_path("#{path}", file_abs_path) + generated_key_values[podname] = podpath + else + puts "Invalid plugin specification: #{line}" + end + end + generated_key_values +end + +target 'Runner' do + use_frameworks! + use_modular_headers! + + # Flutter Pod + + copied_flutter_dir = File.join(__dir__, 'Flutter') + copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework') + copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec') + unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path) + # Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet. + # That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration. + # CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist. + + generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig') + unless File.exist?(generated_xcode_build_settings_path) + raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path) + cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR']; + + unless File.exist?(copied_framework_path) + FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir) + end + unless File.exist?(copied_podspec_path) + FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir) + end + end + + # Keep pod path relative so it can be checked into Podfile.lock. + pod 'Flutter', :path => 'Flutter' + + # Plugin Pods + + # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock + # referring to absolute paths on developers' machines. + system('rm -rf .symlinks') + system('mkdir -p .symlinks/plugins') + plugin_pods = parse_KV_file('../.flutter-plugins') + plugin_pods.each do |name, path| + symlink = File.join('.symlinks', 'plugins', name) + File.symlink(path, symlink) + pod name, :path => File.join(symlink, 'ios') + end +end + +# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system. +install! 'cocoapods', :disable_input_output_paths => true + +post_install do |installer| + installer.pods_project.targets.each do |target| + target.build_configurations.each do |config| + config.build_settings['ENABLE_BITCODE'] = 'NO' + end + end +end diff --git a/ios/Podfile.lock b/ios/Podfile.lock new file mode 100644 index 0000000..f7203c7 --- /dev/null +++ b/ios/Podfile.lock @@ -0,0 +1,34 @@ +PODS: + - Flutter (1.0.0) + - shared_preferences (0.0.1): + - Flutter + - shared_preferences_macos (0.0.1): + - Flutter + - shared_preferences_web (0.0.1): + - Flutter + +DEPENDENCIES: + - Flutter (from `Flutter`) + - shared_preferences (from `.symlinks/plugins/shared_preferences/ios`) + - shared_preferences_macos (from `.symlinks/plugins/shared_preferences_macos/ios`) + - shared_preferences_web (from `.symlinks/plugins/shared_preferences_web/ios`) + +EXTERNAL SOURCES: + Flutter: + :path: Flutter + shared_preferences: + :path: ".symlinks/plugins/shared_preferences/ios" + shared_preferences_macos: + :path: ".symlinks/plugins/shared_preferences_macos/ios" + shared_preferences_web: + :path: ".symlinks/plugins/shared_preferences_web/ios" + +SPEC CHECKSUMS: + Flutter: 0e3d915762c693b495b44d77113d4970485de6ec + shared_preferences: 430726339841afefe5142b9c1f50cb6bd7793e01 + shared_preferences_macos: f3f29b71ccbb56bf40c9dd6396c9acf15e214087 + shared_preferences_web: 141cce0c3ed1a1c5bf2a0e44f52d31eeb66e5ea9 + +PODFILE CHECKSUM: 083258d7f5e80b42ea9bfee905fe93049bc04c64 + +COCOAPODS: 1.7.5 diff --git a/lib/models/game_cards.dart b/lib/models/game_cards.dart new file mode 100644 index 0000000..f36156d --- /dev/null +++ b/lib/models/game_cards.dart @@ -0,0 +1,97 @@ +import 'package:flutter/material.dart'; +import 'package:http/http.dart' as http; + +import '../screens/sport_schedule.dart'; +import 'dart:convert'; + +class GameCardFeed{ + + static final sportUrl = + 'https://charlotte49ers.com/services/adaptive_components.ashx?type=scoreboard&start=0&count=80'; + Future> getEvents(int sportID) 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((json) => sport_schedule.fromJson(json)) + .toList(); + //return games.map((e) => sport_schedule.fromJson(e)).toList(); + } + Future> getGames(int sportID) async { + Map> mapGrab = {}; + + List eventInfo = await getEvents(sportID); + + 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]]); + } + } + List list = []; + mapGrab.forEach((k, v) => list.add(ScheduleObject(k, v))); + return list; + } +} + +class HorizontalGameCards extends StatelessWidget { + final GameCardFeed gameCard; + final double numCards; + final int sportID; + + const HorizontalGameCards({ + Key key, + @required this.gameCard, + this.numCards = 8, + this.sportID, + }) : super(key: key); + + double heightIn(BuildContext context) { + return MediaQuery.of(context).size.height / numCards; + } + + @override + Widget build(BuildContext context) { + var card = gameCard.getGames(sportID); + var events = []; + return SizedBox( + height: 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], + ); + }, + ); + } + }, + ), + ); + } + } + +class ScheduleObject { + DateTime d; + List sportSched; + ScheduleObject(this.d, this.sportSched); +} \ No newline at end of file diff --git a/lib/monthly_calendar.dart b/lib/monthly_calendar.dart index e92d4a1..eb16c58 100644 --- a/lib/monthly_calendar.dart +++ b/lib/monthly_calendar.dart @@ -3,12 +3,14 @@ import 'package:http/http.dart' as http; import 'package:table_calendar/table_calendar.dart'; import 'screens/sport_schedule.dart'; -import 'screens/sport.dart' as globals; import 'dart:convert'; class Calendar extends StatefulWidget { + final int sportID; + Calendar(this.sportID); + @override - _Calendar createState() => _Calendar(); + _Calendar createState() => _Calendar(sportID); } //List _selectedEvents; //original that makes events work @@ -17,15 +19,19 @@ DateTime selectedDay; Map> _events; class _Calendar extends State with TickerProviderStateMixin { + int sportID; + _Calendar(this.sportID); + AnimationController _animationController; CalendarController _calController; - int sportID = globals.Sport.sport_ID; static final sportUrl = 'https://charlotte49ers.com/services/adaptive_components.ashx?type=scoreboard&start=0&count=80'; Future> getEvents() async { var url = '$sportUrl&sport_id=$sportID&name=&extra=%7B%7D'; + print(url.toString()); + http.Response response = await http.get(url); Iterable games = json.decode(response.body); @@ -47,10 +53,8 @@ class _Calendar extends State with TickerProviderStateMixin { 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]]); } } @@ -59,7 +63,7 @@ class _Calendar extends State with TickerProviderStateMixin { @override void initState() { - final _selectedDay = DateTime.now(); + //final _selectedDay = DateTime.now(); //_selectedEvents = _events[_selectedDay] ?? []; _selectedEvents = []; @@ -201,15 +205,20 @@ class _Calendar extends State with TickerProviderStateMixin { markersBuilder: (context, date, events, holidays) { final miniBox = []; - if (events.isNotEmpty) { miniBox.add( Positioned( - right: 1, - bottom: 1, - child: _buildEventsMarker(date, events), + right: 0,top: 0, left: 0, bottom: 0, + child: _buildEventsMarker(date, events[0].location_indicator, true, events), ), ); + if (events.length > 1) + miniBox.add( + Positioned( + right: 1, bottom: 1, + child: _buildEventsMarker(date, events[0].location_indicator, false, events), + ) + ); } return miniBox; @@ -228,27 +237,26 @@ class _Calendar extends State with TickerProviderStateMixin { } //----- Creates event box display (mini box) ----- - Widget _buildEventsMarker(DateTime date, List events) { + Widget _buildEventsMarker(DateTime date, String gameType, bool main, events) { + String eventNum; + if (main) {eventNum = "${date.day}";} else {eventNum = "${events.length}";} + + //return Container( return AnimatedContainer( duration: const Duration(milliseconds: 300), + margin: const EdgeInsets.all(4.0), + alignment: Alignment.center, + decoration: BoxDecoration( - shape: BoxShape.rectangle, - - /*border: _calController.isSelected(date) //if selected date - ? Border.all(color: Colors.black, width: 1.5,) - : _calController.isToday(date) //if today's date - ? Border.all(color: Colors.black, width: 1.5,) - : Border.all(color: Colors.black, width: 0,),*/ - - //color: Color.fromRGBO(0, 112, 60, 1), //UNCC Green - //color: Colors.grey, - - //if selected date && home game / else away game - color: _calController.isSelected(date) - ? Colors.blue[400] - : Color.fromRGBO(0, 112, 60, 1), //UNCC Green - //: Colors.grey, + /*border: Border.all( + color: Color.fromRGBO(0, 112, 60, 1), //UNCC Green + //color: Colors.black, + ),*/ + color: _calController.isSelected(date) + ? Color.fromRGBO(179, 163, 105, 1) //UNCC Gold + : _gameTypeColor(gameType, main), //UNCC Green + borderRadius: BorderRadius.circular(10.0) ), width: 16.0, @@ -256,7 +264,7 @@ class _Calendar extends State with TickerProviderStateMixin { child: Center( child: Text( - '${events.length}', + eventNum, style: TextStyle().copyWith( color: Colors.white, fontSize: 12.0, @@ -266,6 +274,20 @@ class _Calendar extends State with TickerProviderStateMixin { ); } + //Logic on if Home or Away return the colors + Color _gameTypeColor(String gameType, bool main){ + Color c; + if (gameType == "H"){ + c = Color.fromRGBO(0, 112, 60, 1); //UNCC Green + } else { + c = Colors.grey; + } + if (!main){ + c = Colors.black45;//Color.fromRGBO(179, 163, 105, 1); + } + return c; + } + //----- Creates event display ----- Widget _eventLister() { return ListView( @@ -285,7 +307,7 @@ class _Calendar extends State with TickerProviderStateMixin { child: ListTile( leading: Image.network( 'https://charlotte49ers.com' + event.image.toString(), - width: 50.0, + width: 35.0, ), title: Wrap( children: [ @@ -317,7 +339,7 @@ class _Calendar extends State with TickerProviderStateMixin { subtitle: Text( event.sportTitle.toString() + " - " + event.location.toString(), style: TextStyle( - fontSize: 10.3, + fontSize: 9.9, //10.3 ), ), diff --git a/lib/news/article.dart b/lib/news/article.dart index 033f85b..9019538 100644 --- a/lib/news/article.dart +++ b/lib/news/article.dart @@ -90,3 +90,59 @@ class ArticleCard extends StatelessWidget { ); } } + +class ArticleCardVert extends StatelessWidget { + const ArticleCardVert({ + Key key, + @required this.article, + this.numCards = 2.1, + }) : super(key: key); + + final Article article; + final double numCards; + + double heightIn(BuildContext context) { + return (MediaQuery.of(context).size.height * 7/8) / numCards; + } + + @override + Widget build(BuildContext context) { + var decoration = BoxDecoration( + image: DecorationImage( + image: NetworkImage( + article.thumbUrl, + ), + fit: BoxFit.cover, + ), + ); + + var body = Column( + verticalDirection: VerticalDirection.up, + children: [ + Container( + color: Colors.white, + child: ListTile( + title: Text( + article.mediumHeadline, + overflow: TextOverflow.ellipsis, + maxLines: 2, + ), + ), + ), + ], + ); + + + return SizedBox( + height: heightIn(context), + child: Card( + semanticContainer: true, + clipBehavior: Clip.antiAliasWithSaveLayer, + child: Container( + decoration: decoration, + child: body, + ), + ), + ); + } +} diff --git a/lib/news/feed.dart b/lib/news/feed.dart index c5662ce..d4a27db 100644 --- a/lib/news/feed.dart +++ b/lib/news/feed.dart @@ -18,22 +18,25 @@ class Feed { class HorizontalNewsFeed extends StatelessWidget { final Feed newsFeed; - final Widget title; + final Text title; final double numCards; + final String sportFilter; const HorizontalNewsFeed({ Key key, @required this.newsFeed, @required this.title, + @required this.sportFilter, this.numCards = 3.25, }) : super(key: key); double heightIn(BuildContext context) { return MediaQuery.of(context).size.height / numCards; } - @override Widget build(BuildContext context) { + var page = newsFeed.getPage(1, size: 100).then((page) => page.where((article) => article.sport.toLowerCase().contains(sportFilter.toLowerCase())).toList()); + return SizedBox( height: heightIn(context), child: Column( @@ -43,8 +46,7 @@ class HorizontalNewsFeed extends StatelessWidget { title: title, trailing: IconButton( icon: Icon(Icons.navigate_next), - - onPressed: () => Navigator.of(context).pushNamed('/Sport'), + onPressed: () => Navigator.of(context).pushNamed('/Sport', arguments: title.data), /*onPressed: () { //changed Navigator.of(context).pushNamed('/Sport'); @@ -55,13 +57,14 @@ class HorizontalNewsFeed extends StatelessWidget { ), Expanded( child: FutureBuilder( - future: newsFeed.getPage(1), + future: page, builder: (ctx, snapshot) { if (!snapshot.hasData) { return Center(child: CircularProgressIndicator()); } else { List
articles = snapshot.data; return ListView.builder( + //shrinkWrap: true, scrollDirection: Axis.horizontal, itemCount: articles.length, itemBuilder: (ctx, idx) { @@ -79,3 +82,43 @@ class HorizontalNewsFeed extends StatelessWidget { ); } } + + +class VerticalNewsFeed extends StatelessWidget { + final Feed newsFeed; + final String sportFilter; + + const VerticalNewsFeed({ + Key key, + @required this.newsFeed, + @required this.sportFilter, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + var page = newsFeed.getPage(1, size: 100).then((page) => page.where((article) => article.sport.toLowerCase().contains(sportFilter.toLowerCase())).toList()); + var size = MediaQuery.of(context).size; + return SizedBox( + height: size.height * (7/8), + child: FutureBuilder( + future: page, + builder: (ctx, snapshot) { + if (!snapshot.hasData) { + return Center(child: CircularProgressIndicator()); + } else { + List
articles = snapshot.data; + return ListView.builder( + //shrinkWrap: true, + scrollDirection: Axis.vertical, + itemCount: articles.length, + itemBuilder: (ctx, idx) { + return ArticleCardVert( + article: articles[idx], + ); + }, + ); + } + }, + )); + } +} diff --git a/lib/route_generator.dart b/lib/route_generator.dart index 7678fff..e0caca6 100644 --- a/lib/route_generator.dart +++ b/lib/route_generator.dart @@ -12,17 +12,17 @@ class RouteGenerator { static Route generateRoute(RouteSettings settings) { final args = settings .arguments; //This is how we pass arguments and can be used in case - + print("args $args"); switch (settings.name) { case '/': return MaterialPageRoute(builder: (_) => Home()); case '/Sport': //We can put logic and stuff here for checking if logged in - return MaterialPageRoute(builder: (_) => Sport()); + return MaterialPageRoute(builder: (_) => Sport(args)); case '/Schedule': - return MaterialPageRoute(builder: (_) => Schedule()); + return MaterialPageRoute(builder: (_) => Schedule(args)); case '/Standing': - return MaterialPageRoute(builder: (_) => Standing()); + return MaterialPageRoute(builder: (_) => Standing(args)); case '/Chat': return MaterialPageRoute(builder: (_) => Chat()); case '/Details': diff --git a/lib/screens/favorites_reorder.dart b/lib/screens/favorites_reorder.dart index 3c6ad9a..6e2d388 100644 --- a/lib/screens/favorites_reorder.dart +++ b/lib/screens/favorites_reorder.dart @@ -10,7 +10,6 @@ class Favorites { 'Basketball', 'Baseball', 'Soccer', - 'Tennis', 'Volleyball' ]; diff --git a/lib/screens/home_widget.dart b/lib/screens/home_widget.dart index 1a7f475..a9c919f 100644 --- a/lib/screens/home_widget.dart +++ b/lib/screens/home_widget.dart @@ -96,6 +96,7 @@ Future> _buildList() async { return HorizontalNewsFeed( newsFeed: feed, title: Text(sport), + sportFilter: sport, ); }).toList(); } diff --git a/lib/screens/schedule.dart b/lib/screens/schedule.dart index 0a3f716..b7dc1aa 100644 --- a/lib/screens/schedule.dart +++ b/lib/screens/schedule.dart @@ -1,17 +1,19 @@ import 'package:flutter/material.dart'; import '../monthly_calendar.dart'; - +import '../screens/sport.dart' as globals; class Schedule extends StatelessWidget{ - final calendar = Calendar(); + final List sport; + Schedule(this.sport); @override Widget build(BuildContext context) { + var calendar = Calendar(sport[0]); return StatefulBuilder( builder: (context, StateSetter setState) => Scaffold( appBar: AppBar( centerTitle: false, - title: Text("49ers"), + title: Text("${sport[1]}"), backgroundColor: Colors.green, ), body: Container ( diff --git a/lib/screens/sport.dart b/lib/screens/sport.dart index b141d4d..cc28258 100644 --- a/lib/screens/sport.dart +++ b/lib/screens/sport.dart @@ -1,53 +1,63 @@ import 'package:flutter/material.dart'; import '../news/feed.dart'; +import '../models/game_cards.dart'; class Sport extends StatelessWidget { - static final List colorList = [ - const Item('FootBall', Colors.green), - const Item("BasketBall", Colors.red), - const Item("Soccer", Colors.pinkAccent), - const Item('Baseball', Colors.orange), + const Item('Football',[3]), + const Item("Basketball",[5,13]), + const Item("Soccer",[9,17]), + const Item('Baseball',[1]), + const Item('Softball',[12]), + const Item('Volleyball',[20]), + const Item('Tennis',[10,18]), ]; + final feed = Feed(); // was var not final + final gameCard = GameCardFeed(); + + final String imageMale = 'images/male.png'; + final String imageFemale = 'images/female.png'; + static bool genderSportSwitch = false; //determines if sport needs the gender switch + static bool genderSport = false; //determines which gender switch is set M - false / F - True + static int sport_ID; + final String sport; + Sport(this.sport); + Item _curSport = colorList[0]; - final feed = Feed(); // was var not final - - bool genderSportSwitch = false; //determines if sport needs the gender switch - final String imageMale = 'images/male.png'; - final String imageFemale = 'images/female.png'; - static bool genderSport = false; //determines which gender switch is set M - false / F - True - - static int sport_ID; - @override Widget build(BuildContext context) { + Item _setDefault(){ + Item _curSport; + for (Item i in colorList){ + if (i.name == sport){ + _curSport = i; + break; + } + } + return _curSport; + } + _curSport = _setDefault(); + sport_ID = _curSport.sportID[0]; Item selectedSport; - + _genderSwitcherCheck(); return StatefulBuilder( builder: (context, StateSetter setState) => Scaffold( appBar: AppBar( - centerTitle: false, - title: buildDropdownButton(selectedSport, setState), - backgroundColor: _curSport.color, + centerTitle: false, + title: buildDropdownButton(selectedSport, setState), + backgroundColor: Colors.green, //--Gender Switch-- Need to make condition to determine gender actions: [ - if (genderSportSwitch == true) + if (genderSportSwitch) Switch( value: genderSport, onChanged: (value) { setState(() { - if (value == false) { - genderSport = false; - } - else { - genderSport = true; - } - - print("value: " + value.toString()); - print("gender: " + genderSport.toString()); + genderSport = value; + _genderSwitcherCheck(); }); }, inactiveThumbColor: Colors.lightBlue, @@ -59,11 +69,10 @@ class Sport extends StatelessWidget { ] ), body: ListView( + physics: const NeverScrollableScrollPhysics(), children: [ - HorizontalNewsFeed(newsFeed: feed, title: Text(_curSport.name)), - HorizontalNewsFeed(newsFeed: feed, title: Text(_curSport.name)), - HorizontalNewsFeed(newsFeed: feed, title: Text(_curSport.name)), - HorizontalNewsFeed(newsFeed: feed, title: Text(_curSport.name)), + HorizontalGameCards(gameCard: gameCard, sportID: sport_ID,), + VerticalNewsFeed(newsFeed: feed, sportFilter: _curSport.name), ], ), drawer: Drawer( @@ -90,13 +99,13 @@ class Sport extends StatelessWidget { ListTile( title: IconButton( icon: Icon(Icons.table_chart), - onPressed: () => Navigator.pushNamed(context, '/Standing'), + onPressed: () => Navigator.pushNamed(context, '/Standing', arguments: [sport_ID, _curSport.name]), ), ), ListTile( title: IconButton( icon: Icon(Icons.calendar_today), - onPressed: () => Navigator.pushNamed(context, '/Schedule'), + onPressed: () => Navigator.pushNamed(context, '/Schedule',arguments: [sport_ID, _curSport.name],), ), ), ], @@ -106,8 +115,7 @@ class Sport extends StatelessWidget { ); } - DropdownButtonHideUnderline buildDropdownButton( - Item selectedSport, StateSetter setState) { + DropdownButtonHideUnderline buildDropdownButton(Item selectedSport, StateSetter setState) { return DropdownButtonHideUnderline( child: DropdownButton( value: selectedSport, @@ -123,45 +131,8 @@ class Sport extends StatelessWidget { onChanged: (Item value) { setState(() { _curSport = value; - - print("genderSport: " + genderSport.toString()); - - //Will set the sport id / Display gender switch - switch (_curSport.name) { //prints are temp - case 'FootBall': - genderSportSwitch = false; - sport_ID = 3; - break; - - case 'BasketBall': - genderSportSwitch = true; - - if (genderSport == false) { - sport_ID = 5; //Male - } - else { - sport_ID = 13; //Female - } - break; - - case 'Soccer': - genderSportSwitch = true; - - if (genderSport == false) { - sport_ID = 9; //Male - } - else { - sport_ID = 17; //Female - } - break; - - case 'Baseball': - genderSportSwitch = false; - - sport_ID = 1; - break; - } - print(sport_ID); + _genderSwitcherCheck(); + //print(sport_ID); }); }, items: colorList.map>((Item item) { @@ -176,11 +147,21 @@ class Sport extends StatelessWidget { ), ); } + + void _genderSwitcherCheck() { + if (_curSport.name == "Soccer" || _curSport.name == "Basketball" || _curSport.name == "Tennis" ){ + genderSportSwitch = true; + sport_ID = genderSport ? _curSport.sportID[1] : _curSport.sportID[0]; + } else { + genderSportSwitch = false; + sport_ID = _curSport.sportID[0]; + } + //print(sport_ID); + } } class Item { - const Item(this.name, this.color); - + const Item(this.name, this.sportID); final String name; - final Color color; -} + final List sportID; +} \ No newline at end of file diff --git a/lib/screens/sport_schedule.dart b/lib/screens/sport_schedule.dart index 5dcb470..71a93a5 100644 --- a/lib/screens/sport_schedule.dart +++ b/lib/screens/sport_schedule.dart @@ -62,3 +62,141 @@ class sport_schedule { ); } } + +class GameCard extends StatelessWidget { + const GameCard({ + Key key, + @required this.gameCard, + this.numCards = 2.25, + }) : 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, + )); + } + } + + Color winLoss(String wl){ + if (wl == "W") { + return Colors.green; + } else if (wl == "L") { + return Colors.red; + } else { + return Colors.grey; + } + } + + @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: winLoss(gameCard.status), //UNCC Green + width: 1.2, + ), + borderRadius: BorderRadius.circular(2), + ); + var logoWidth = 4.5; + var body = Column( + verticalDirection: VerticalDirection.up, + children: [ + Container( + color: Colors.white, + child: ListTile( + leading: SizedBox( + width: widthIn(ctx)/logoWidth, + child: _homeAwayImageOrder( + gameCard.location_indicator, + gameCard.image, + true, ctx)), + title: FittedBox( + fit: BoxFit.contain, + child: Wrap( + children: [ + 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,), + ], + ) + ), + subtitle: FittedBox( + fit: BoxFit.contain, + child: Wrap( + children: [ + if (gameCard.status != null) // no game yet + Text( + '${_months[gameCard.date.month]} ${gameCard.date.day}', textAlign: TextAlign.center, + ) + else + Text('${gameCard.date.hour}:${gameCard.date.minute} PM'), + ], + ) + ), + trailing: SizedBox( + width: widthIn(ctx)/logoWidth, + child: _homeAwayImageOrder( + gameCard.location_indicator, + gameCard.image, + false, ctx)), + onTap: () => print('${gameCard.date} ${gameCard.status}'), + ), + ), + ], + ); + + + return SizedBox( + width: widthIn(ctx), + child: Card( + semanticContainer: true, + clipBehavior: Clip.antiAliasWithSaveLayer, + child: Container( + decoration: decoration, + child: body, + ), + ), + ); + } +} diff --git a/lib/screens/standing.dart b/lib/screens/standing.dart index 8a57a29..87252ce 100644 --- a/lib/screens/standing.dart +++ b/lib/screens/standing.dart @@ -1,171 +1,54 @@ -import 'package:capstone_hungry_hippos/models/School.dart'; import 'package:flutter/material.dart'; +import '../team_standings.dart'; + class Standing extends StatelessWidget { - final _schools = [ - School("North Texas Mean Green",AssetImage('assets/school_logos/NorthTexas.png'), 14, 4), - School("Louisiana Tech Bulldogs",AssetImage('assets/school_logos/LT.png'), 13, 5), - School("Western Kentucky Hilltoppers",AssetImage('assets/school_logos/wku.png'), 13, 5), - School("Charlotte 49ers",AssetImage('assets/school_logos/uncc.png'), 10, 8), - School("Marshall Thundering Herd",AssetImage('assets/school_logos/Marshall.png'), 10, 8), - School("Florida Int'L Panthers",AssetImage('assets/school_logos/FIU.png'), 9, 9), - School("UAB Blazers",AssetImage('assets/school_logos/UAB.png'), 9, 9), - School("Old Dominion Monarchs",AssetImage('assets/school_logos/ODU.png'), 9, 9), - School("Florida Atlantic Owl",AssetImage('assets/school_logos/FAU.png'), 8, 10), - School("UTEP Miners",AssetImage('assets/school_logos/UTEP.png'), 8, 10), - School("UTSA Roadrunners",AssetImage('assets/school_logos/UTSA.png'), 7, 11), - School("Rice Owls",AssetImage('assets/school_logos/RiceOwls.png'), 7, 11), - School("Southern Miss Golden Eagles",AssetImage('assets/school_logos/SouthernMiss.png'), 5, 13), - School("Middle Tennessee Blue Raiders",AssetImage('assets/school_logos/MT.png'), 4, 14), - ]; + final int sport_id; + final String sport_name; + + Standing(List args) + : sport_id = args[0], + sport_name = args[1]; @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - centerTitle: false, - title: Text("49ers"), - backgroundColor: Colors.green, - ), - body: SingleChildScrollView( - child: Column( + return StatefulBuilder( + builder: (context, StateSetter setState) => Scaffold( + appBar: AppBar( + centerTitle: false, + title: Text("$sport_name Standings"), + backgroundColor: Colors.green, + ), + body: ListView( children: [ - Container( - child: Text( - "W L", - style: TextStyle(fontWeight: FontWeight.bold), - ), - alignment: Alignment(.85, 0), - height: 20, - color: Colors.grey, - ), - SportLine( - s: _schools[0], - position: 1, - ), - SportLine( - s: _schools[1], - position: 2, - ), - SportLine( - s: _schools[2], - position: 3, - ), - SportLine( - s: _schools[3], - position: 4, - ), - SportLine( - s: _schools[4], - position: 5, - ), - SportLine( - s: _schools[5], - position: 6, - ), - SportLine( - s: _schools[6], - position: 7, - ), - SportLine( - s: _schools[7], - position: 8, - ), - SportLine( - s: _schools[8], - position: 9, - ), - SportLine( - s: _schools[9], - position: 10, - ), - SportLine( - s: _schools[10], - position: 11, - ), - SportLine( - s: _schools[11], - position: 12, - ),SportLine( - s: _schools[12], - position: 13, - ),SportLine( - s: _schools[13], - position: 14, - ), + HorizontalStandings(sportName: sport_name,), ], ), + drawer: Drawer( + child: ListView( + children: [ + DrawerHeader( + child: Text( + 'Drawer Header', + style: TextStyle( + color: Colors.white, + fontSize: 24, + ), + ), + decoration: BoxDecoration( + color: Colors.green, + ), + ), + ListTile( + title: IconButton( + icon: Icon(Icons.home), + onPressed: () => Navigator.pushNamed(context, '/'), + ), + ), + ], + ), + ), ), ); } } - -class SportLine extends StatelessWidget { - const SportLine({ - Key key, - @required - this.position, - this.s - }) : super(key: key); - - final School s; - final int position; - @override - Widget build(BuildContext context) { - int w = s.win; - int l = s.loss; - return Container( - color: evenOdd(position), - height: 60, - child: Row( - children: [ - Container( - height: 55, - width: 20, - //color: Colors.orange, - child: Center( - child: Text( - "$position", - style: TextStyle(fontWeight: FontWeight.bold), - )), - ), - Container( - //color: Colors.blue, - width: 55, - child: Image( - image: s.logo, - ), - ), - Container( - width: 5, - //color: Colors.red, - ), - Container( - //color: Colors.pinkAccent, - width: 220, - child: Text(s.name), - ), - Container( - //color: Colors.orange, - width: 35, - child: Text( - "$w", - style: TextStyle(fontWeight: FontWeight.bold), - )), - Container( - //color: Colors.blue, - width: 35, - child: Text( - " $l", - style: TextStyle(fontWeight: FontWeight.bold), - )) - ], - ) - ); - } - - Color evenOdd(int i) { - Color c = i % 2 == 0 ? Colors.black12 : Colors.white30; - return c; - } -} diff --git a/lib/team_standings.dart b/lib/team_standings.dart new file mode 100644 index 0000000..ad18b70 --- /dev/null +++ b/lib/team_standings.dart @@ -0,0 +1,122 @@ +import 'dart:convert'; + +import 'package:flutter/material.dart'; +import 'package:http/http.dart' as http; + +import 'screens/sport.dart'; + +class HorizontalStandings extends StatelessWidget { + static final standingsUrls = { + "football": [ + "https://site.web.api.espn.com/apis/v2/sports/football/college-football/standings?region=us&lang=en&contentorigin=espn&group=12&sort=leaguewinpercent%3Adesc%2Cvsconf_wins%3Adesc%2Cvsconf_gamesbehind%3Aasc%2Cvsconf_playoffseed%3Aasc%2Cwins%3Adesc%2Closses%3Adesc%2Cplayoffseed%3Aasc%2Calpha%3Aasc", + ], + "basketball": [ + "https://site.web.api.espn.com/apis/v2/sports/basketball/mens-college-basketball/standings?region=us&lang=en&contentorigin=espn&group=11&sort=leaguewinpercent%3Adesc%2Cvsconf_wins%3Adesc%2Cvsconf_gamesbehind%3Aasc%2Cvsconf_playoffseed%3Aasc%2Cwins%3Adesc%2Closses%3Adesc%2Cplayoffseed%3Aasc%2Calpha%3Aasc", + "https://site.web.api.espn.com/apis/v2/sports/basketball/womens-college-basketball/standings?region=us&lang=en&contentorigin=espn&group=11&sort=leaguewinpercent%3Adesc%2Cvsconf_wins%3Adesc%2Cvsconf_gamesbehind%3Aasc%2Cvsconf_playoffseed%3Aasc%2Cwins%3Adesc%2Closses%3Adesc%2Cplayoffseed%3Aasc%2Calpha%3Aasc", + ], + }; + + final String sportName; + + const HorizontalStandings({Key key, this.sportName}) : super(key: key); + + Future getStandingsTable(String url) async { + var response = await http.get(url); + var body = json.decode(response.body); + if (body['children'].length == 0) body['children'] = [body]; + + var res = Center( + child: Column( + children: [ + Text( + "${body['name']}", + style: TextStyle(fontSize: 24), + ), + Column( + children: body['children'] + .map((conference) { + var teams = conference['standings']['entries'].map((team) { + var stats = {}; + for (var stat in team['stats']) { + stats[stat['name']] = stat; + } + + var source = team; + + return {'stats': stats, 'source': source}; + }).toList(); + + var interested = { + 'football': ['vsConf', 'streak'], + 'basketball': ['Season','streak'] + }[sportName.toLowerCase()]; + + var table = Table( + defaultVerticalAlignment: + TableCellVerticalAlignment.middle, + children: teams + .map((data) { + var stats = data['stats']; + var team = data['source']; + + var row = interested + .map((e) => stats[e]) + .where((e) => e != null) + .map((s) => Text("${s['displayValue']}")) + .cast() + .toList(); + + row.insert(0, Text(team['team']['name'])); + row.insert( + 0, + Image.network(team['team']['logos'][0]['href'], + height: 40)); + + return TableRow(children: row); + }) + .cast() + .toList(), + ); + + return Column( + children: [ + Text( + conference['shortName'], + style: TextStyle(fontSize: 16), + ), + table, + ], + ); + }) + .cast() + .toList()), + ], + ), + ); + + return res; + } + + @override + Widget build(BuildContext context) { + var sportUrl = standingsUrls[sportName.toLowerCase()]; + var idx = (Sport.genderSportSwitch && Sport.genderSport) ? 1 : 0; + var url = sportUrl[idx]; + + return Center( + child: Column( + children: [ + FutureBuilder( + future: getStandingsTable(url), + builder: (context, snapshot) { + if (snapshot.hasError) return Text(snapshot.error.toString()); + if (!snapshot.hasData) return CircularProgressIndicator(); + + return snapshot.data; + }, + ) + ], + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 7fc9f02..b39c496 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -259,6 +259,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.2.3" + table_sticky_headers: + dependency: "direct main" + description: + name: table_sticky_headers + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.2" term_glyph: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 323c7ae..8177a56 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,6 +29,7 @@ dependencies: # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.2 table_calendar: + table_sticky_headers: dev_dependencies: flutter_test: