diff --git a/lib/screens/gh_user.dart b/lib/screens/gh_user.dart index 0eef91ab..3062d03b 100644 --- a/lib/screens/gh_user.dart +++ b/lib/screens/gh_user.dart @@ -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) ] ], ), diff --git a/lib/widgets/contribution.dart b/lib/widgets/contribution.dart index cc66f71f..4aa86fb5 100644 --- a/lib/widgets/contribution.dart +++ b/lib/widgets/contribution.dart @@ -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 { @@ -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(); @@ -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)), ), ) ], diff --git a/pubspec.yaml b/pubspec.yaml index 69eaf1ef..f9a5134c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 @@ -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: