Skip to content

Commit

Permalink
Add next target
Browse files Browse the repository at this point in the history
  • Loading branch information
waldeck-dev committed Oct 29, 2022
1 parent 1a87cef commit 2324336
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions flutter/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
late Map<String, dynamic> _save;
List<List<Result>> _rankedResults = [[]];
int _nextRemarkableNumbers = 0;

void _loadSave(Map<String, dynamic> newSave) {
setState(() {
Expand All @@ -56,6 +57,7 @@ class _MyHomePageState extends State<MyHomePage> {
saveMgr.fetch().then((response) {
_loadSave(jsonDecode(response.body));
getRankedResults(_save);
getNextRemarkableNumber(_save);
});
}

Expand All @@ -77,12 +79,23 @@ class _MyHomePageState extends State<MyHomePage> {
children: [
Padding(
padding: const EdgeInsets.only(top: 48.0),
child: Text(
'#PR Cup',
style: GoogleFonts.racingSansOne(
color: fontColor,
fontSize: 64,
shadows: [Shadow(color: shadowColor, blurRadius: 8)]),
child: Column(
children: [
Text(
'#PR Cup',
style: GoogleFonts.racingSansOne(
color: fontColor,
fontSize: 64,
shadows: [Shadow(color: shadowColor, blurRadius: 8)]),
),
Text(
"Next target: #${_nextRemarkableNumbers.toString()}",
style: GoogleFonts.spaceGrotesk(
color: fontColor,
fontSize: 16,
shadows: [Shadow(color: shadowColor, blurRadius: 8)]),
)
],
),
),
SizedBox(height: offsetH),
Expand Down Expand Up @@ -159,4 +172,22 @@ class _MyHomePageState extends State<MyHomePage> {
_rankedResults = rankedResults;
});
}

getNextRemarkableNumber(save) {
final allNumbers = save['remarkable_numbers']..sort();

final scoredNumbers = save['results'].map((r) => r['number']).toList()
..sort();

final latestNumber = scoredNumbers.last;
final latestNumberIndex = allNumbers.indexOf(latestNumber);

final nextRemarkableNumbers = latestNumberIndex + 1 < allNumbers.length
? allNumbers[latestNumberIndex + 1]
: -1;

setState(() {
_nextRemarkableNumbers = nextRemarkableNumbers;
});
}
}

0 comments on commit 2324336

Please sign in to comment.