@@ -58,14 +58,18 @@ class UndefinedLanguageColourError extends ArgumentError
5858 "UndefinedLanguageColourError" );
5959}
6060
61- Map <String , Color > _colourReader (String json) =>
62- (jsonDecode (json) as Map <String , dynamic >)
63- .map <String , Color >((language, node) {
64- String hex = node["color" ] ?? GitHubColour .defaultColourHex;
65- hex = "FF${hex .substring (1 ).toUpperCase ()}" ;
61+ Color _hex2C (String hex, [String alphaHex = "ff" ]) {
62+ assert (RegExp (r"^#[0-9a-f]{6}$" , caseSensitive: false ).hasMatch (hex));
63+ assert (RegExp (r"^[0-9a-f]{2}$" , caseSensitive: false ).hasMatch (alphaHex));
64+
65+ return Color (
66+ int .parse ("$alphaHex ${hex .substring (1 )}" .toUpperCase (), radix: 16 ));
67+ }
6668
67- return MapEntry (language, Color (int .parse (hex, radix: 16 )));
68- });
69+ Map <String , Color > _colourReader (String json) =>
70+ (jsonDecode (json) as Map <String , dynamic >).map <String , Color >(
71+ (language, node) => MapEntry (
72+ language, _hex2C (node["color" ] ?? GitHubColour .defaultColourHex)));
6973
7074/// A class for getting GitHub language colour.
7175@sealed
@@ -74,10 +78,10 @@ class GitHubColour {
7478 final Map <String , Color > _githubLangColour;
7579
7680 /// A [String] of hex value when the language is undefined or null.
77- static const String defaultColourHex = "#8f8f8f " ;
81+ static const String defaultColourHex = "#f0f0f0 " ;
7882
7983 /// [Color] object of [defaultColourHex] .
80- static const Color defaultColour = Color ( 0xff8f8f8f );
84+ static Color get defaultColour => _hex2C (defaultColourHex );
8185
8286 GitHubColour ._(Map <String , Color > githubLangColour)
8387 : this ._githubLangColour = Map .unmodifiable (githubLangColour);
@@ -122,6 +126,7 @@ class GitHubColour {
122126 ghjson = _colourReader (resp.body);
123127 } catch (neterr) {
124128 try {
129+ // Second source.
125130 ghjson = await getCache ();
126131 cacheSource = true ;
127132 } catch (cerr) {
@@ -142,6 +147,7 @@ class GitHubColour {
142147 }
143148
144149 if (! cacheSource) {
150+ // Do nothing if received data is exact same with source.
145151 await saveCache (ghjson);
146152 }
147153
0 commit comments