fixed bar length
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:fluttericon/rpg_awesome_icons.dart';
|
import 'package:fluttericon/rpg_awesome_icons.dart';
|
||||||
import 'package:tallee/core/common.dart';
|
import 'package:tallee/core/common.dart';
|
||||||
import 'package:tallee/core/custom_theme.dart';
|
import 'package:tallee/core/custom_theme.dart';
|
||||||
|
import 'package:tallee/core/enums.dart';
|
||||||
import 'package:tallee/data/models/game.dart';
|
import 'package:tallee/data/models/game.dart';
|
||||||
import 'package:tallee/data/models/group.dart';
|
import 'package:tallee/data/models/group.dart';
|
||||||
import 'package:tallee/data/models/player.dart';
|
import 'package:tallee/data/models/player.dart';
|
||||||
@@ -62,34 +63,51 @@ class StatisticsTile extends StatelessWidget {
|
|||||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||||
child: Visibility(
|
child: Visibility(
|
||||||
visible: values.isNotEmpty,
|
visible: values.isNotEmpty,
|
||||||
|
|
||||||
|
// No data avaiable message
|
||||||
replacement: Center(
|
replacement: Center(
|
||||||
heightFactor: 4,
|
heightFactor: 4,
|
||||||
child: Text(loc.no_data_available),
|
child: Text(loc.no_data_available),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// Bar chart
|
||||||
child: LayoutBuilder(
|
child: LayoutBuilder(
|
||||||
builder: (context, constraints) {
|
builder: (context, constraints) {
|
||||||
final maxBarWidth = constraints.maxWidth * 0.65;
|
final maxBarWidth = constraints.maxWidth * 0.8;
|
||||||
|
final displayCount = min(values.length, itemCount);
|
||||||
|
final displayValues = values.take(displayCount).toList();
|
||||||
|
final maxVal = displayValues.isNotEmpty
|
||||||
|
? displayValues.fold<num>(
|
||||||
|
0,
|
||||||
|
(currentMax, entry) =>
|
||||||
|
entry.$2 > currentMax ? entry.$2 : currentMax,
|
||||||
|
)
|
||||||
|
: 0;
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
// Bar chart
|
// Bars
|
||||||
...List.generate(min(values.length, itemCount), (index) {
|
...List.generate(displayCount, (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 = (maxVal > 0)
|
||||||
? (values[index].$2 / maxMatches)
|
? (displayValues[index].$2 / maxVal)
|
||||||
: 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).clamp(
|
||||||
|
0.0,
|
||||||
|
maxBarWidth,
|
||||||
|
);
|
||||||
|
|
||||||
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: [
|
children: [
|
||||||
Stack(
|
SizedBox(
|
||||||
|
width: maxBarWidth,
|
||||||
|
child: Stack(
|
||||||
|
clipBehavior: Clip.hardEdge,
|
||||||
children: [
|
children: [
|
||||||
// Bar
|
// Bar
|
||||||
Container(
|
Container(
|
||||||
@@ -105,25 +123,42 @@ class StatisticsTile extends StatelessWidget {
|
|||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(left: 4.0),
|
padding: const EdgeInsets.only(left: 4.0),
|
||||||
child: RichText(
|
child: RichText(
|
||||||
|
maxLines: 1,
|
||||||
|
softWrap: false,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
text: TextSpan(
|
text: TextSpan(
|
||||||
style: DefaultTextStyle.of(context).style,
|
style: DefaultTextStyle.of(context).style,
|
||||||
children: [
|
children: [
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: values[index].$1.name,
|
text: displayValues[index].$1.name,
|
||||||
style: const TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
|
color:
|
||||||
|
barColor ==
|
||||||
|
getColorFromAppColor(
|
||||||
|
AppColor.yellow,
|
||||||
|
)
|
||||||
|
? const Color(0xFF101010)
|
||||||
|
: CustomTheme.textColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: getNameCountText(
|
text: getNameCountText(
|
||||||
values[index].$1,
|
displayValues[index].$1,
|
||||||
),
|
),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
color: CustomTheme.textColor
|
color:
|
||||||
|
(barColor ==
|
||||||
|
getColorFromAppColor(
|
||||||
|
AppColor.yellow,
|
||||||
|
)
|
||||||
|
? const Color(
|
||||||
|
0xFF101010,
|
||||||
|
)
|
||||||
|
: CustomTheme.textColor)
|
||||||
.withAlpha(150),
|
.withAlpha(150),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -133,15 +168,16 @@ class StatisticsTile extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
|
|
||||||
// Value
|
// Value
|
||||||
Center(
|
Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
values[index].$2 <= 1 &&
|
displayValues[index].$2 <= 1 &&
|
||||||
values[index].$2 is double
|
displayValues[index].$2 is double
|
||||||
? values[index].$2.toStringAsFixed(2)
|
? displayValues[index].$2.toStringAsFixed(2)
|
||||||
: values[index].$2.toString(),
|
: displayValues[index].$2.toString(),
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
|
|||||||
Reference in New Issue
Block a user