stack_wallet/lib/utilities/extensions/impl/gradient.dart

64 lines
1.5 KiB
Dart
Raw Normal View History

2023-04-18 16:46:04 +00:00
import 'package:flutter/material.dart';
import 'package:stackwallet/utilities/extensions/impl/string.dart';
// todo: delete this map (example)
final map = {
"name": "Dark",
"coinColors": {
"bitcoin": "0xFF267352",
},
"assets": {
"circleLock": "svg/somerandomnamecreatedbythemecreator.svg",
},
"colors": {
"background": "0xFF848383",
},
"gradients": {
2023-04-25 13:28:10 +00:00
"background": {
"type": "linear",
2023-04-18 16:46:04 +00:00
"begin": {
"x": 0.0,
"y": 1.0,
},
"end": {
"x": -1.0,
"y": 1.0,
},
"colors": [
"0xFF638227",
"0xFF632827",
]
}
}
};
extension GradientExt on Gradient {
static Gradient fromJson(Map<String, dynamic> json) {
2023-04-25 13:28:10 +00:00
switch (json["type"]) {
case "linear":
final colorStrings =
List<String>.from(json["background"]["colors"] as List);
return LinearGradient(
begin: Alignment(
json["background"]["begin"]["x"] as double,
json["background"]["begin"]["y"] as double,
),
end: Alignment(
json["background"]["end"]["x"] as double,
json["background"]["end"]["y"] as double,
),
colors: colorStrings
.map(
(e) => Color(
e.toBigIntFromHex.toInt(),
),
)
.toList(),
);
2023-04-18 16:46:04 +00:00
2023-04-25 13:28:10 +00:00
default:
throw ArgumentError("Invalid json gradient: $json");
2023-04-18 16:46:04 +00:00
}
}
}