Minor version bump, add rank icons and leaderboard sorting
|
@ -3,6 +3,7 @@ analyzer:
|
||||||
errors:
|
errors:
|
||||||
library_private_types_in_public_api: ignore
|
library_private_types_in_public_api: ignore
|
||||||
prefer_const_constructors: ignore
|
prefer_const_constructors: ignore
|
||||||
|
prefer_const_literals_to_create_immutables: ignore
|
||||||
prefer_final_fields: ignore
|
prefer_final_fields: ignore
|
||||||
use_build_context_synchronously: ignore
|
use_build_context_synchronously: ignore
|
||||||
use_key_in_widget_constructors: ignore
|
use_key_in_widget_constructors: ignore
|
||||||
|
|
BIN
assets/A.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
assets/B.png
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
assets/C.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
assets/D.png
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
assets/E.png
Normal file
After Width: | Height: | Size: 6.6 KiB |
BIN
assets/S.png
Normal file
After Width: | Height: | Size: 6.6 KiB |
BIN
assets/SS.png
Normal file
After Width: | Height: | Size: 9.6 KiB |
BIN
assets/infdan.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
assets/none.png
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/player_0.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
assets/player_0_dp.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
assets/player_1.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
assets/player_1_dp.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
assets/player_2.png
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
assets/player_2_dp.png
Normal file
After Width: | Height: | Size: 16 KiB |
|
@ -11,6 +11,7 @@ class LeaderboardPage extends StatefulWidget {
|
||||||
class _LeaderboardPageState extends State<LeaderboardPage> {
|
class _LeaderboardPageState extends State<LeaderboardPage> {
|
||||||
List<dynamic> _leaderboard = [];
|
List<dynamic> _leaderboard = [];
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
|
bool _sortByOskMu = false;
|
||||||
|
|
||||||
final String _leaderboardApi = '$apiurl/leaderboards';
|
final String _leaderboardApi = '$apiurl/leaderboards';
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ class _LeaderboardPageState extends State<LeaderboardPage> {
|
||||||
List<dynamic> data = json.decode(response.body);
|
List<dynamic> data = json.decode(response.body);
|
||||||
setState(() {
|
setState(() {
|
||||||
_leaderboard = data;
|
_leaderboard = data;
|
||||||
|
_sortLeaderboard();
|
||||||
_isLoading = false;
|
_isLoading = false;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -42,6 +44,23 @@ class _LeaderboardPageState extends State<LeaderboardPage> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _sortLeaderboard() {
|
||||||
|
setState(() {
|
||||||
|
if (_sortByOskMu) {
|
||||||
|
_leaderboard.sort((a, b) => b['osk_mu'].compareTo(a['osk_mu']));
|
||||||
|
} else {
|
||||||
|
_leaderboard.sort((a, b) => b['elo_rating'].compareTo(a['elo_rating']));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _toggleSort() {
|
||||||
|
setState(() {
|
||||||
|
_sortByOskMu = !_sortByOskMu;
|
||||||
|
_sortLeaderboard();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void _showError(String message) {
|
void _showError(String message) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
@ -69,6 +88,16 @@ class _LeaderboardPageState extends State<LeaderboardPage> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text('Leaderboard'),
|
||||||
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.sort),
|
||||||
|
onPressed: _toggleSort,
|
||||||
|
tooltip: _sortByOskMu ? 'Sort by Elo' : 'Sort by Osk_Mu',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
body: _isLoading
|
body: _isLoading
|
||||||
? Center(child: CircularProgressIndicator())
|
? Center(child: CircularProgressIndicator())
|
||||||
: RefreshIndicator(
|
: RefreshIndicator(
|
||||||
|
@ -77,16 +106,28 @@ class _LeaderboardPageState extends State<LeaderboardPage> {
|
||||||
itemCount: _leaderboard.length,
|
itemCount: _leaderboard.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
var player = _leaderboard[index];
|
var player = _leaderboard[index];
|
||||||
|
String truncatedOskMu = player['osk_mu'].toStringAsFixed(3);
|
||||||
|
|
||||||
|
String assetName = _sortByOskMu
|
||||||
|
? 'assets/player_${index}_dp.png'
|
||||||
|
: 'assets/player_${index}.png';
|
||||||
|
|
||||||
return Card(
|
return Card(
|
||||||
margin: EdgeInsets.all(8),
|
margin: EdgeInsets.all(8),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
contentPadding: EdgeInsets.all(10),
|
contentPadding: EdgeInsets.all(10),
|
||||||
leading: CircleAvatar(
|
leading: CircleAvatar(
|
||||||
child: Text(player['player_name'][0].toUpperCase()),
|
child: Text(player['player_name'][0].toUpperCase())),
|
||||||
|
title: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(player['player_name']),
|
||||||
|
if (index < 3)
|
||||||
|
Image.asset(assetName, width: 45, height: 45),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
title: Text(player['player_name']),
|
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
'Elo: ${player['elo_rating']} | TSC: ${player['osk_mu']}'),
|
'Elo: ${player['elo_rating']} | TSC: $truncatedOskMu'),
|
||||||
trailing: Text('UID: ${player['friend_code']}'),
|
trailing: Text('UID: ${player['friend_code']}'),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -79,14 +79,15 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
String getRankImage(int? elo) {
|
String getRankImage(int? elo) {
|
||||||
if (elo == null) return '$apiurl/assets/none.png';
|
if (elo == null || elo < -100) return 'assets/none.png';
|
||||||
if (elo > 1000) return '$apiurl/assets/U.png';
|
if (elo >= 120) return 'assets/infdan.png';
|
||||||
if (elo > 750) return '$apiurl/assets/S.png';
|
if (elo >= 90) return 'assets/SS.png';
|
||||||
if (elo > 400) return '$apiurl/assets/A.png';
|
if (elo >= 60) return 'assets/S.png';
|
||||||
if (elo > 200) return '$apiurl/assets/B.png';
|
if (elo >= 30) return 'assets/A.png';
|
||||||
if (elo > 100) return '$apiurl/assets/C.png';
|
if (elo >= 0) return 'assets/B.png';
|
||||||
if (elo > 30) return '$apiurl/assets/D.png';
|
if (elo >= -30) return 'assets/C.png';
|
||||||
return '$apiurl/assets/none.png';
|
if (elo >= -60) return 'assets/D.png';
|
||||||
|
return 'assets/E.png';
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showExplanationDialog() {
|
void _showExplanationDialog() {
|
||||||
|
@ -182,9 +183,7 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||||
),
|
),
|
||||||
radius: 40,
|
radius: 40,
|
||||||
),
|
),
|
||||||
|
|
||||||
SizedBox(width: 16),
|
SizedBox(width: 16),
|
||||||
// Profile Info
|
|
||||||
Column(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
@ -196,7 +195,19 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 6),
|
SizedBox(height: 6),
|
||||||
Text('UID: ${_uid ?? 'N/A'}'),
|
Row(
|
||||||
|
children: [
|
||||||
|
Text('UID: ${_uid ?? 'N/A'}'),
|
||||||
|
SizedBox(
|
||||||
|
width: 30,
|
||||||
|
),
|
||||||
|
Image.asset(
|
||||||
|
getRankImage(_elo),
|
||||||
|
width: 100,
|
||||||
|
height: 30,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
|
@ -210,12 +221,6 @@ class _ProfilePageState extends State<ProfilePage> {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
SizedBox(width: 25),
|
|
||||||
Image.network(
|
|
||||||
getRankImage(_elo),
|
|
||||||
width: 137,
|
|
||||||
height: 137,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -2,7 +2,7 @@ name: pingpongapp
|
||||||
description: "DTH Ping Pong Score tracking app"
|
description: "DTH Ping Pong Score tracking app"
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
|
|
||||||
version: 0.0.55+1
|
version: 0.0.57+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.4.3 <4.0.0'
|
sdk: '>=3.4.3 <4.0.0'
|
||||||
|
@ -27,8 +27,8 @@ flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
|
||||||
# To add assets to your application, add an assets section, like this:
|
# To add assets to your application, add an assets section, like this:
|
||||||
# assets:
|
assets:
|
||||||
# - images/a_dot_ham.jpeg
|
- assets/
|
||||||
|
|
||||||
# An image asset can refer to one or more resolution-specific "variants", see
|
# An image asset can refer to one or more resolution-specific "variants", see
|
||||||
# https://flutter.dev/assets-and-images/#resolution-aware
|
# https://flutter.dev/assets-and-images/#resolution-aware
|
||||||
|
|