Skip to content

Commit

Permalink
feat: tweak dark mode contribution color
Browse files Browse the repository at this point in the history
  • Loading branch information
pd4d10 committed Dec 12, 2020
1 parent 08511fb commit 6036849
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
13 changes: 1 addition & 12 deletions lib/screens/gh_user.dart
Expand Up @@ -122,18 +122,7 @@ class GhUserScreen extends StatelessWidget {
[
// https://github.com/git-touch/git-touch/issues/122
for (final day in week.contributionDays)
if (day.color.startsWith('#'))
ContributionDay(hexColor: day.color)
else if (day.color.contains('L1'))
ContributionDay(hexColor: contributionColors[0])
else if (day.color.contains('L2'))
ContributionDay(hexColor: contributionColors[1])
else if (day.color.contains('L3'))
ContributionDay(hexColor: contributionColors[2])
else if (day.color.contains('L4'))
ContributionDay(hexColor: contributionColors[3])
else
ContributionDay(hexColor: contributionEmptyColor)
ContributionDay(hexColor: day.color)
]
],
),
Expand Down
31 changes: 17 additions & 14 deletions lib/widgets/contribution.dart
Expand Up @@ -8,12 +8,19 @@ import 'package:provider/provider.dart';
const contributionEmptyColor = '#ebedf0';
const contributionColors = ['#9be9a8', '#40c463', '#30a14e', '#216e39'];

const darkMapper = {
'#ebedf0': '#161b22',
'#9be9a8': '#01311f',
'#40c463': '#034525',
'#30a14e': '#0f6d31',
'#216e39': '#00c647'
};

class ContributionDay {
String hexColor;
int count;
Color color;
ContributionDay({this.hexColor, this.count, this.color})
: assert(hexColor != null || count != null || color != null);
ContributionDay({this.hexColor, this.count})
: assert(hexColor != null || count != null);
}

class ContributionWidget extends StatelessWidget {
Expand All @@ -33,22 +40,15 @@ class ContributionWidget extends StatelessWidget {
if (day.count == 0) {
day.hexColor = contributionEmptyColor;
} else {
// TODO: algorithm
final level = (day.count * 4) ~/ (maxCount + 1);
day.hexColor = contributionColors[level];
}
}
if (day.hexColor != null) {
day.color = convertColor(day.hexColor);
}
}
}
}

static Color _revert(Color color) {
return Color.fromRGBO(
0xff - color.red, 0xff - color.green, 0xff - color.blue, 1);
}

@override
Widget build(BuildContext context) {
final theme = context.watch<ThemeModel>();
Expand All @@ -72,9 +72,12 @@ class ContributionWidget extends StatelessWidget {
height: 10,
child: DecoratedBox(
decoration: BoxDecoration(
color: theme.brightness == Brightness.dark
? _revert(day.color)
: day.color),
color: convertColor(
theme.brightness == Brightness.dark
? darkMapper[day.hexColor]
: day.hexColor,
),
borderRadius: BorderRadius.circular(2)),
),
)
],
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Expand Up @@ -31,6 +31,7 @@ dependencies:
http: ^0.12.0
in_app_review: ^1.0.4
intl: ^0.16.0
json_annotation: ^3.1.1
launch_review: ^2.0.0
nanoid: ^0.1.0
package_info: ^0.4.0
Expand All @@ -50,7 +51,7 @@ dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^1.10.3
json_serializable: ^3.5.0
json_serializable: ^3.5.1

# dependencies_overrides:
# flutter_highlight:
Expand Down

0 comments on commit 6036849

Please sign in to comment.