2023-07-07 20:32:57 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
2023-07-15 16:22:25 +00:00
|
|
|
import 'package:tetra_stats/gen/strings.g.dart';
|
2023-07-07 20:32:57 +00:00
|
|
|
import 'package:tetra_stats/services/tetrio_crud.dart';
|
2023-07-09 16:50:17 +00:00
|
|
|
import 'package:tetra_stats/views/main_view.dart';
|
|
|
|
import 'package:tetra_stats/views/ranks_averages_view.dart';
|
2023-07-07 20:32:57 +00:00
|
|
|
|
|
|
|
final TetrioService teto = TetrioService();
|
|
|
|
|
|
|
|
class TLLeaderboardView extends StatefulWidget {
|
|
|
|
const TLLeaderboardView({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => TLLeaderboardState();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class TLLeaderboardState extends State<TLLeaderboardView> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-07-15 16:22:25 +00:00
|
|
|
final t = Translations.of(context);
|
|
|
|
final NumberFormat f2 = NumberFormat.decimalPattern(LocaleSettings.currentLocale.languageCode)..maximumFractionDigits = 2;
|
2023-07-07 20:32:57 +00:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2023-07-15 16:22:25 +00:00
|
|
|
title: Text(t.tlLeaderboard),
|
2023-07-09 16:50:17 +00:00
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => const RankAveragesView(),
|
|
|
|
maintainState: false,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.compress),
|
2023-07-15 16:22:25 +00:00
|
|
|
tooltip: t.averages,
|
2023-07-09 16:50:17 +00:00
|
|
|
),
|
|
|
|
],
|
2023-07-07 20:32:57 +00:00
|
|
|
),
|
|
|
|
backgroundColor: Colors.black,
|
|
|
|
body: SafeArea(
|
|
|
|
child: FutureBuilder(
|
|
|
|
future: teto.fetchTLLeaderboard(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
switch (snapshot.connectionState) {
|
|
|
|
case ConnectionState.none:
|
|
|
|
case ConnectionState.waiting:
|
|
|
|
case ConnectionState.active:
|
|
|
|
return const Center(child: Text('Fetching...'));
|
|
|
|
case ConnectionState.done:
|
|
|
|
final allPlayers = snapshot.data?.leaderboard;
|
|
|
|
return NestedScrollView(
|
|
|
|
headerSliverBuilder: (context, value) {
|
|
|
|
String howManyPlayers(int numberOfPlayers) => Intl.plural(
|
|
|
|
numberOfPlayers,
|
2023-07-15 16:22:25 +00:00
|
|
|
zero: t.lbViewZeroEntrys,
|
|
|
|
one: t.lbViewOneEntry,
|
|
|
|
other: t.lbViewManyEntrys(numberOfPlayers: numberOfPlayers),
|
2023-07-07 20:32:57 +00:00
|
|
|
name: 'howManyPeople',
|
|
|
|
args: [numberOfPlayers],
|
|
|
|
desc: 'Description of how many people are seen in a place.',
|
|
|
|
examples: const {'numberOfPeople': 3},
|
|
|
|
);
|
|
|
|
return [
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(left: 16),
|
|
|
|
child: Text(
|
|
|
|
howManyPlayers(allPlayers.length),
|
|
|
|
style: const TextStyle(color: Colors.white, fontSize: 25),
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
const SliverToBoxAdapter(child: Divider())
|
|
|
|
];
|
|
|
|
},
|
|
|
|
body: ListView.builder(
|
|
|
|
itemCount: allPlayers!.length,
|
|
|
|
itemBuilder: (context, index) {
|
2023-07-09 16:50:17 +00:00
|
|
|
bool bigScreen = MediaQuery.of(context).size.width > 768;
|
2023-07-07 20:32:57 +00:00
|
|
|
return ListTile(
|
2023-07-09 16:50:17 +00:00
|
|
|
leading: Text((index+1).toString(), style: bigScreen ? const TextStyle(fontFamily: "Eurostile Round Extended", fontSize: 28) : null),
|
|
|
|
title: Text(allPlayers[index].username, style: const TextStyle(fontFamily: "Eurostile Round Extended")),
|
2023-07-07 20:32:57 +00:00
|
|
|
subtitle: Text(
|
|
|
|
"${f2.format(allPlayers[index].apm)} APM, ${f2.format(allPlayers[index].pps)} PPS, ${f2.format(allPlayers[index].vs)} VS, ${f2.format(allPlayers[index].app)} APP, ${f2.format(allPlayers[index].vsapm)} VS/APM"),
|
|
|
|
trailing: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2023-07-09 16:50:17 +00:00
|
|
|
Text("${f2.format(allPlayers[index].rating)} TR", style: bigScreen ? const TextStyle(fontSize: 28) : null),
|
|
|
|
Image.asset("res/tetrio_tl_alpha_ranks/${allPlayers[index].rank}.png", height: bigScreen ? 48 : 16),
|
2023-07-07 20:32:57 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
onTap: () {
|
2023-07-09 16:50:17 +00:00
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => MainView(player: allPlayers[index].userId),
|
|
|
|
maintainState: false,
|
|
|
|
),
|
|
|
|
);
|
2023-07-07 20:32:57 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
})),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|