Skip to content

Commit 671aaad

Browse files
authored
patch: Fixed color parsing from RGBA array (#56)
* Fixed color parsing from RGBA int array * upd tests
1 parent 79b0cc0 commit 671aaad

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

lib/src/view_attributes/data_source.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ extension type DuitDataSource(Map<String, dynamic> _json)
201201
Color? _colorFromList(List color) {
202202
final colorData = color.map((e) => e as num).toList();
203203
return switch (colorData.length) {
204-
4 => Color.fromRGBO(
204+
4 => Color.fromARGB(
205+
colorData[3].toInt(),
205206
colorData[0].toInt(),
206207
colorData[1].toInt(),
207208
colorData[2].toInt(),
208-
colorData[3].toDouble(),
209209
),
210210
3 => Color.fromRGBO(
211211
colorData[0].toInt(),

test/data_source_test.dart

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ void main() {
395395
expect(data["icon"], result);
396396
});
397397

398-
test("should return default value if the value is not String, Map or IconData",
398+
test(
399+
"should return default value if the value is not String, Map or IconData",
399400
() {
400401
final defaultIcon = Icons.star;
401402
final json = <String, dynamic>{"icon": 42};
@@ -582,23 +583,28 @@ void main() {
582583

583584
test("should parse color from RGBA list", () {
584585
final json = <String, dynamic>{
585-
"color": [255, 0, 0, 0.5],
586-
"color2": [0, 255, 0, 0.7],
587-
"color3": [0, 0, 255, 0.3],
586+
"color": [255, 0, 0, 190],
587+
"color2": [0, 255, 0, 230],
588+
"color3": [0, 0, 255, 100],
588589
};
589590

590591
final data = DuitDataSource(json);
591592
expect(
592593
data.parseColor(key: "color"),
593-
const Color.fromRGBO(255, 0, 0, 0.5),
594+
const Color.fromARGB(190, 255, 0, 0),
594595
);
595596
expect(
596597
data.parseColor(key: "color2"),
597-
const Color.fromRGBO(0, 255, 0, 0.7),
598+
const Color.fromARGB(
599+
230,
600+
0,
601+
255,
602+
0,
603+
),
598604
);
599605
expect(
600606
data.parseColor(key: "color3"),
601-
const Color.fromRGBO(0, 0, 255, 0.3),
607+
const Color.fromARGB(100, 0, 0, 255),
602608
);
603609
});
604610

@@ -7843,7 +7849,9 @@ void main() {
78437849
MultitouchDragStrategy.sumAllPointers,
78447850
);
78457851
expect(
7846-
data["multitouchDragStrategy"], MultitouchDragStrategy.latestPointer,);
7852+
data["multitouchDragStrategy"],
7853+
MultitouchDragStrategy.latestPointer,
7854+
);
78477855
expect(
78487856
data["multitouchDragStrategy2"],
78497857
MultitouchDragStrategy.sumAllPointers,
@@ -7867,7 +7875,9 @@ void main() {
78677875
MultitouchDragStrategy.averageBoundaryPointers,
78687876
);
78697877
expect(
7870-
data["multitouchDragStrategy"], MultitouchDragStrategy.latestPointer,);
7878+
data["multitouchDragStrategy"],
7879+
MultitouchDragStrategy.latestPointer,
7880+
);
78717881
expect(
78727882
data["multitouchDragStrategy2"],
78737883
MultitouchDragStrategy.averageBoundaryPointers,

0 commit comments

Comments
 (0)