Skip to content

Commit 6689dc5

Browse files
authored
Merge pull request #111 from imsamgarg/fix_not_passing_args
Fix not passing args to colorToHex function in toHexString extension method
2 parents ce6aee9 + 808c9e6 commit 6689dc5

File tree

2 files changed

+92
-2
lines changed

2 files changed

+92
-2
lines changed

lib/src/utils.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ extension ColorExtension1 on String {
210210

211211
// Extension from Color
212212
extension ColorExtension2 on Color {
213-
String toHexString({bool includeHashSign = false, bool enableAlpha = true, bool toUpperCase = true}) =>
214-
colorToHex(this, includeHashSign: false, enableAlpha: true, toUpperCase: true);
213+
String toHexString({
214+
bool includeHashSign = false,
215+
bool enableAlpha = true,
216+
bool toUpperCase = true,
217+
}) {
218+
return colorToHex(
219+
this,
220+
includeHashSign: includeHashSign,
221+
enableAlpha: enableAlpha,
222+
toUpperCase: toUpperCase,
223+
);
224+
}
215225
}

test/utils_test.dart

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,84 @@ void main() {
253253
() => expect(colorToHex(color, enableAlpha: false, toUpperCase: false), string.toLowerCase()),
254254
));
255255
});
256+
257+
group('Test ColorExtension2.toHexString:', () {
258+
final Map<Color, String> colorsMap = {
259+
const Color(0xffffffff): 'FFFFFF',
260+
const Color(0x00000000): '000000',
261+
const Color(0xF0F0F0F0): 'F0F0F0'
262+
};
263+
264+
colorsMap.forEach((color, string) {
265+
final String transparency = string.substring(4);
266+
test(
267+
'It should convert $color: to ${transparency + string}',
268+
() => expect(color.toHexString(), transparency + string),
269+
);
270+
});
271+
272+
colorsMap.forEach((color, string) {
273+
final String transparency = string.substring(4);
274+
test(
275+
'It should convert $color: to #${transparency + string} with hash',
276+
() => expect(
277+
color.toHexString(includeHashSign: true), '#$transparency$string'),
278+
);
279+
});
280+
281+
colorsMap.forEach((color, string) {
282+
final String transparency = string.substring(4).toLowerCase();
283+
test(
284+
'It should convert $color: to #${transparency + string.toLowerCase()}, with hash, to lower case',
285+
() => expect(
286+
color.toHexString(includeHashSign: true, toUpperCase: false),
287+
'#$transparency${string.toLowerCase()}'),
288+
);
289+
});
290+
291+
colorsMap.forEach((color, string) {
292+
final String transparency = string.substring(4).toLowerCase();
293+
test(
294+
'It should convert $color to ${transparency + string.toLowerCase()}, with lower case',
295+
() => expect(
296+
color.toHexString(toUpperCase: false),
297+
transparency + string.toLowerCase(),
298+
),
299+
);
300+
});
301+
302+
colorsMap.forEach((color, string) => test(
303+
'It should convert $color: to $string, with alpha disabled',
304+
() => expect(
305+
color.toHexString(enableAlpha: false),
306+
string,
307+
),
308+
));
309+
310+
colorsMap.forEach((color, string) => test(
311+
'It should convert $color: to #$string, with alpha disabled and hash',
312+
() => expect(
313+
color.toHexString(enableAlpha: false, includeHashSign: true),
314+
'#$string'),
315+
));
316+
317+
colorsMap.forEach((color, string) => test(
318+
'It should convert $color: to #${string.toLowerCase()}, with alpha disabled and hash, to lower case',
319+
() => expect(
320+
color.toHexString(
321+
enableAlpha: false,
322+
includeHashSign: true,
323+
toUpperCase: false,
324+
),
325+
'#$string'.toLowerCase(),
326+
),
327+
));
328+
329+
colorsMap.forEach((color, string) => test(
330+
'It should convert $color to ${string.toLowerCase()}, with alpha disabled, to lower case',
331+
() => expect(
332+
color.toHexString(enableAlpha: false, toUpperCase: false),
333+
string.toLowerCase()),
334+
));
335+
});
256336
}

0 commit comments

Comments
 (0)