mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-26 00:58:50 +00:00
WIP re themeing
This commit is contained in:
parent
3db3ad06c5
commit
f6becfbe77
7 changed files with 170 additions and 7 deletions
lib
models/isar
temp_themes
utilities
|
@ -1,8 +1,19 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||
import 'package:stackwallet/utilities/extensions/impl/gradient.dart';
|
||||
import 'package:stackwallet/utilities/extensions/impl/string.dart';
|
||||
import 'package:stackwallet/utilities/theme/color_theme.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
@Collection(inheritance: false)
|
||||
class SWTheme {
|
||||
class ColorTheme {
|
||||
static String themesDirPath = "/djhfgj/sdfd/themes/";
|
||||
|
||||
final String assetBundleUrl;
|
||||
|
||||
/// should be a uuid
|
||||
@Index(unique: true, replace: true)
|
||||
final String id;
|
||||
|
@ -26,4 +37,91 @@ class SWTheme {
|
|||
return Brightness.light;
|
||||
}
|
||||
}
|
||||
|
||||
@ignore
|
||||
Color get background => _background ??= Color(
|
||||
backgroundString.toBigIntFromHex.toInt(),
|
||||
);
|
||||
@ignore
|
||||
Color? _background;
|
||||
final String backgroundString;
|
||||
|
||||
// ==== backgroundAppBar =====================================================
|
||||
@ignore
|
||||
Color get backgroundAppBar => _backgroundAppBar ??= Color(
|
||||
backgroundAppBarString.toBigIntFromHex.toInt(),
|
||||
);
|
||||
@ignore
|
||||
Color? _backgroundAppBar;
|
||||
final String backgroundAppBarString;
|
||||
// ===========================================================================
|
||||
|
||||
@ignore
|
||||
Gradient get gradientBackground =>
|
||||
_gradientBackground ??= GradientExt.fromJson(
|
||||
Map<String, dynamic>.from(
|
||||
jsonDecode(gradientBackgroundString) as Map,
|
||||
),
|
||||
);
|
||||
@ignore
|
||||
Gradient? _gradientBackground;
|
||||
final String gradientBackgroundString;
|
||||
|
||||
@ignore
|
||||
Map<Coin, Color> get coinColors =>
|
||||
_coinColors ??= parseCoinColors(coinColorsString);
|
||||
@ignore
|
||||
Map<Coin, Color>? _coinColors;
|
||||
final String coinColorsString;
|
||||
|
||||
// ==== assets =====================================================
|
||||
final String circleLock;
|
||||
|
||||
ColorTheme({
|
||||
required this.id,
|
||||
required this.assetBundleUrl,
|
||||
required this.name,
|
||||
required this.brightnessString,
|
||||
required this.backgroundString,
|
||||
required this.backgroundAppBarString,
|
||||
required this.gradientBackgroundString,
|
||||
required this.coinColorsString,
|
||||
required this.circleLock,
|
||||
});
|
||||
|
||||
factory ColorTheme.fromJson(Map<String, dynamic> json) {
|
||||
final _id = const Uuid().v1();
|
||||
return ColorTheme(
|
||||
id: _id,
|
||||
name: json["name"] as String,
|
||||
assetBundleUrl: json["assetBundleUrl"] as String,
|
||||
brightnessString: json["brightness"] as String,
|
||||
backgroundString: json["colors"]["background"] as String,
|
||||
backgroundAppBarString: json["colors"]["backgroundAppBar"] as String,
|
||||
gradientBackgroundString:
|
||||
jsonEncode(json["gradients"]["gradientBackground"] as Map),
|
||||
coinColorsString: jsonEncode(json["coinColors"] as Map),
|
||||
circleLock:
|
||||
"$themesDirPath/$_id/${json["assets"]["circleLock"] as String}",
|
||||
);
|
||||
}
|
||||
|
||||
static Map<Coin, Color> parseCoinColors(String jsonString) {
|
||||
final json = jsonDecode(jsonString) as Map;
|
||||
final map = Map<String, dynamic>.from(json);
|
||||
|
||||
final Map<Coin, Color> result = {};
|
||||
|
||||
for (final coin in Coin.values) {
|
||||
if (map[coin.name] is String) {
|
||||
result[coin] = Color(
|
||||
(map[coin.name] as String).toBigIntFromHex.toInt(),
|
||||
);
|
||||
} else {
|
||||
result[coin] = kCoinThemeColorDefaults.forCoin(coin);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
1
lib/temp_themes/dark.dart
Normal file
1
lib/temp_themes/dark.dart
Normal file
|
@ -0,0 +1 @@
|
|||
final Map<String, dynamic> darkJson = {};
|
0
lib/utilities/extensions/impl/box_shadow.dart
Normal file
0
lib/utilities/extensions/impl/box_shadow.dart
Normal file
62
lib/utilities/extensions/impl/gradient.dart
Normal file
62
lib/utilities/extensions/impl/gradient.dart
Normal file
|
@ -0,0 +1,62 @@
|
|||
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<String, dynamic> json) {
|
||||
switch (json["gradientType"] as String) {
|
||||
case "linear":
|
||||
final colorStrings = List<String>.from(json["colors"] as List);
|
||||
return LinearGradient(
|
||||
begin: Alignment(
|
||||
json["begin"]["x"] as double,
|
||||
json["begin"]["y"] as double,
|
||||
),
|
||||
end: Alignment(
|
||||
json["end"]["x"] as double,
|
||||
json["end"]["y"] as double,
|
||||
),
|
||||
colors: colorStrings
|
||||
.map(
|
||||
(e) => Color(
|
||||
e.toBigIntFromHex.toInt(),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
|
||||
default:
|
||||
throw ArgumentError("Invalid json gradient: $json");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -300,8 +300,10 @@ abstract class StackColorTheme {
|
|||
}
|
||||
// 0xFFFFD8CE
|
||||
|
||||
class CoinThemeColor {
|
||||
const CoinThemeColor();
|
||||
const kCoinThemeColorDefaults = CoinThemeColorDefault();
|
||||
|
||||
class CoinThemeColorDefault {
|
||||
const CoinThemeColorDefault();
|
||||
|
||||
Color get bitcoin => const Color(0xFFFCC17B);
|
||||
Color get litecoin => const Color(0xFF7FA6E1);
|
||||
|
|
|
@ -365,8 +365,8 @@ class OceanBreezeColors extends StackColorTheme {
|
|||
@override
|
||||
BoxShadow get standardBoxShadow => BoxShadow(
|
||||
color: shadow,
|
||||
spreadRadius: 3,
|
||||
blurRadius: 4,
|
||||
spreadRadius: 3.0,
|
||||
blurRadius: 4.0,
|
||||
);
|
||||
|
||||
@override
|
||||
|
|
|
@ -1686,7 +1686,7 @@ class StackColors extends ThemeExtension<StackColors> {
|
|||
}
|
||||
}
|
||||
|
||||
static const _coin = CoinThemeColor();
|
||||
static const _coin = CoinThemeColorDefault();
|
||||
|
||||
Color colorForStatus(String status) {
|
||||
switch (status) {
|
||||
|
|
Loading…
Reference in a new issue