2023-10-09 18:48:50 +00:00
|
|
|
import 'dart:io';
|
2023-10-10 20:20:27 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2023-07-09 16:50:17 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-07-15 16:22:25 +00:00
|
|
|
import 'package:tetra_stats/gen/strings.g.dart';
|
2024-03-06 22:34:15 +00:00
|
|
|
import 'package:tetra_stats/utils/numers_formats.dart';
|
2023-07-29 18:01:49 +00:00
|
|
|
import 'package:tetra_stats/views/rank_averages_view.dart';
|
2023-10-09 18:48:50 +00:00
|
|
|
import 'package:window_manager/window_manager.dart';
|
2023-10-26 22:38:03 +00:00
|
|
|
import 'main_view.dart'; // lol
|
2023-07-09 16:50:17 +00:00
|
|
|
|
|
|
|
class RankAveragesView extends StatefulWidget {
|
2024-01-13 18:49:36 +00:00
|
|
|
const RankAveragesView({super.key});
|
2023-07-09 16:50:17 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => RanksAverages();
|
|
|
|
}
|
|
|
|
|
2023-10-09 18:48:50 +00:00
|
|
|
late String oldWindowTitle;
|
|
|
|
|
2023-07-09 16:50:17 +00:00
|
|
|
class RanksAverages extends State<RankAveragesView> {
|
|
|
|
Map<String, List<dynamic>> averages = {};
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
2023-10-09 18:48:50 +00:00
|
|
|
teto.fetchTLLeaderboard().then((value){
|
|
|
|
averages = value.averages;
|
|
|
|
setState(() {});
|
|
|
|
});
|
2023-10-10 20:20:27 +00:00
|
|
|
if (!kIsWeb && !Platform.isAndroid && !Platform.isIOS){
|
2023-10-09 18:48:50 +00:00
|
|
|
windowManager.getTitle().then((value) => oldWindowTitle = value);
|
|
|
|
windowManager.setTitle("Tetra Stats: ${t.rankAveragesViewTitle}");
|
|
|
|
}
|
2023-07-09 16:50:17 +00:00
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2023-10-09 18:48:50 +00:00
|
|
|
@override
|
|
|
|
void dispose() {
|
2023-10-10 20:20:27 +00:00
|
|
|
if (!kIsWeb && !Platform.isAndroid && !Platform.isIOS) windowManager.setTitle(oldWindowTitle);
|
2023-10-09 18:48:50 +00:00
|
|
|
super.dispose();
|
|
|
|
}
|
2023-07-09 16:50:17 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2023-07-15 16:22:25 +00:00
|
|
|
title: Text(t.rankAveragesViewTitle),
|
2023-07-09 16:50:17 +00:00
|
|
|
),
|
|
|
|
backgroundColor: Colors.black,
|
|
|
|
body: SafeArea(
|
2023-09-04 18:00:13 +00:00
|
|
|
child: averages.isEmpty ? const Center(child: Text('Fetching...')) : ListView.builder(
|
2023-07-09 16:50:17 +00:00
|
|
|
itemCount: averages.length,
|
|
|
|
itemBuilder: (context, index){
|
|
|
|
bool bigScreen = MediaQuery.of(context).size.width > 768;
|
|
|
|
List<String> keys = averages.keys.toList();
|
|
|
|
return ListTile(
|
|
|
|
leading: Image.asset("res/tetrio_tl_alpha_ranks/${keys[index]}.png", height: 48),
|
2023-08-20 21:57:01 +00:00
|
|
|
title: Text(t.players(n: averages[keys[index]]?[1]["players"]), style: const TextStyle(fontFamily: "Eurostile Round Extended")),
|
2024-03-24 16:38:06 +00:00
|
|
|
subtitle: Text("${f2.format(averages[keys[index]]?[0].apm)} APM, ${f2.format(averages[keys[index]]?[0].pps)} PPS, ${f2.format(averages[keys[index]]?[0].vs)} VS, ${f2.format(averages[keys[index]]?[0].nerdStats.app)} APP, ${f2.format(averages[keys[index]]?[0].nerdStats.vsapm)} VS/APM",
|
|
|
|
style: TextStyle(fontFamily: "Eurostile Round Condensed", color: Colors.grey)),
|
2023-07-29 18:01:49 +00:00
|
|
|
trailing: Text("${f2.format(averages[keys[index]]?[1]["toEnterTR"])} TR", style: bigScreen ? const TextStyle(fontSize: 28) : null),
|
|
|
|
onTap: (){
|
2023-09-23 19:09:36 +00:00
|
|
|
if (averages[keys[index]]?[1]["players"] > 0) {
|
|
|
|
Navigator.push(
|
2023-07-29 18:01:49 +00:00
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => RankView(rank: averages[keys[index]]!),
|
|
|
|
),
|
|
|
|
);
|
2023-09-23 19:09:36 +00:00
|
|
|
}
|
2023-07-29 18:01:49 +00:00
|
|
|
},
|
|
|
|
);
|
2023-07-09 16:50:17 +00:00
|
|
|
})
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|