1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 06:18:49 +00:00

web/github_dataviz: Migrate to null safety (#919)

This commit is contained in:
Brett Morgan
2021-10-08 19:43:25 +11:00
committed by GitHub
parent 8932e60976
commit 83d3ea99f0
12 changed files with 183 additions and 144 deletions

View File

@@ -8,7 +8,7 @@ class ContributionData {
static ContributionData fromJson(Map<String, dynamic> jsonMap) {
ContributionData data = ContributionData(
jsonMap["w"], jsonMap["a"], jsonMap["d"], jsonMap["c"]);
jsonMap['w'], jsonMap['a'], jsonMap['d'], jsonMap['c']);
return data;
}
}

View File

@@ -6,7 +6,7 @@ class User {
User(this.id, this.username, this.avatarUrl);
static User fromJson(Map<String, dynamic> jsonMap) {
User user = User(jsonMap["id"], jsonMap["login"], jsonMap["avatar_url"]);
User user = User(jsonMap['id'], jsonMap['login'], jsonMap['avatar_url']);
return user;
}
}

View File

@@ -8,11 +8,11 @@ class UserContribution {
UserContribution(this.user, this.contributions);
static UserContribution fromJson(Map<String, dynamic> jsonMap) {
List<ContributionData> contributionList = (jsonMap["weeks"] as List)
List<ContributionData> contributionList = (jsonMap['weeks'] as List)
.map((e) => ContributionData.fromJson(e))
.toList();
var userContribution =
UserContribution(User.fromJson(jsonMap["author"]), contributionList);
UserContribution(User.fromJson(jsonMap['author']), contributionList);
return userContribution;
}
}

View File

@@ -1,24 +1,23 @@
import 'package:intl/intl.dart';
class WeekLabel {
int weekNum;
int? weekNum;
String label;
WeekLabel(this.weekNum, this.label);
WeekLabel.forDate(DateTime date, String label) {
this.label = label;
WeekLabel.forDate(DateTime date, this.label) {
int year = getYear(date);
int weekOfYearNum = getWeekNumber(date);
this.weekNum = 9 + ((year - 2015) * 52) + weekOfYearNum;
weekNum = 9 + ((year - 2015) * 52) + weekOfYearNum;
}
int getYear(DateTime date) {
return int.parse(DateFormat("y").format(date));
return int.parse(DateFormat('y').format(date));
}
int getWeekNumber(DateTime date) {
int dayOfYear = int.parse(DateFormat("D").format(date));
int dayOfYear = int.parse(DateFormat('D').format(date));
return ((dayOfYear - date.weekday + 10) / 7).floor();
}
}