TetraStats/lib/views/ranks_averages_view.dart

75 lines
2.9 KiB
Dart
Raw Normal View History

import 'dart:io';
2023-10-10 20:20:27 +00:00
import 'package:flutter/foundation.dart';
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';
import 'package:tetra_stats/views/rank_averages_view.dart';
import 'package:window_manager/window_manager.dart';
import 'package:tetra_stats/main.dart' show teto;
class RankAveragesView extends StatefulWidget {
const RankAveragesView({super.key});
@override
State<StatefulWidget> createState() => RanksAverages();
}
late String oldWindowTitle;
class RanksAverages extends State<RankAveragesView> {
Map<String, List<dynamic>> averages = {};
@override
void initState() {
teto.fetchTLLeaderboard().then((value){
averages = value.averages;
setState(() {});
});
2023-10-10 20:20:27 +00:00
if (!kIsWeb && !Platform.isAndroid && !Platform.isIOS){
windowManager.getTitle().then((value) => oldWindowTitle = value);
windowManager.setTitle("Tetra Stats: ${t.rankAveragesViewTitle}");
}
super.initState();
}
@override
void dispose() {
2023-10-10 20:20:27 +00:00
if (!kIsWeb && !Platform.isAndroid && !Platform.isIOS) windowManager.setTitle(oldWindowTitle);
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2023-07-15 16:22:25 +00:00
title: Text(t.rankAveragesViewTitle),
),
backgroundColor: Colors.black,
body: SafeArea(
child: averages.isEmpty ? const Center(child: Text('Fetching...')) : ListView.builder(
itemCount: averages.length,
itemBuilder: (context, index){
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",
2024-07-10 15:31:00 +00:00
style: const TextStyle(fontFamily: "Eurostile Round Condensed", color: Colors.grey, fontSize: 13)),
trailing: Text("${f2.format(averages[keys[index]]?[1]["toEnterTR"])} TR", style: const TextStyle(fontSize: 28, fontFamily: "Eurostile Round")),
onTap: (){
if (averages[keys[index]]?[1]["players"] > 0) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => RankView(rank: averages[keys[index]]!),
),
);
}
},
);
})
),
);
}
}