Optimized statistics tile
This commit is contained in:
@@ -42,7 +42,6 @@ class StatisticsTile extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final maxBarWidth = MediaQuery.of(context).size.width * 0.65;
|
|
||||||
final loc = AppLocalizations.of(context);
|
final loc = AppLocalizations.of(context);
|
||||||
|
|
||||||
return InfoTile(
|
return InfoTile(
|
||||||
@@ -57,38 +56,56 @@ class StatisticsTile extends StatelessWidget {
|
|||||||
heightFactor: 4,
|
heightFactor: 4,
|
||||||
child: Text(loc.no_data_available),
|
child: Text(loc.no_data_available),
|
||||||
),
|
),
|
||||||
child: Column(
|
child: LayoutBuilder(
|
||||||
children: List.generate(min(values.length, itemCount), (index) {
|
builder: (context, constraints) {
|
||||||
/// The maximum wins among all players
|
final maxBarWidth = constraints.maxWidth * 0.65;
|
||||||
final maxMatches = values.isNotEmpty ? values[0].$2 : 0;
|
return Column(
|
||||||
|
children: List.generate(min(values.length, itemCount), (index) {
|
||||||
|
/// The maximum wins among all players
|
||||||
|
final maxMatches = values.isNotEmpty ? values[0].$2 : 0;
|
||||||
|
|
||||||
/// Fraction of wins
|
/// Fraction of wins
|
||||||
final double fraction = (maxMatches > 0)
|
final double fraction = (maxMatches > 0)
|
||||||
? (values[index].$2 / maxMatches)
|
? (values[index].$2 / maxMatches)
|
||||||
: 0.0;
|
: 0.0;
|
||||||
|
|
||||||
/// Calculated width for current the bar
|
/// Calculated width for current the bar
|
||||||
final double barWidth = maxBarWidth * fraction;
|
final double barWidth = maxBarWidth * fraction;
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 2.0),
|
padding: const EdgeInsets.symmetric(vertical: 2.0),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: [
|
|
||||||
Stack(
|
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Stack(
|
||||||
height: 24,
|
children: [
|
||||||
width: barWidth,
|
Container(
|
||||||
decoration: BoxDecoration(
|
height: 24,
|
||||||
borderRadius: BorderRadius.circular(4),
|
width: barWidth,
|
||||||
color: barColor,
|
decoration: BoxDecoration(
|
||||||
),
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
color: barColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 4.0),
|
||||||
|
child: Text(
|
||||||
|
values[index].$1,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
Padding(
|
const Spacer(),
|
||||||
padding: const EdgeInsets.only(left: 4.0),
|
Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
values[index].$1,
|
values[index].$2 <= 1 && values[index].$2 is double
|
||||||
|
? values[index].$2.toStringAsFixed(2)
|
||||||
|
: values[index].$2.toString(),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
@@ -97,23 +114,10 @@ class StatisticsTile extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const Spacer(),
|
);
|
||||||
Center(
|
}),
|
||||||
child: Text(
|
|
||||||
values[index].$2 <= 1 && values[index].$2 is double
|
|
||||||
? values[index].$2.toStringAsFixed(2)
|
|
||||||
: values[index].$2.toString(),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}),
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user