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';
|
2024-09-05 21:42:21 +00:00
|
|
|
import 'package:tetra_stats/data_objects/cutoff_tetrio.dart';
|
|
|
|
import 'package:tetra_stats/data_objects/tetrio_constants.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';
|
2024-08-17 23:39:20 +00:00
|
|
|
import 'package:tetra_stats/utils/text_shadow.dart';
|
|
|
|
import 'package:tetra_stats/widgets/text_timestamp.dart';
|
2023-10-09 18:48:50 +00:00
|
|
|
import 'package:window_manager/window_manager.dart';
|
2024-06-03 23:42:44 +00:00
|
|
|
import 'package:tetra_stats/main.dart' show teto;
|
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> {
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
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(
|
2024-08-24 14:41:07 +00:00
|
|
|
child: FutureBuilder<CutoffsTetrio?>(future: teto.fetchCutoffsTetrio(), builder: (context, snapshot){
|
2024-08-17 23:39:20 +00:00
|
|
|
switch (snapshot.connectionState) {
|
|
|
|
case ConnectionState.none:
|
|
|
|
case ConnectionState.waiting:
|
|
|
|
case ConnectionState.active:
|
|
|
|
return const Center(child: CircularProgressIndicator(color: Colors.white));
|
|
|
|
case ConnectionState.done:
|
|
|
|
if (snapshot.hasData){
|
|
|
|
return Container(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
child: Container(
|
|
|
|
alignment: Alignment.center,
|
2024-08-24 14:41:07 +00:00
|
|
|
width: 900,
|
2024-08-17 23:39:20 +00:00
|
|
|
child: SingleChildScrollView(
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Table(
|
|
|
|
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
|
|
|
|
border: TableBorder.all(color: Colors.grey.shade900),
|
2024-08-24 14:41:07 +00:00
|
|
|
columnWidths: const {
|
|
|
|
0: FixedColumnWidth(48),
|
|
|
|
1: FixedColumnWidth(155),
|
|
|
|
2: FixedColumnWidth(150),
|
|
|
|
3: FixedColumnWidth(90),
|
|
|
|
4: FixedColumnWidth(130),
|
|
|
|
},
|
2024-08-17 23:39:20 +00:00
|
|
|
children: [
|
|
|
|
TableRow(
|
|
|
|
children: [
|
|
|
|
Text(t.rank, textAlign: TextAlign.center, style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white)),
|
2024-08-24 14:41:07 +00:00
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.only(right: 8.0),
|
|
|
|
child: Text("TR", textAlign: TextAlign.right, style: TextStyle(fontFamily: "Eurostile Round", fontSize: 28, fontWeight: FontWeight.w500, color: Colors.white)),
|
2024-08-17 23:39:20 +00:00
|
|
|
),
|
2024-08-24 14:41:07 +00:00
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.only(right: 8.0),
|
|
|
|
child: Text("APM", textAlign: TextAlign.right, style: TextStyle(fontFamily: "Eurostile Round", fontSize: 28, fontWeight: FontWeight.w500, color: Colors.white)),
|
2024-08-17 23:39:20 +00:00
|
|
|
),
|
2024-08-24 14:41:07 +00:00
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.only(right: 8.0),
|
|
|
|
child: Text("PPS", textAlign: TextAlign.right, style: TextStyle(fontFamily: "Eurostile Round", fontSize: 28, fontWeight: FontWeight.w500, color: Colors.white)),
|
|
|
|
),
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.only(right: 8.0),
|
|
|
|
child: Text("VS", textAlign: TextAlign.right, style: TextStyle(fontFamily: "Eurostile Round", fontSize: 28, fontWeight: FontWeight.w500, color: Colors.white)),
|
|
|
|
),
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.only(right: 8.0),
|
|
|
|
child: Text("Advanced", textAlign: TextAlign.right, style: TextStyle(fontFamily: "Eurostile Round", fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white)),
|
2024-08-17 23:39:20 +00:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
2024-08-24 14:41:07 +00:00
|
|
|
child: Text("Players (${intf.format(snapshot.data!.total)})", textAlign: TextAlign.right, style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white)),
|
2024-08-17 23:39:20 +00:00
|
|
|
),
|
|
|
|
]
|
|
|
|
),
|
2024-08-24 14:41:07 +00:00
|
|
|
for (String rank in snapshot.data!.data.keys) TableRow(
|
|
|
|
decoration: BoxDecoration(gradient: LinearGradient(colors: [rankColors[rank]!.withAlpha(200), rankColors[rank]!.withAlpha(100)])),
|
2024-08-17 23:39:20 +00:00
|
|
|
children: [
|
|
|
|
Container(decoration: BoxDecoration(boxShadow: [BoxShadow(color: Colors.black.withAlpha(132), blurRadius: 32.0, blurStyle: BlurStyle.inner)]), child: Image.asset("res/tetrio_tl_alpha_ranks/$rank.png", height: 48)),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
2024-08-24 14:41:07 +00:00
|
|
|
child: Text(f2.format(snapshot.data!.data[rank]!.tr), textAlign: TextAlign.right, style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 28, fontWeight: FontWeight.w500, color: Colors.white, shadows: textShadow)),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
2024-09-16 22:37:25 +00:00
|
|
|
child: Text(snapshot.data?.data[rank]?.apm != null ? f2.format(snapshot.data!.data[rank]!.apm) : "-.--", textAlign: TextAlign.right, style: TextStyle(fontFamily: "Eurostile Round", fontSize: 28, fontWeight: FontWeight.w100, color: snapshot.data?.data[rank]?.apm != null ? Colors.white : Colors.grey, shadows: textShadow)),
|
2024-08-24 14:41:07 +00:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
2024-09-16 22:37:25 +00:00
|
|
|
child: Text(snapshot.data?.data[rank]?.pps != null ? f2.format(snapshot.data!.data[rank]!.pps) : "-.--", textAlign: TextAlign.right, style: TextStyle(fontFamily: "Eurostile Round", fontSize: 28, fontWeight: FontWeight.w100, color: snapshot.data?.data[rank]?.pps != null ? Colors.white : Colors.grey, shadows: textShadow)),
|
2024-08-17 23:39:20 +00:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
2024-09-16 22:37:25 +00:00
|
|
|
child: Text(snapshot.data?.data[rank]?.vs != null ? f2.format(snapshot.data!.data[rank]!.vs) : "-.--", textAlign: TextAlign.right, style: TextStyle(fontFamily: "Eurostile Round", fontSize: 28, fontWeight: FontWeight.w100, color: snapshot.data?.data[rank]?.vs != null ? Colors.white : Colors.grey, shadows: textShadow)),
|
2024-08-17 23:39:20 +00:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
2024-09-16 22:37:25 +00:00
|
|
|
child: Text("${snapshot.data?.data[rank]?.apm != null && snapshot.data?.data[rank]?.pps != null ? f3.format(snapshot.data!.data[rank]!.apm! / (snapshot.data!.data[rank]!.pps! * 60)) : "-.---"} APP\n${snapshot.data?.data[rank]?.apm != null && snapshot.data?.data[rank]?.vs != null ? f3.format(snapshot.data!.data[rank]!.vs! / snapshot.data!.data[rank]!.apm!) : "-.---"} VS/APM", textAlign: TextAlign.right, style: TextStyle(fontFamily: "Eurostile Round", fontSize: 14, fontWeight: FontWeight.w100, color: snapshot.data?.data[rank]?.apm != null && snapshot.data?.data[rank]?.pps != null && snapshot.data?.data[rank]?.vs != null ? Colors.white : Colors.grey, shadows: textShadow)),
|
2024-08-17 23:39:20 +00:00
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(right: 8.0),
|
2024-08-24 14:41:07 +00:00
|
|
|
child: RichText(
|
|
|
|
textAlign: TextAlign.right,
|
|
|
|
text: TextSpan(
|
|
|
|
style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 14, fontWeight: FontWeight.w100, color: Colors.white, shadows: textShadow),
|
|
|
|
children: [
|
|
|
|
TextSpan(text: intf.format(snapshot.data!.data[rank]!.count)),
|
|
|
|
TextSpan(text: " (${f2.format(snapshot.data!.data[rank]!.countPercentile * 100)}%)", style: const TextStyle(color: Colors.white60, shadows: null)),
|
|
|
|
TextSpan(text: "\n(from № ${intf.format(snapshot.data!.data[rank]!.pos)})", style: const TextStyle(color: Colors.white60, shadows: null))
|
|
|
|
]
|
|
|
|
))
|
2024-08-17 23:39:20 +00:00
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2024-08-24 14:41:07 +00:00
|
|
|
Text(t.sprintAndBlitsRelevance(date: timestamp(snapshot.data!.timestamp)))
|
2024-08-17 23:39:20 +00:00
|
|
|
],
|
2023-07-29 18:01:49 +00:00
|
|
|
),
|
2024-08-17 23:39:20 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-07-29 18:01:49 +00:00
|
|
|
);
|
2024-08-17 23:39:20 +00:00
|
|
|
}
|
|
|
|
if (snapshot.hasError){
|
|
|
|
return Center(child:
|
|
|
|
Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Text(snapshot.error.toString(), style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 42, fontWeight: FontWeight.bold), textAlign: TextAlign.center),
|
|
|
|
if (snapshot.stackTrace != null) Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8.0),
|
|
|
|
child: Text(snapshot.stackTrace.toString(), style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 18), textAlign: TextAlign.center),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return const Text("end of FutureBuilder");
|
|
|
|
}
|
|
|
|
})
|
|
|
|
),
|
2023-07-09 16:50:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|