Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate design to null safety #430

Merged
merged 2 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/design/lib/src/color_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class ColorParser {
return rgbColor.toHexColor().toString();
}

static Color fromHex(String hex) {
static Color fromHex(String? hex) {
if (hex == null) return Colors.blue;
final rgbColor = colorlib.HexColor(hex).toRgbColor();
return Color.fromARGB(255, rgbColor.r, rgbColor.g, rgbColor.b);
return Color.fromARGB(255, rgbColor.r as int, rgbColor.g as int, rgbColor.b as int);
}
}
15 changes: 9 additions & 6 deletions lib/design/lib/src/design.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ enum DesignType {
color,
}

DesignType designTypeFromJson(dynamic data) =>
DesignType? designTypeFromJson(dynamic data) =>
enumFromString<DesignType>(DesignType.values, data,
orElse: DesignType.color);

String designTypeToJson(DesignType designType) => enumToString(designType);
String? designTypeToJson(DesignType? designType) => enumToString(designType);

class Design {
final String hex;
final DesignType type;

const Design._({this.hex, this.type});
const Design._({
required this.hex,
required this.type,
});

factory Design.standard() => Design.fromColor(Colors.lightBlue);

Expand All @@ -46,9 +49,9 @@ class Design {
if (data is String) {
return Design._(hex: data, type: DesignType.color);
}
DesignType type = designTypeFromJson(data['type']);
DesignType? type = designTypeFromJson(data['type']);
if (type == DesignType.color) {
return Design._(hex: data['color'], type: type);
return Design._(hex: data['color'], type: type!);
}
return Design.standard();
} catch (_) {
Expand Down Expand Up @@ -93,5 +96,5 @@ class Design {
Colors.grey,
Colors.brown,
Colors.black87,
].map((color) => Design.fromColor(color)).toList();
].map((color) => Design.fromColor(color!)).toList();
}
2 changes: 1 addition & 1 deletion lib/design/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ version: 0.0.1
publish_to: none

environment:
sdk: ">=2.10.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
sharezone_common:
Expand Down