mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Group the plates for easier reading
This commit is contained in:
@@ -44,3 +44,19 @@ List<num> plateCalculator(num totalWeight, num barWeight, List<num> plates) {
|
||||
|
||||
return ans;
|
||||
}
|
||||
|
||||
/// Groups a list of plates as calculated by [plateCalculator]
|
||||
///
|
||||
/// e.g. [15, 15, 15, 10, 10, 5] returns {15: 3, 10: 2, 5: 1}
|
||||
Map<num, int> groupPlates(List<num> plates) {
|
||||
Map<num, int> out = {};
|
||||
for (var plate in plates) {
|
||||
if (!out.containsKey(plate)) {
|
||||
out[plate] = 1;
|
||||
} else {
|
||||
out[plate] = out[plate]! + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -523,6 +523,7 @@ class _LogPageState extends State<LogPage> {
|
||||
BAR_WEIGHT,
|
||||
AVAILABLE_PLATES,
|
||||
);
|
||||
final groupedPlates = groupPlates(plates);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
@@ -531,32 +532,39 @@ class _LogPageState extends State<LogPage> {
|
||||
style: Theme.of(context).textTheme.headline6,
|
||||
),
|
||||
SizedBox(
|
||||
height: 40,
|
||||
height: 35,
|
||||
child: plates.length > 0
|
||||
? Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
...plates
|
||||
...groupedPlates.keys
|
||||
.map(
|
||||
(e) => Container(
|
||||
decoration: BoxDecoration(
|
||||
color: wgerPrimaryColorLight,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5),
|
||||
child: SizedBox(
|
||||
height: 35,
|
||||
width: 35,
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
e.toString(),
|
||||
style: Theme.of(context).textTheme.headline6,
|
||||
(key) => Row(
|
||||
children: [
|
||||
Text(groupedPlates[key].toString()),
|
||||
Text('×'),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: wgerPrimaryColorLight,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 3),
|
||||
child: SizedBox(
|
||||
height: 35,
|
||||
width: 35,
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
key.toString(),
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
],
|
||||
),
|
||||
)
|
||||
.toList()
|
||||
@@ -564,6 +572,7 @@ class _LogPageState extends State<LogPage> {
|
||||
)
|
||||
: MutedText(AppLocalizations.of(context).plateCalculatorNotDivisible),
|
||||
),
|
||||
SizedBox(height: 3),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -45,4 +45,12 @@ void main() {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('Test the plate calculator group', () {
|
||||
test('Test groups', () async {
|
||||
expect(groupPlates([15, 15, 15, 10, 10, 5]), {15: 3, 10: 2, 5: 1});
|
||||
expect(groupPlates([15, 10, 5, 1.25]), {15: 1, 10: 1, 5: 1, 1.25: 1});
|
||||
expect(groupPlates([10, 10, 10, 10, 10, 10, 10]), {10: 7});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user