Skip to content

Commit 6036849

Browse files
committed
feat: tweak dark mode contribution color
1 parent 08511fb commit 6036849

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed

lib/screens/gh_user.dart

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,7 @@ class GhUserScreen extends StatelessWidget {
122122
[
123123
// https://github.com/git-touch/git-touch/issues/122
124124
for (final day in week.contributionDays)
125-
if (day.color.startsWith('#'))
126-
ContributionDay(hexColor: day.color)
127-
else if (day.color.contains('L1'))
128-
ContributionDay(hexColor: contributionColors[0])
129-
else if (day.color.contains('L2'))
130-
ContributionDay(hexColor: contributionColors[1])
131-
else if (day.color.contains('L3'))
132-
ContributionDay(hexColor: contributionColors[2])
133-
else if (day.color.contains('L4'))
134-
ContributionDay(hexColor: contributionColors[3])
135-
else
136-
ContributionDay(hexColor: contributionEmptyColor)
125+
ContributionDay(hexColor: day.color)
137126
]
138127
],
139128
),

lib/widgets/contribution.dart

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@ import 'package:provider/provider.dart';
88
const contributionEmptyColor = '#ebedf0';
99
const contributionColors = ['#9be9a8', '#40c463', '#30a14e', '#216e39'];
1010

11+
const darkMapper = {
12+
'#ebedf0': '#161b22',
13+
'#9be9a8': '#01311f',
14+
'#40c463': '#034525',
15+
'#30a14e': '#0f6d31',
16+
'#216e39': '#00c647'
17+
};
18+
1119
class ContributionDay {
1220
String hexColor;
1321
int count;
14-
Color color;
15-
ContributionDay({this.hexColor, this.count, this.color})
16-
: assert(hexColor != null || count != null || color != null);
22+
ContributionDay({this.hexColor, this.count})
23+
: assert(hexColor != null || count != null);
1724
}
1825

1926
class ContributionWidget extends StatelessWidget {
@@ -33,22 +40,15 @@ class ContributionWidget extends StatelessWidget {
3340
if (day.count == 0) {
3441
day.hexColor = contributionEmptyColor;
3542
} else {
43+
// TODO: algorithm
3644
final level = (day.count * 4) ~/ (maxCount + 1);
3745
day.hexColor = contributionColors[level];
3846
}
3947
}
40-
if (day.hexColor != null) {
41-
day.color = convertColor(day.hexColor);
42-
}
4348
}
4449
}
4550
}
4651

47-
static Color _revert(Color color) {
48-
return Color.fromRGBO(
49-
0xff - color.red, 0xff - color.green, 0xff - color.blue, 1);
50-
}
51-
5252
@override
5353
Widget build(BuildContext context) {
5454
final theme = context.watch<ThemeModel>();
@@ -72,9 +72,12 @@ class ContributionWidget extends StatelessWidget {
7272
height: 10,
7373
child: DecoratedBox(
7474
decoration: BoxDecoration(
75-
color: theme.brightness == Brightness.dark
76-
? _revert(day.color)
77-
: day.color),
75+
color: convertColor(
76+
theme.brightness == Brightness.dark
77+
? darkMapper[day.hexColor]
78+
: day.hexColor,
79+
),
80+
borderRadius: BorderRadius.circular(2)),
7881
),
7982
)
8083
],

pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ dependencies:
3131
http: ^0.12.0
3232
in_app_review: ^1.0.4
3333
intl: ^0.16.0
34+
json_annotation: ^3.1.1
3435
launch_review: ^2.0.0
3536
nanoid: ^0.1.0
3637
package_info: ^0.4.0
@@ -50,7 +51,7 @@ dev_dependencies:
5051
flutter_test:
5152
sdk: flutter
5253
build_runner: ^1.10.3
53-
json_serializable: ^3.5.0
54+
json_serializable: ^3.5.1
5455

5556
# dependencies_overrides:
5657
# flutter_highlight:

0 commit comments

Comments
 (0)