Skip to content

Commit 0784915

Browse files
committed
Test
1 parent d2149fe commit 0784915

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import 'package:fl_chart/fl_chart.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter_test/flutter_test.dart';
4+
5+
List<BarChartGroupData> get barGroups => [
6+
BarChartGroupData(x: 0, barRods: [BarChartRodData(toY: 8)]),
7+
BarChartGroupData(x: 1, barRods: [BarChartRodData(toY: 10)]),
8+
BarChartGroupData(x: 2, barRods: [BarChartRodData(toY: 14)]),
9+
BarChartGroupData(x: 3, barRods: [BarChartRodData(toY: 15)]),
10+
BarChartGroupData(x: 4, barRods: [BarChartRodData(toY: 13)]),
11+
BarChartGroupData(x: 5, barRods: [BarChartRodData(toY: 10)]),
12+
BarChartGroupData(x: 6, barRods: [BarChartRodData(toY: 16)]),
13+
BarChartGroupData(x: 7, barRods: [BarChartRodData(toY: 8)]),
14+
BarChartGroupData(x: 8, barRods: [BarChartRodData(toY: 10)]),
15+
BarChartGroupData(x: 9, barRods: [BarChartRodData(toY: 14)]),
16+
BarChartGroupData(x: 10, barRods: [BarChartRodData(toY: 15)]),
17+
BarChartGroupData(x: 11, barRods: [BarChartRodData(toY: 13)]),
18+
BarChartGroupData(x: 12, barRods: [BarChartRodData(toY: 10)]),
19+
BarChartGroupData(x: 13, barRods: [BarChartRodData(toY: 16)]),
20+
BarChartGroupData(x: 14, barRods: [BarChartRodData(toY: 8)]),
21+
BarChartGroupData(x: 15, barRods: [BarChartRodData(toY: 10)]),
22+
BarChartGroupData(x: 16, barRods: [BarChartRodData(toY: 14)]),
23+
BarChartGroupData(x: 17, barRods: [BarChartRodData(toY: 15)]),
24+
BarChartGroupData(x: 18, barRods: [BarChartRodData(toY: 13)]),
25+
BarChartGroupData(x: 19, barRods: [BarChartRodData(toY: 10)]),
26+
BarChartGroupData(x: 20, barRods: [BarChartRodData(toY: 16)]),
27+
];
28+
29+
void main() {
30+
const viewSize = Size(400, 400);
31+
32+
testWidgets(
33+
'Barchart alignment overflow test',
34+
(WidgetTester tester) async {
35+
// Test that the bar chart alignment works as expected when the
36+
// bar groups are too wide to fit in the chart.
37+
for (final groupsSpace in [4.0, 20.0]) {
38+
for (final barChartAlignment in [
39+
BarChartAlignment.start,
40+
BarChartAlignment.center,
41+
BarChartAlignment.end,
42+
]) {
43+
// Build the bar chart.
44+
await tester.pumpWidget(
45+
MaterialApp(
46+
home: Scaffold(
47+
body: Center(
48+
child: SizedBox(
49+
width: viewSize.width,
50+
height: viewSize.height,
51+
child: BarChart(
52+
BarChartData(
53+
barGroups: barGroups,
54+
gridData: const FlGridData(show: false),
55+
alignment: barChartAlignment,
56+
groupsSpace: groupsSpace,
57+
maxY: 20,
58+
),
59+
),
60+
),
61+
),
62+
),
63+
),
64+
);
65+
66+
// Wait for the chart to be rendered.
67+
await tester.pumpAndSettle();
68+
69+
// Take a golden image.
70+
final fname = '${barChartAlignment}_$groupsSpace';
71+
await expectLater(
72+
find.byType(BarChart),
73+
matchesGoldenFile('golden/$fname.png'),
74+
);
75+
}
76+
}
77+
},
78+
);
79+
}

0 commit comments

Comments
 (0)