2023-06-17 21:50:52 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
2024-03-06 22:34:15 +00:00
|
|
|
import 'package:tetra_stats/data_objects/tetrio.dart';
|
2023-07-15 16:22:25 +00:00
|
|
|
import 'package:tetra_stats/gen/strings.g.dart';
|
2024-03-24 16:38:06 +00:00
|
|
|
import 'package:tetra_stats/utils/colors_functions.dart';
|
2024-03-06 22:34:15 +00:00
|
|
|
import 'package:tetra_stats/utils/numers_formats.dart';
|
2023-06-17 21:50:52 +00:00
|
|
|
|
|
|
|
class StatCellNum extends StatelessWidget {
|
2023-06-27 20:55:59 +00:00
|
|
|
const StatCellNum(
|
|
|
|
{super.key,
|
|
|
|
required this.playerStat,
|
|
|
|
required this.playerStatLabel,
|
|
|
|
required this.isScreenBig,
|
2024-07-29 20:58:17 +00:00
|
|
|
this.smallDecimal = false,
|
2023-06-27 20:55:59 +00:00
|
|
|
this.alertWidgets,
|
2023-07-12 15:14:25 +00:00
|
|
|
this.fractionDigits,
|
|
|
|
this.oldPlayerStat,
|
|
|
|
required this.higherIsBetter,
|
2024-03-10 22:34:30 +00:00
|
|
|
this.okText, this.alertTitle, this.pos, this.averageStat});
|
2023-06-17 21:50:52 +00:00
|
|
|
|
|
|
|
final num playerStat;
|
2023-06-28 16:50:40 +00:00
|
|
|
final num? oldPlayerStat;
|
|
|
|
final bool higherIsBetter;
|
2023-06-17 21:50:52 +00:00
|
|
|
final String playerStatLabel;
|
2023-07-12 15:14:25 +00:00
|
|
|
final String? okText;
|
2023-06-17 21:50:52 +00:00
|
|
|
final bool isScreenBig;
|
2024-03-10 22:34:30 +00:00
|
|
|
final bool smallDecimal;
|
2024-01-22 18:00:24 +00:00
|
|
|
final String? alertTitle;
|
2023-06-27 20:55:59 +00:00
|
|
|
final List<Widget>? alertWidgets;
|
2023-06-17 21:50:52 +00:00
|
|
|
final int? fractionDigits;
|
2024-03-06 22:34:15 +00:00
|
|
|
final LeaderboardPosition? pos;
|
2024-03-10 22:34:30 +00:00
|
|
|
final num? averageStat;
|
|
|
|
|
|
|
|
Color getStatColor(){
|
|
|
|
if (averageStat == null) return Colors.white;
|
|
|
|
num percentile = (higherIsBetter ? playerStat / averageStat! : averageStat! / playerStat).abs();
|
2024-03-17 23:15:44 +00:00
|
|
|
if (percentile > 1.50) return Colors.purpleAccent;
|
|
|
|
if (percentile > 1.20) return Colors.blueAccent;
|
|
|
|
if (percentile > 0.90) return Colors.greenAccent;
|
|
|
|
if (percentile > 0.70) return Colors.yellowAccent;
|
|
|
|
return Colors.redAccent;
|
2024-03-10 22:34:30 +00:00
|
|
|
}
|
2023-06-17 21:50:52 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-06-16 13:25:16 +00:00
|
|
|
NumberFormat f = NumberFormat.decimalPatternDigits(locale: LocaleSettings.currentLocale.languageCode, decimalDigits: fractionDigits ?? 0);
|
2024-01-01 17:26:09 +00:00
|
|
|
NumberFormat comparef = NumberFormat("+#,###.###;-#,###.###")..maximumFractionDigits = fractionDigits ?? 0;
|
2024-06-16 13:25:16 +00:00
|
|
|
String formated = f.format(playerStat);
|
|
|
|
List<String> splited = formated.split(f.symbols.DECIMAL_SEP);
|
2023-06-17 21:50:52 +00:00
|
|
|
return Column(
|
|
|
|
children: [
|
2024-01-01 17:26:09 +00:00
|
|
|
RichText(
|
2024-06-16 13:25:16 +00:00
|
|
|
text: TextSpan(text: splited[0],
|
2024-01-01 17:26:09 +00:00
|
|
|
children: [
|
2024-07-31 21:50:15 +00:00
|
|
|
if ((fractionDigits??0) > 0 && splited.elementAtOrNull(1) != null) TextSpan(text: f.symbols.DECIMAL_SEP+splited[1], style: smallDecimal ? const TextStyle(fontFamily: "Eurostile Round", fontSize: 16) : null)
|
2024-01-01 17:26:09 +00:00
|
|
|
],
|
2023-06-17 21:50:52 +00:00
|
|
|
style: TextStyle(
|
|
|
|
fontFamily: "Eurostile Round Extended",
|
|
|
|
fontSize: isScreenBig ? 32 : 24,
|
2024-03-10 22:34:30 +00:00
|
|
|
color: getStatColor()
|
2024-01-01 17:26:09 +00:00
|
|
|
)
|
|
|
|
)
|
2023-06-17 21:50:52 +00:00
|
|
|
),
|
2024-03-06 22:34:15 +00:00
|
|
|
if (oldPlayerStat != null || pos != null) RichText(text: TextSpan(
|
|
|
|
text: "",
|
|
|
|
style: const TextStyle(fontFamily: "Eurostile Round", fontSize: 14, color: Colors.grey),
|
|
|
|
children: [
|
|
|
|
if (oldPlayerStat != null) TextSpan(text: comparef.format(playerStat - oldPlayerStat!), style: TextStyle(
|
|
|
|
color: higherIsBetter ?
|
|
|
|
oldPlayerStat! > playerStat ? Colors.redAccent : Colors.greenAccent :
|
|
|
|
oldPlayerStat! < playerStat ? Colors.redAccent : Colors.greenAccent
|
|
|
|
),),
|
|
|
|
if (oldPlayerStat != null && pos != null) const TextSpan(text: " • "),
|
2024-03-24 16:38:06 +00:00
|
|
|
if (pos != null) TextSpan(text: pos!.position >= 1000 ? "${t.top} ${f2.format(pos!.percentage*100)}%" : "№${pos!.position}", style: TextStyle(color: getColorOfRank(pos!.position)))
|
2024-03-06 22:34:15 +00:00
|
|
|
]
|
|
|
|
),
|
|
|
|
),
|
2023-06-27 20:55:59 +00:00
|
|
|
alertWidgets == null
|
2023-06-17 21:50:52 +00:00
|
|
|
? Text(
|
|
|
|
playerStatLabel,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontFamily: "Eurostile Round",
|
|
|
|
fontSize: 16,
|
2023-09-03 18:25:59 +00:00
|
|
|
height: 1.1
|
2023-06-17 21:50:52 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
: TextButton(
|
|
|
|
onPressed: () {
|
2023-06-27 20:55:59 +00:00
|
|
|
showDialog(
|
2024-08-08 23:01:46 +00:00
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) => AlertDialog(
|
|
|
|
title: Text(alertTitle??playerStatLabel.replaceAll(RegExp(r'\n'), " "),
|
|
|
|
style: const TextStyle(
|
|
|
|
fontFamily: "Eurostile Round Extended")),
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: ListBody(children: alertWidgets!),
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
TextButton(
|
|
|
|
child: Text(okText??"OK"),
|
|
|
|
onPressed: () {Navigator.of(context).pop();}
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
2024-01-01 17:26:09 +00:00
|
|
|
);
|
2023-06-17 21:50:52 +00:00
|
|
|
},
|
2023-06-27 20:55:59 +00:00
|
|
|
style: ButtonStyle(
|
2024-08-03 17:52:20 +00:00
|
|
|
padding: WidgetStateProperty.all(EdgeInsets.zero)),
|
2023-06-17 21:50:52 +00:00
|
|
|
child: Text(
|
|
|
|
playerStatLabel,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontFamily: "Eurostile Round",
|
|
|
|
fontSize: 16,
|
2023-09-03 18:25:59 +00:00
|
|
|
height: 1.1
|
2023-06-17 21:50:52 +00:00
|
|
|
),
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|