diff --git a/lib/views/destination_graphs.dart b/lib/views/destination_graphs.dart index 6073bac..422ca6d 100644 --- a/lib/views/destination_graphs.dart +++ b/lib/views/destination_graphs.dart @@ -10,6 +10,7 @@ import 'package:tetra_stats/gen/strings.g.dart'; import 'package:tetra_stats/main.dart'; import 'package:tetra_stats/services/crud_exceptions.dart'; import 'package:tetra_stats/utils/numers_formats.dart'; +import 'package:tetra_stats/views/destination_home.dart'; import 'package:tetra_stats/views/main_view_tiles.dart'; import 'package:tetra_stats/widgets/text_timestamp.dart'; @@ -132,7 +133,7 @@ class _DestinationGraphsState extends State { super.initState(); } - Future>>> getHistoryData(bool fetchHistory) async { + Future>>> getHistoryData(bool fetchHistory) async { if(fetchHistory){ try{ var history = await teto.fetchAndsaveTLHistory(widget.searchFor); @@ -151,15 +152,12 @@ class _DestinationGraphsState extends State { List> states = await Future.wait>([ teto.getStates(widget.searchFor, season: 1), teto.getStates(widget.searchFor, season: 2), ]); - List>> historyData = []; // [season][metric][spot] + Map>> historyData = {}; // [season][metric][spot] for (int season = 0; season < currentSeason; season++){ if (states[season].length >= 2){ Map> statsMap = {}; for (var stat in Stats.values) statsMap[stat] = [for (var tl in states[season]) if (tl.getStatByEnum(stat) != null) _HistoryChartSpot(tl.timestamp, tl.gamesPlayed, tl.rank, tl.getStatByEnum(stat)!.toDouble())]; - historyData.add(statsMap); - }else{ - historyData.add({}); - break; + historyData[season] = statsMap; } } fetchData = false; @@ -184,7 +182,7 @@ class _DestinationGraphsState extends State { } Widget getHistoryGraph(){ - return FutureBuilder>>>( + return FutureBuilder>>>( future: getHistoryData(fetchData), builder: (context, snapshot) { switch (snapshot.connectionState){ @@ -194,7 +192,8 @@ class _DestinationGraphsState extends State { return const Center(child: CircularProgressIndicator()); case ConnectionState.done: if (snapshot.hasData){ - List<_HistoryChartSpot> selectedGraph = snapshot.data![_season][_Ychart]!; + if (snapshot.data!.isEmpty || !snapshot.data!.containsKey(_season)) return ErrorThingy(eText: "Not enough data"); + List<_HistoryChartSpot> selectedGraph = snapshot.data![_season]![_Ychart]!; yAxisTitle = chartsShortTitles[_Ychart]!; // TODO: this graph can Krash return SfCartesianChart( diff --git a/lib/views/destination_home.dart b/lib/views/destination_home.dart index 9fea795..5c0e183 100644 --- a/lib/views/destination_home.dart +++ b/lib/views/destination_home.dart @@ -980,7 +980,7 @@ class _DestinationHomeState extends State with SingleTickerProv case ConnectionState.done: if (snapshot.hasError){ return FutureError(snapshot); } if (snapshot.hasData){ - if (!snapshot.data!.success) return FetchResultError(snapshot.data!); + if (!snapshot.data!.success) return ErrorThingy(data: snapshot.data!); blitzBetterThanRankAverage = (snapshot.data!.summaries!.league.rank != "z" && snapshot.data!.summaries!.blitz != null && snapshot.data!.summaries!.league.rank != "x+") ? snapshot.data!.summaries!.blitz!.stats.score > blitzAverages[snapshot.data!.summaries!.league.rank]! : null; sprintBetterThanRankAverage = (snapshot.data!.summaries!.league.rank != "z" && snapshot.data!.summaries!.sprint != null && snapshot.data!.summaries!.league.rank != "x+") ? snapshot.data!.summaries!.sprint!.stats.finalTime < sprintAverages[snapshot.data!.summaries!.league.rank]! : null; if (snapshot.data!.summaries!.sprint != null) { diff --git a/lib/views/main_view_tiles.dart b/lib/views/main_view_tiles.dart index c498194..2316ff5 100644 --- a/lib/views/main_view_tiles.dart +++ b/lib/views/main_view_tiles.dart @@ -1385,7 +1385,7 @@ class _NewUserThingyState extends State with SingleTickerProvider label: _addToTrackAnim.value < 0.5 ? Container( transform: Matrix4.translationValues(0, firstButtonPosition, 0), child: Opacity( - opacity: min(1, firstButtonOpacity), + opacity: max(min(1, firstButtonOpacity), 0), child: Text(_addToTrackAnimController.isAnimating && _addToTrackAnim.status == AnimationStatus.forward ? "Done!" : "Track") ) ) : Container( @@ -2169,17 +2169,18 @@ class FutureError extends StatelessWidget{ } } -class FetchResultError extends StatelessWidget{ - final FetchResults data; +class ErrorThingy extends StatelessWidget{ + final FetchResults? data; + final String? eText; - FetchResultError(this.data); + ErrorThingy({this.data, this.eText}); @override Widget build(BuildContext context) { IconData icon = Icons.error_outline; - String errText = ""; + String errText = eText??""; String? subText; - switch (data.exception.runtimeType){ + if (data?.exception != null) switch (data!.exception!.runtimeType){ case TetrioPlayerNotExist: icon = Icons.search_off; errText = t.errors.noSuchUser; @@ -2190,7 +2191,7 @@ class FetchResultError extends StatelessWidget{ errText = t.errors.discordNotAssigned; subText = t.errors.discordNotAssignedSub; case ConnectionIssue: - var err = data.exception as ConnectionIssue; + var err = data!.exception as ConnectionIssue; errText = t.errors.connection(code: err.code, message: err.message); break; case TetrioForbidden: @@ -2214,7 +2215,7 @@ class FetchResultError extends StatelessWidget{ errText = t.errors.clientException; break; default: - errText = data.exception.toString(); + errText = data!.exception.toString(); } return TweenAnimationBuilder( duration: Durations.medium3,