Correctly parse gradient

This commit is contained in:
likho 2023-04-25 15:12:56 +02:00
parent d42f48ceee
commit 4ed34ad50f
4 changed files with 39 additions and 25 deletions

View file

@ -1643,7 +1643,7 @@ class StackTheme {
parseColor(json["colors"]["background"]["background"] as String), parseColor(json["colors"]["background"]["background"] as String),
backgroundAppBarInt: parseColor( backgroundAppBarInt: parseColor(
json["colors"]["background"]["backgroundAppBar"] as String), json["colors"]["background"]["backgroundAppBar"] as String),
gradientBackgroundString: jsonEncode(json["gradients"] ?? ["background"]), gradientBackgroundString: jsonEncode(json["gradients"] as Map),
standardBoxShadowString: standardBoxShadowString:
jsonEncode(json["box_shadows"]["standard"] as Map), jsonEncode(json["box_shadows"]["standard"] as Map),
homeViewButtonBarBoxShadowString: homeViewButtonBarBoxShadowString:

View file

@ -69,6 +69,14 @@ final Map<String, dynamic> darkJson = {
"nav": "0xFF3E4148", "nav": "0xFF3E4148",
}, },
}, },
"gradients": {
// "background": {
// "type": "Linear",
// "begin": {"x": 0.0, "y": 1.0},
// "end": {"x": -1.0, "y": 1.0},
// "colors": ["0xFF638227", "0xFF638227"]
// }
},
"overlay": "0xFF111215", "overlay": "0xFF111215",
"shadow": "0x0F2D3132", "shadow": "0x0F2D3132",
"text_subtitles": { "text_subtitles": {

View file

@ -73,8 +73,8 @@ final Map<String, dynamic> darkJson = {
"gradients": { "gradients": {
"background": { "background": {
"type": "Linear", "type": "Linear",
"begin": {"x": 0, "y": 1}, "begin": {"x": 0.0, "y": 1.0},
"end": {"x": -1, "y": 1}, "end": {"x": -1.0, "y": 1.0},
"colors": ["0xFF638227", "0xFF638227"] "colors": ["0xFF638227", "0xFF638227"]
} }
}, },

View file

@ -34,29 +34,35 @@ final map = {
extension GradientExt on Gradient { extension GradientExt on Gradient {
static Gradient fromJson(Map<String, dynamic> json) { static Gradient fromJson(Map<String, dynamic> json) {
switch (json["gradientType"] as String) { print("THIS GRADIENTS IS ${json.isEmpty}");
case "linear": if (!json.isEmpty) {
final colorStrings = List<String>.from(json["colors"] as List); switch (json["background"]["type"]) {
return LinearGradient( case "Linear":
begin: Alignment( final colorStrings =
json["begin"]["x"] as double, List<String>.from(json["background"]["colors"] as List);
json["begin"]["y"] as double, return LinearGradient(
), begin: Alignment(
end: Alignment( json["background"]["begin"]["x"] as double,
json["end"]["x"] as double, json["background"]["begin"]["y"] as double,
json["end"]["y"] as double, ),
), end: Alignment(
colors: colorStrings json["background"]["end"]["x"] as double,
.map( json["background"]["end"]["y"] as double,
(e) => Color( ),
e.toBigIntFromHex.toInt(), colors: colorStrings
), .map(
) (e) => Color(
.toList(), e.toBigIntFromHex.toInt(),
); ),
)
.toList(),
);
default: default:
throw ArgumentError("Invalid json gradient: $json"); throw ArgumentError("Invalid json gradient: $json");
}
} }
throw ArgumentError("Invalid json gradient: $json");
// if ()
} }
} }