Skip to content

Commit

Permalink
Migrate design to null safety (#430)
Browse files Browse the repository at this point in the history
Closes #200
  • Loading branch information
nilsreichardt authored Mar 8, 2023
1 parent 8933c38 commit 2fa2c17
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
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

0 comments on commit 2fa2c17

Please sign in to comment.