TetraStats/lib/widgets/stat_sell_num.dart

101 lines
4.0 KiB
Dart
Raw Normal View History

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';
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,
this.alertWidgets,
2023-07-12 15:14:25 +00:00
this.fractionDigits,
this.oldPlayerStat,
required this.higherIsBetter,
2024-01-22 18:00:24 +00:00
this.okText, this.alertTitle});
final num playerStat;
2023-06-28 16:50:40 +00:00
final num? oldPlayerStat;
final bool higherIsBetter;
final String playerStatLabel;
2023-07-12 15:14:25 +00:00
final String? okText;
final bool isScreenBig;
2024-01-22 18:00:24 +00:00
final String? alertTitle;
2023-06-27 20:55:59 +00:00
final List<Widget>? alertWidgets;
final int? fractionDigits;
@override
Widget build(BuildContext context) {
NumberFormat comparef = NumberFormat("+#,###.###;-#,###.###")..maximumFractionDigits = fractionDigits ?? 0;
NumberFormat intf = NumberFormat.decimalPatternDigits(locale: LocaleSettings.currentLocale.languageCode, decimalDigits: 0);
NumberFormat fractionf = NumberFormat.decimalPatternDigits(locale: LocaleSettings.currentLocale.languageCode, decimalDigits: fractionDigits ?? 0)..maximumIntegerDigits = 0;
num fraction = playerStat.isNegative ? 1 - (playerStat - playerStat.floor()) : playerStat - playerStat.floor();
int integer = playerStat.isNegative ? (playerStat + fraction).toInt() : (playerStat - fraction).toInt();
// String valueAsString = fractionDigits == null ? f.format(playerStat.floor()) : f.format(playerStat);
// var exploded = valueAsString.split(".");
return Column(
children: [
RichText(
text: TextSpan(text: intf.format(integer),
children: [
TextSpan(text: fractionf.format(fraction).substring(1), style: const TextStyle(fontSize: 16))
],
style: TextStyle(
fontFamily: "Eurostile Round Extended",
//fontWeight: FontWeight.bold,
fontSize: isScreenBig ? 32 : 24,
2024-01-22 18:00:24 +00:00
color: Colors.white
)
)
),
2024-01-01 21:43:12 +00:00
if (oldPlayerStat != null) Text(comparef.format(playerStat - oldPlayerStat!), style: TextStyle(
2023-06-28 16:50:40 +00:00
color: higherIsBetter ?
oldPlayerStat! > playerStat ? Colors.red : Colors.green :
oldPlayerStat! < playerStat ? Colors.red : Colors.green
),),
2023-06-27 20:55:59 +00:00
alertWidgets == null
? Text(
playerStatLabel,
textAlign: TextAlign.center,
style: const TextStyle(
fontFamily: "Eurostile Round",
fontSize: 16,
height: 1.1
),
)
: TextButton(
onPressed: () {
2023-06-27 20:55:59 +00:00
showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
2024-01-22 18:00:24 +00:00
title: Text(alertTitle??playerStatLabel.replaceAll(RegExp(r'\n'), " "),
2023-06-27 20:55:59 +00:00
style: const TextStyle(
fontFamily: "Eurostile Round Extended")),
content: SingleChildScrollView(
child: ListBody(children: alertWidgets!),
),
actions: <Widget>[
TextButton(
2023-07-12 15:14:25 +00:00
child: Text(okText??"OK"),
onPressed: () {Navigator.of(context).pop();}
2023-06-27 20:55:59 +00:00
)
],
)
);
},
2023-06-27 20:55:59 +00:00
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero)),
child: Text(
playerStatLabel,
textAlign: TextAlign.center,
style: const TextStyle(
fontFamily: "Eurostile Round",
fontSize: 16,
height: 1.1
),
)),
],
);
}
}