diff --git a/lib/models/isar/sw_theme.dart b/lib/models/isar/sw_theme.dart index 1f006dd83..dc79e4f04 100644 --- a/lib/models/isar/sw_theme.dart +++ b/lib/models/isar/sw_theme.dart @@ -59,15 +59,22 @@ class StackTheme { // ==== gradientBackground ===================================================== @ignore - Gradient get gradientBackground => + Gradient? get gradientBackground { + if (gradientBackgroundString == null) { + _gradientBackground = null; + } else { _gradientBackground ??= GradientExt.fromJson( Map.from( - jsonDecode(gradientBackgroundString) as Map, + jsonDecode(gradientBackgroundString!) as Map, ), ); + } + return _gradientBackground; + } + @ignore Gradient? _gradientBackground; - final String gradientBackgroundString; + final String? gradientBackgroundString; // ==== boxShadows ===================================================== @@ -1643,7 +1650,7 @@ class StackTheme { parseColor(json["colors"]["background"]["background"] as String), backgroundAppBarInt: parseColor( json["colors"]["background"]["backgroundAppBar"] as String), - gradientBackgroundString: jsonEncode(json["gradients"] as Map), + gradientBackgroundString: json["gradients"] as String?, standardBoxShadowString: jsonEncode(json["box_shadows"]["standard"] as Map), homeViewButtonBarBoxShadowString: diff --git a/lib/themes/defaults/dark.dart b/lib/themes/defaults/dark.dart index cc7de678f..19f140003 100644 --- a/lib/themes/defaults/dark.dart +++ b/lib/themes/defaults/dark.dart @@ -69,14 +69,6 @@ final Map darkJson = { "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", "shadow": "0x0F2D3132", "text_subtitles": { diff --git a/lib/utilities/extensions/impl/gradient.dart b/lib/utilities/extensions/impl/gradient.dart index f34a24fe5..8af06d421 100644 --- a/lib/utilities/extensions/impl/gradient.dart +++ b/lib/utilities/extensions/impl/gradient.dart @@ -1,68 +1,32 @@ 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": { - "gradientBackground": { - "gradientType": "linear", - "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 json) { - print("THIS GRADIENTS IS ${json.isEmpty}"); - if (!json.isEmpty) { - switch (json["background"]["type"]) { - case "Linear": - final colorStrings = - List.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(), - ); + switch (json["background"]["type"]) { + case "Linear": + final colorStrings = + List.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(), + ); - default: - throw ArgumentError("Invalid json gradient: $json"); - } + default: + throw ArgumentError("Invalid json gradient: $json"); } - throw ArgumentError("Invalid json gradient: $json"); - // if () } }