mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-26 20:26:02 +00:00
choose custom themes to set based on the system's light/dark brightness
This commit is contained in:
parent
75ea516005
commit
891f15cd58
10 changed files with 506 additions and 138 deletions
|
@ -31,7 +31,7 @@ class DB {
|
||||||
static const String boxNameWalletsToDeleteOnStart = "walletsToDeleteOnStart";
|
static const String boxNameWalletsToDeleteOnStart = "walletsToDeleteOnStart";
|
||||||
static const String boxNamePriceCache = "priceAPIPrice24hCache";
|
static const String boxNamePriceCache = "priceAPIPrice24hCache";
|
||||||
static const String boxNameDBInfo = "dbInfo";
|
static const String boxNameDBInfo = "dbInfo";
|
||||||
static const String boxNameTheme = "theme";
|
// static const String boxNameTheme = "theme";
|
||||||
static const String boxNameDesktopData = "desktopData";
|
static const String boxNameDesktopData = "desktopData";
|
||||||
static const String boxNameBuys = "buysBox";
|
static const String boxNameBuys = "buysBox";
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import 'package:cw_core/wallet_info.dart';
|
||||||
import 'package:cw_core/wallet_type.dart';
|
import 'package:cw_core/wallet_type.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/scheduler.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_libmonero/monero/monero.dart';
|
import 'package:flutter_libmonero/monero/monero.dart';
|
||||||
import 'package:flutter_libmonero/wownero/wownero.dart';
|
import 'package:flutter_libmonero/wownero/wownero.dart';
|
||||||
|
@ -59,15 +58,7 @@ import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
import 'package:stackwallet/utilities/prefs.dart';
|
import 'package:stackwallet/utilities/prefs.dart';
|
||||||
import 'package:stackwallet/utilities/stack_file_system.dart';
|
import 'package:stackwallet/utilities/stack_file_system.dart';
|
||||||
import 'package:stackwallet/utilities/theme/chan_colors.dart';
|
|
||||||
import 'package:stackwallet/utilities/theme/color_theme.dart';
|
import 'package:stackwallet/utilities/theme/color_theme.dart';
|
||||||
import 'package:stackwallet/utilities/theme/dark_colors.dart';
|
|
||||||
import 'package:stackwallet/utilities/theme/forest_colors.dart';
|
|
||||||
import 'package:stackwallet/utilities/theme/fruit_sorbet_colors.dart';
|
|
||||||
import 'package:stackwallet/utilities/theme/light_colors.dart';
|
|
||||||
import 'package:stackwallet/utilities/theme/ocean_breeze_colors.dart';
|
|
||||||
import 'package:stackwallet/utilities/theme/oled_black_colors.dart';
|
|
||||||
import 'package:stackwallet/utilities/theme/oled_chans_colors.dart';
|
|
||||||
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||||
import 'package:stackwallet/utilities/util.dart';
|
import 'package:stackwallet/utilities/util.dart';
|
||||||
import 'package:window_size/window_size.dart';
|
import 'package:window_size/window_size.dart';
|
||||||
|
@ -190,8 +181,6 @@ void main() async {
|
||||||
monero.onStartup();
|
monero.onStartup();
|
||||||
wownero.onStartup();
|
wownero.onStartup();
|
||||||
|
|
||||||
await Hive.openBox<dynamic>(DB.boxNameTheme);
|
|
||||||
|
|
||||||
// SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
// SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
||||||
// overlays: [SystemUiOverlay.bottom]);
|
// overlays: [SystemUiOverlay.bottom]);
|
||||||
await NotificationApi.init();
|
await NotificationApi.init();
|
||||||
|
@ -339,53 +328,27 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
final String? colorScheme;
|
StackColorTheme colorTheme;
|
||||||
if (ref.read(prefsChangeNotifierProvider).enableSystemBrightness) {
|
if (ref.read(prefsChangeNotifierProvider).enableSystemBrightness) {
|
||||||
final brightness =
|
final brightness = WidgetsBinding.instance.window.platformBrightness;
|
||||||
SchedulerBinding.instance.platformDispatcher.platformBrightness;
|
|
||||||
switch (brightness) {
|
switch (brightness) {
|
||||||
case Brightness.dark:
|
case Brightness.dark:
|
||||||
colorScheme =
|
colorTheme = ref
|
||||||
ref.read(prefsChangeNotifierProvider).systemBrightnessDarkTheme;
|
.read(prefsChangeNotifierProvider)
|
||||||
|
.systemBrightnessDarkTheme
|
||||||
|
.colorTheme;
|
||||||
break;
|
break;
|
||||||
case Brightness.light:
|
case Brightness.light:
|
||||||
colorScheme =
|
colorTheme = ref
|
||||||
ref.read(prefsChangeNotifierProvider).systemBrightnessLightTheme;
|
.read(prefsChangeNotifierProvider)
|
||||||
|
.systemBrightnessLightTheme
|
||||||
|
.colorTheme;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
colorScheme =
|
colorTheme = ref.read(prefsChangeNotifierProvider).theme.colorTheme;
|
||||||
DB.instance.get<dynamic>(boxName: DB.boxNameTheme, key: "colorScheme")
|
|
||||||
as String?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StackColorTheme colorTheme;
|
|
||||||
switch (colorScheme) {
|
|
||||||
case "dark":
|
|
||||||
colorTheme = DarkColors();
|
|
||||||
break;
|
|
||||||
case "oledBlack":
|
|
||||||
colorTheme = OledBlackColors();
|
|
||||||
break;
|
|
||||||
case "oceanBreeze":
|
|
||||||
colorTheme = OceanBreezeColors();
|
|
||||||
break;
|
|
||||||
case "fruitSorbet":
|
|
||||||
colorTheme = FruitSorbetColors();
|
|
||||||
break;
|
|
||||||
case "forest":
|
|
||||||
colorTheme = ForestColors();
|
|
||||||
break;
|
|
||||||
case "chan":
|
|
||||||
colorTheme = ChanColors();
|
|
||||||
break;
|
|
||||||
case "oledChans":
|
|
||||||
colorTheme = DarkChansColors();
|
|
||||||
break;
|
|
||||||
case "light":
|
|
||||||
default:
|
|
||||||
colorTheme = LightColors();
|
|
||||||
}
|
|
||||||
loadingCompleter = Completer();
|
loadingCompleter = Completer();
|
||||||
WidgetsBinding.instance.addObserver(this);
|
WidgetsBinding.instance.addObserver(this);
|
||||||
// load locale and prefs
|
// load locale and prefs
|
||||||
|
@ -414,6 +377,33 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
WidgetsBinding.instance.window.onPlatformBrightnessChanged = () {
|
||||||
|
StackColorTheme colorTheme;
|
||||||
|
switch (WidgetsBinding.instance.window.platformBrightness) {
|
||||||
|
case Brightness.dark:
|
||||||
|
colorTheme = ref
|
||||||
|
.read(prefsChangeNotifierProvider)
|
||||||
|
.systemBrightnessDarkTheme
|
||||||
|
.colorTheme;
|
||||||
|
break;
|
||||||
|
case Brightness.light:
|
||||||
|
colorTheme = ref
|
||||||
|
.read(prefsChangeNotifierProvider)
|
||||||
|
.systemBrightnessLightTheme
|
||||||
|
.colorTheme;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
print("=============================================================");
|
||||||
|
print("colorTheme: $colorTheme");
|
||||||
|
print("=============================================================");
|
||||||
|
|
||||||
|
ref.read(colorThemeProvider.notifier).state =
|
||||||
|
StackColors.fromStackColorTheme(colorTheme);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:stackwallet/hive/db.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:stackwallet/providers/providers.dart';
|
import 'package:stackwallet/providers/providers.dart';
|
||||||
import 'package:stackwallet/providers/ui/color_theme_provider.dart';
|
import 'package:stackwallet/providers/ui/color_theme_provider.dart';
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
|
@ -11,7 +11,10 @@ import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
||||||
import 'package:stackwallet/widgets/background.dart';
|
import 'package:stackwallet/widgets/background.dart';
|
||||||
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
|
||||||
import 'package:stackwallet/widgets/custom_buttons/draggable_switch_button.dart';
|
import 'package:stackwallet/widgets/custom_buttons/draggable_switch_button.dart';
|
||||||
|
import 'package:stackwallet/widgets/expandable.dart';
|
||||||
|
import 'package:stackwallet/widgets/rounded_container.dart';
|
||||||
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
import 'package:stackwallet/widgets/rounded_white_container.dart';
|
||||||
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
class AppearanceSettingsView extends ConsumerWidget {
|
class AppearanceSettingsView extends ConsumerWidget {
|
||||||
const AppearanceSettingsView({Key? key}) : super(key: key);
|
const AppearanceSettingsView({Key? key}) : super(key: key);
|
||||||
|
@ -101,57 +104,7 @@ class AppearanceSettingsView extends ConsumerWidget {
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 10,
|
height: 10,
|
||||||
),
|
),
|
||||||
RoundedWhiteContainer(
|
const SystemBrightnessToggle(),
|
||||||
child: Consumer(
|
|
||||||
builder: (_, ref, __) {
|
|
||||||
return RawMaterialButton(
|
|
||||||
splashColor: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.highlight,
|
|
||||||
materialTapTargetSize:
|
|
||||||
MaterialTapTargetSize.shrinkWrap,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(
|
|
||||||
Constants.size.circularBorderRadius,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressed: null,
|
|
||||||
child: Padding(
|
|
||||||
padding:
|
|
||||||
const EdgeInsets.symmetric(vertical: 8),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"System brightness",
|
|
||||||
style: STextStyles.titleBold12(context),
|
|
||||||
textAlign: TextAlign.left,
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
height: 20,
|
|
||||||
width: 40,
|
|
||||||
child: DraggableSwitchButton(
|
|
||||||
isOn: ref.watch(
|
|
||||||
prefsChangeNotifierProvider.select(
|
|
||||||
(value) => value
|
|
||||||
.enableSystemBrightness),
|
|
||||||
),
|
|
||||||
onValueChanged: (newValue) {
|
|
||||||
ref
|
|
||||||
.read(
|
|
||||||
prefsChangeNotifierProvider)
|
|
||||||
.enableSystemBrightness = newValue;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (!ref.watch(
|
if (!ref.watch(
|
||||||
prefsChangeNotifierProvider
|
prefsChangeNotifierProvider
|
||||||
.select((value) => value.enableSystemBrightness),
|
.select((value) => value.enableSystemBrightness),
|
||||||
|
@ -214,6 +167,238 @@ class AppearanceSettingsView extends ConsumerWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SystemBrightnessToggle extends ConsumerStatefulWidget {
|
||||||
|
const SystemBrightnessToggle({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
ConsumerState<SystemBrightnessToggle> createState() =>
|
||||||
|
_SystemBrightnessToggleState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SystemBrightnessToggleState
|
||||||
|
extends ConsumerState<SystemBrightnessToggle> {
|
||||||
|
final controller = ExpandableController();
|
||||||
|
|
||||||
|
void _toggle(bool enable) {
|
||||||
|
ref.read(prefsChangeNotifierProvider).enableSystemBrightness = enable;
|
||||||
|
|
||||||
|
if (enable && controller.state == ExpandableState.collapsed) {
|
||||||
|
controller.toggle?.call();
|
||||||
|
} else if (!enable && controller.state == ExpandableState.expanded) {
|
||||||
|
controller.toggle?.call();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enable) {
|
||||||
|
final ThemeType type;
|
||||||
|
switch (MediaQuery.of(context).platformBrightness) {
|
||||||
|
case Brightness.dark:
|
||||||
|
type = ref
|
||||||
|
.read(prefsChangeNotifierProvider.notifier)
|
||||||
|
.systemBrightnessDarkTheme;
|
||||||
|
break;
|
||||||
|
case Brightness.light:
|
||||||
|
type = ref
|
||||||
|
.read(prefsChangeNotifierProvider.notifier)
|
||||||
|
.systemBrightnessLightTheme;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ref.read(colorThemeProvider.notifier).state =
|
||||||
|
StackColors.fromStackColorTheme(
|
||||||
|
type.colorTheme,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
ref.read(prefsChangeNotifierProvider.notifier).theme =
|
||||||
|
ref.read(colorThemeProvider.notifier).state.themeType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
if (ref.read(prefsChangeNotifierProvider).enableSystemBrightness) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
controller.toggle?.call();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final enable = ref.watch(
|
||||||
|
prefsChangeNotifierProvider
|
||||||
|
.select((value) => value.enableSystemBrightness),
|
||||||
|
);
|
||||||
|
|
||||||
|
return RoundedWhiteContainer(
|
||||||
|
child: Expandable(
|
||||||
|
controller: controller,
|
||||||
|
expandOverride: () {
|
||||||
|
_toggle(
|
||||||
|
!ref.read(prefsChangeNotifierProvider).enableSystemBrightness);
|
||||||
|
},
|
||||||
|
header: RawMaterialButton(
|
||||||
|
splashColor: Theme.of(context).extension<StackColors>()!.highlight,
|
||||||
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(
|
||||||
|
Constants.size.circularBorderRadius,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onPressed: null,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"System brightness",
|
||||||
|
style: STextStyles.titleBold12(context),
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
key: Key("${enable}enableSystemBrightnessToggleKey"),
|
||||||
|
height: 20,
|
||||||
|
width: 40,
|
||||||
|
child: DraggableSwitchButton(
|
||||||
|
isOn: enable,
|
||||||
|
onValueChanged: _toggle,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
body: Column(
|
||||||
|
children: [
|
||||||
|
RoundedContainer(
|
||||||
|
color: Colors.transparent,
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
onPressed: () async {
|
||||||
|
final result = await Navigator.of(context).pushNamed(
|
||||||
|
SystemBrightnessThemeSelectionView.routeName,
|
||||||
|
arguments: Tuple2(
|
||||||
|
"light",
|
||||||
|
ref
|
||||||
|
.read(prefsChangeNotifierProvider)
|
||||||
|
.systemBrightnessLightTheme),
|
||||||
|
);
|
||||||
|
if (result is ThemeType) {
|
||||||
|
ref
|
||||||
|
.read(prefsChangeNotifierProvider)
|
||||||
|
.systemBrightnessLightTheme = result;
|
||||||
|
if (ref
|
||||||
|
.read(prefsChangeNotifierProvider)
|
||||||
|
.enableSystemBrightness) {
|
||||||
|
if (mounted &&
|
||||||
|
MediaQuery.of(context).platformBrightness ==
|
||||||
|
Brightness.light) {
|
||||||
|
ref.read(colorThemeProvider.notifier).state =
|
||||||
|
StackColors.fromStackColorTheme(result.colorTheme);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"Light theme",
|
||||||
|
style: STextStyles.itemSubtitle(context),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 2,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
ref
|
||||||
|
.watch(
|
||||||
|
prefsChangeNotifierProvider.select((value) =>
|
||||||
|
value.systemBrightnessLightTheme),
|
||||||
|
)
|
||||||
|
.prettyName,
|
||||||
|
style: STextStyles.itemSubtitle12(context),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SvgPicture.asset(
|
||||||
|
Assets.svg.chevronRight,
|
||||||
|
color: Theme.of(context).extension<StackColors>()!.textDark,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
RoundedContainer(
|
||||||
|
color: Colors.transparent,
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
onPressed: () async {
|
||||||
|
final result = await Navigator.of(context).pushNamed(
|
||||||
|
SystemBrightnessThemeSelectionView.routeName,
|
||||||
|
arguments: Tuple2(
|
||||||
|
"dark",
|
||||||
|
ref
|
||||||
|
.read(prefsChangeNotifierProvider)
|
||||||
|
.systemBrightnessDarkTheme),
|
||||||
|
);
|
||||||
|
if (result is ThemeType) {
|
||||||
|
ref
|
||||||
|
.read(prefsChangeNotifierProvider)
|
||||||
|
.systemBrightnessDarkTheme = result;
|
||||||
|
if (ref
|
||||||
|
.read(prefsChangeNotifierProvider)
|
||||||
|
.enableSystemBrightness) {
|
||||||
|
if (mounted &&
|
||||||
|
MediaQuery.of(context).platformBrightness ==
|
||||||
|
Brightness.dark) {
|
||||||
|
ref.read(colorThemeProvider.notifier).state =
|
||||||
|
StackColors.fromStackColorTheme(result.colorTheme);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"Dark theme",
|
||||||
|
style: STextStyles.itemSubtitle(context),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 2,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
ref.watch(
|
||||||
|
prefsChangeNotifierProvider.select((value) =>
|
||||||
|
value.systemBrightnessDarkTheme.prettyName),
|
||||||
|
),
|
||||||
|
style: STextStyles.itemSubtitle12(context),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SvgPicture.asset(
|
||||||
|
Assets.svg.chevronRight,
|
||||||
|
color: Theme.of(context).extension<StackColors>()!.textDark,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ThemeOptionsView extends ConsumerWidget {
|
class ThemeOptionsView extends ConsumerWidget {
|
||||||
const ThemeOptionsView({Key? key}) : super(key: key);
|
const ThemeOptionsView({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@ -228,12 +413,9 @@ class ThemeOptionsView extends ConsumerWidget {
|
||||||
)
|
)
|
||||||
: ThemeOption(
|
: ThemeOption(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
DB.instance.put<dynamic>(
|
ref.read(prefsChangeNotifierProvider.notifier).theme =
|
||||||
boxName: DB.boxNameTheme,
|
ThemeType.values[i ~/ 2];
|
||||||
key: "colorScheme",
|
ref.read(colorThemeProvider.notifier).state =
|
||||||
value: ThemeType.values[i ~/ 2].name,
|
|
||||||
);
|
|
||||||
ref.read(colorThemeProvider.state).state =
|
|
||||||
StackColors.fromStackColorTheme(
|
StackColors.fromStackColorTheme(
|
||||||
ThemeType.values[i ~/ 2].colorTheme,
|
ThemeType.values[i ~/ 2].colorTheme,
|
||||||
);
|
);
|
||||||
|
@ -241,12 +423,9 @@ class ThemeOptionsView extends ConsumerWidget {
|
||||||
},
|
},
|
||||||
onChanged: (newValue) {
|
onChanged: (newValue) {
|
||||||
if (newValue == ThemeType.values[i ~/ 2]) {
|
if (newValue == ThemeType.values[i ~/ 2]) {
|
||||||
DB.instance.put<dynamic>(
|
ref.read(prefsChangeNotifierProvider.notifier).theme =
|
||||||
boxName: DB.boxNameTheme,
|
ThemeType.values[i ~/ 2];
|
||||||
key: "colorScheme",
|
ref.read(colorThemeProvider.notifier).state =
|
||||||
value: ThemeType.values[i ~/ 2].name,
|
|
||||||
);
|
|
||||||
ref.read(colorThemeProvider.state).state =
|
|
||||||
StackColors.fromStackColorTheme(
|
StackColors.fromStackColorTheme(
|
||||||
ThemeType.values[i ~/ 2].colorTheme,
|
ThemeType.values[i ~/ 2].colorTheme,
|
||||||
);
|
);
|
||||||
|
@ -326,3 +505,124 @@ class ThemeOption extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SystemBrightnessThemeSelectionView extends StatelessWidget {
|
||||||
|
const SystemBrightnessThemeSelectionView({
|
||||||
|
Key? key,
|
||||||
|
required this.brightness,
|
||||||
|
required this.current,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
final String brightness;
|
||||||
|
final ThemeType current;
|
||||||
|
|
||||||
|
static const String routeName = "/chooseSystemTheme";
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Background(
|
||||||
|
child: Scaffold(
|
||||||
|
backgroundColor: Theme.of(context).extension<StackColors>()!.background,
|
||||||
|
appBar: AppBar(
|
||||||
|
leading: AppBarBackButton(
|
||||||
|
onPressed: () async {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
"Choose $brightness theme",
|
||||||
|
style: STextStyles.navBarTitle(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
body: Padding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
return SingleChildScrollView(
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(
|
||||||
|
minHeight: constraints.maxHeight,
|
||||||
|
),
|
||||||
|
child: IntrinsicHeight(
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
RoundedWhiteContainer(
|
||||||
|
padding: const EdgeInsets.all(0),
|
||||||
|
child: RawMaterialButton(
|
||||||
|
// splashColor: Theme.of(context).extension<StackColors>()!.highlight,
|
||||||
|
padding: const EdgeInsets.all(0),
|
||||||
|
materialTapTargetSize:
|
||||||
|
MaterialTapTargetSize.shrinkWrap,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(
|
||||||
|
Constants.size.circularBorderRadius,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onPressed: null,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Column(
|
||||||
|
crossAxisAlignment:
|
||||||
|
CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(10),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
for (int i = 0;
|
||||||
|
i <
|
||||||
|
(2 *
|
||||||
|
ThemeType.values
|
||||||
|
.length) -
|
||||||
|
1;
|
||||||
|
i++)
|
||||||
|
(i % 2 == 1)
|
||||||
|
? const SizedBox(
|
||||||
|
height: 10,
|
||||||
|
)
|
||||||
|
: ThemeOption(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context)
|
||||||
|
.pop(ThemeType
|
||||||
|
.values[
|
||||||
|
i ~/ 2]);
|
||||||
|
},
|
||||||
|
onChanged: (newValue) {
|
||||||
|
if (newValue ==
|
||||||
|
ThemeType.values[
|
||||||
|
i ~/ 2]) {
|
||||||
|
Navigator.of(context)
|
||||||
|
.pop(ThemeType
|
||||||
|
.values[
|
||||||
|
i ~/ 2]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
value: ThemeType
|
||||||
|
.values[i ~/ 2],
|
||||||
|
groupValue: current,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:stackwallet/hive/db.dart';
|
|
||||||
import 'package:stackwallet/providers/global/prefs_provider.dart';
|
import 'package:stackwallet/providers/global/prefs_provider.dart';
|
||||||
import 'package:stackwallet/providers/ui/color_theme_provider.dart';
|
import 'package:stackwallet/providers/ui/color_theme_provider.dart';
|
||||||
import 'package:stackwallet/utilities/assets.dart';
|
import 'package:stackwallet/utilities/assets.dart';
|
||||||
|
@ -232,14 +231,12 @@ class _ThemeToggle extends ConsumerState<ThemeToggle> {
|
||||||
cursor: SystemMouseCursors.click,
|
cursor: SystemMouseCursors.click,
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (ref.read(colorThemeProvider.state).state.themeType !=
|
if (ref.read(colorThemeProvider.notifier).state.themeType !=
|
||||||
ThemeType.values[i]) {
|
ThemeType.values[i]) {
|
||||||
DB.instance.put<dynamic>(
|
ref.read(prefsChangeNotifierProvider.notifier).theme =
|
||||||
boxName: DB.boxNameTheme,
|
ThemeType.values[i];
|
||||||
key: "colorScheme",
|
|
||||||
value: ThemeType.values[i].name,
|
ref.read(colorThemeProvider.notifier).state =
|
||||||
);
|
|
||||||
ref.read(colorThemeProvider.state).state =
|
|
||||||
StackColors.fromStackColorTheme(
|
StackColors.fromStackColorTheme(
|
||||||
ThemeType.values[i].colorTheme);
|
ThemeType.values[i].colorTheme);
|
||||||
}
|
}
|
||||||
|
@ -255,7 +252,7 @@ class _ThemeToggle extends ConsumerState<ThemeToggle> {
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
width: 2.5,
|
width: 2.5,
|
||||||
color: ref
|
color: ref
|
||||||
.read(colorThemeProvider.state)
|
.read(colorThemeProvider.notifier)
|
||||||
.state
|
.state
|
||||||
.themeType ==
|
.themeType ==
|
||||||
ThemeType.values[i]
|
ThemeType.values[i]
|
||||||
|
|
|
@ -133,6 +133,7 @@ import 'package:stackwallet/services/event_bus/events/global/node_connection_sta
|
||||||
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart';
|
||||||
import 'package:stackwallet/utilities/enums/add_wallet_type_enum.dart';
|
import 'package:stackwallet/utilities/enums/add_wallet_type_enum.dart';
|
||||||
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
import 'package:stackwallet/utilities/enums/coin_enum.dart';
|
||||||
|
import 'package:stackwallet/utilities/theme/color_theme.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
|
|
||||||
class RouteGenerator {
|
class RouteGenerator {
|
||||||
|
@ -640,6 +641,21 @@ class RouteGenerator {
|
||||||
}
|
}
|
||||||
return _routeError("${settings.name} invalid args: ${args.toString()}");
|
return _routeError("${settings.name} invalid args: ${args.toString()}");
|
||||||
|
|
||||||
|
case SystemBrightnessThemeSelectionView.routeName:
|
||||||
|
if (args is Tuple2<String, ThemeType>) {
|
||||||
|
return getRoute(
|
||||||
|
shouldUseMaterialRoute: useMaterialPageRoute,
|
||||||
|
builder: (_) => SystemBrightnessThemeSelectionView(
|
||||||
|
brightness: args.item1,
|
||||||
|
current: args.item2,
|
||||||
|
),
|
||||||
|
settings: RouteSettings(
|
||||||
|
name: settings.name,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _routeError("${settings.name} invalid args: ${args.toString()}");
|
||||||
|
|
||||||
case WalletNetworkSettingsView.routeName:
|
case WalletNetworkSettingsView.routeName:
|
||||||
if (args is Tuple3<String, WalletSyncStatus, NodeConnectionStatus>) {
|
if (args is Tuple3<String, WalletSyncStatus, NodeConnectionStatus>) {
|
||||||
return getRoute(
|
return getRoute(
|
||||||
|
|
|
@ -41,7 +41,7 @@ abstract class Constants {
|
||||||
// Enable Logger.print statements
|
// Enable Logger.print statements
|
||||||
static const bool disableLogger = false;
|
static const bool disableLogger = false;
|
||||||
|
|
||||||
static const int currentHiveDbVersion = 5;
|
static const int currentHiveDbVersion = 6;
|
||||||
|
|
||||||
static const int rescanV1 = 1;
|
static const int rescanV1 = 1;
|
||||||
|
|
||||||
|
|
|
@ -185,6 +185,26 @@ class DbVersionMigrator with WalletDB {
|
||||||
// try to continue migrating
|
// try to continue migrating
|
||||||
return await migrate(5, secureStore: secureStore);
|
return await migrate(5, secureStore: secureStore);
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
// migrate
|
||||||
|
await Hive.openBox<dynamic>("theme");
|
||||||
|
await Hive.openBox<dynamic>(DB.boxNamePrefs);
|
||||||
|
|
||||||
|
final themeName =
|
||||||
|
DB.instance.get<dynamic>(boxName: "theme", key: "colorScheme")
|
||||||
|
as String? ??
|
||||||
|
"light";
|
||||||
|
|
||||||
|
await DB.instance.put<dynamic>(
|
||||||
|
boxName: DB.boxNamePrefs, key: "theme", value: themeName);
|
||||||
|
|
||||||
|
// update version
|
||||||
|
await DB.instance.put<dynamic>(
|
||||||
|
boxName: DB.boxNameDBInfo, key: "hive_data_version", value: 6);
|
||||||
|
|
||||||
|
// try to continue migrating
|
||||||
|
return await migrate(6, secureStore: secureStore);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// finally return
|
// finally return
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -21,7 +21,7 @@ Future<bool> deleteEverything() async {
|
||||||
.deleteBoxFromDisk(boxName: DB.boxNameWalletsToDeleteOnStart);
|
.deleteBoxFromDisk(boxName: DB.boxNameWalletsToDeleteOnStart);
|
||||||
await DB.instance.deleteBoxFromDisk(boxName: DB.boxNamePriceCache);
|
await DB.instance.deleteBoxFromDisk(boxName: DB.boxNamePriceCache);
|
||||||
await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameDBInfo);
|
await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameDBInfo);
|
||||||
await DB.instance.deleteBoxFromDisk(boxName: DB.boxNameTheme);
|
await DB.instance.deleteBoxFromDisk(boxName: "theme");
|
||||||
return true;
|
return true;
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logging.instance.log("$e $s", level: LogLevel.Error);
|
Logging.instance.log("$e $s", level: LogLevel.Error);
|
||||||
|
|
|
@ -43,6 +43,7 @@ class Prefs extends ChangeNotifier {
|
||||||
_signupEpoch = await _getSignupEpoch();
|
_signupEpoch = await _getSignupEpoch();
|
||||||
_enableCoinControl = await _getEnableCoinControl();
|
_enableCoinControl = await _getEnableCoinControl();
|
||||||
_enableSystemBrightness = await _getEnableSystemBrightness();
|
_enableSystemBrightness = await _getEnableSystemBrightness();
|
||||||
|
_theme = await _getTheme();
|
||||||
_systemBrightnessLightTheme = await _getSystemBrightnessLightTheme();
|
_systemBrightnessLightTheme = await _getSystemBrightnessLightTheme();
|
||||||
_systemBrightnessDarkTheme = await _getSystemBrightnessDarkTheme();
|
_systemBrightnessDarkTheme = await _getSystemBrightnessDarkTheme();
|
||||||
|
|
||||||
|
@ -699,49 +700,70 @@ class Prefs extends ChangeNotifier {
|
||||||
|
|
||||||
// system brightness light theme name
|
// system brightness light theme name
|
||||||
|
|
||||||
String _systemBrightnessLightTheme = ThemeType.light.name;
|
ThemeType _theme = ThemeType.light;
|
||||||
|
|
||||||
String get systemBrightnessLightTheme => _systemBrightnessLightTheme;
|
ThemeType get theme => _theme;
|
||||||
|
|
||||||
set systemBrightnessLightTheme(String systemBrightnessLightTheme) {
|
set theme(ThemeType theme) {
|
||||||
|
if (this.theme != theme) {
|
||||||
|
DB.instance.put<dynamic>(
|
||||||
|
boxName: DB.boxNamePrefs, key: "theme", value: theme.name);
|
||||||
|
_theme = theme;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<ThemeType> _getTheme() async {
|
||||||
|
return ThemeTypeExt.fromName(await DB.instance
|
||||||
|
.get<dynamic>(boxName: DB.boxNamePrefs, key: "theme") as String? ??
|
||||||
|
ThemeType.light.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// system brightness light theme name
|
||||||
|
|
||||||
|
ThemeType _systemBrightnessLightTheme = ThemeType.light;
|
||||||
|
|
||||||
|
ThemeType get systemBrightnessLightTheme => _systemBrightnessLightTheme;
|
||||||
|
|
||||||
|
set systemBrightnessLightTheme(ThemeType systemBrightnessLightTheme) {
|
||||||
if (this.systemBrightnessLightTheme != systemBrightnessLightTheme) {
|
if (this.systemBrightnessLightTheme != systemBrightnessLightTheme) {
|
||||||
DB.instance.put<dynamic>(
|
DB.instance.put<dynamic>(
|
||||||
boxName: DB.boxNamePrefs,
|
boxName: DB.boxNamePrefs,
|
||||||
key: "systemBrightnessLightTheme",
|
key: "systemBrightnessLightTheme",
|
||||||
value: systemBrightnessLightTheme);
|
value: systemBrightnessLightTheme.name);
|
||||||
_systemBrightnessLightTheme = systemBrightnessLightTheme;
|
_systemBrightnessLightTheme = systemBrightnessLightTheme;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> _getSystemBrightnessLightTheme() async {
|
Future<ThemeType> _getSystemBrightnessLightTheme() async {
|
||||||
return await DB.instance.get<dynamic>(
|
return ThemeTypeExt.fromName(await DB.instance.get<dynamic>(
|
||||||
boxName: DB.boxNamePrefs,
|
boxName: DB.boxNamePrefs,
|
||||||
key: "systemBrightnessLightTheme") as String? ??
|
key: "systemBrightnessLightTheme") as String? ??
|
||||||
ThemeType.light.name;
|
ThemeType.light.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// system brightness dark theme name
|
// system brightness dark theme name
|
||||||
|
|
||||||
String _systemBrightnessDarkTheme = ThemeType.dark.name;
|
ThemeType _systemBrightnessDarkTheme = ThemeType.dark;
|
||||||
|
|
||||||
String get systemBrightnessDarkTheme => _systemBrightnessDarkTheme;
|
ThemeType get systemBrightnessDarkTheme => _systemBrightnessDarkTheme;
|
||||||
|
|
||||||
set systemBrightnessDarkTheme(String systemBrightnessDarkTheme) {
|
set systemBrightnessDarkTheme(ThemeType systemBrightnessDarkTheme) {
|
||||||
if (this.systemBrightnessDarkTheme != systemBrightnessDarkTheme) {
|
if (this.systemBrightnessDarkTheme != systemBrightnessDarkTheme) {
|
||||||
DB.instance.put<dynamic>(
|
DB.instance.put<dynamic>(
|
||||||
boxName: DB.boxNamePrefs,
|
boxName: DB.boxNamePrefs,
|
||||||
key: "systemBrightnessDarkTheme",
|
key: "systemBrightnessDarkTheme",
|
||||||
value: systemBrightnessDarkTheme);
|
value: systemBrightnessDarkTheme.name);
|
||||||
_systemBrightnessDarkTheme = systemBrightnessDarkTheme;
|
_systemBrightnessDarkTheme = systemBrightnessDarkTheme;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> _getSystemBrightnessDarkTheme() async {
|
Future<ThemeType> _getSystemBrightnessDarkTheme() async {
|
||||||
return await DB.instance.get<dynamic>(
|
return ThemeTypeExt.fromName(await DB.instance.get<dynamic>(
|
||||||
boxName: DB.boxNamePrefs,
|
boxName: DB.boxNamePrefs,
|
||||||
key: "systemBrightnessDarkTheme") as String? ??
|
key: "systemBrightnessDarkTheme") as String? ??
|
||||||
ThemeType.dark.name;
|
ThemeType.dark.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,29 @@ enum ThemeType {
|
||||||
// adjust this file
|
// adjust this file
|
||||||
|
|
||||||
extension ThemeTypeExt on ThemeType {
|
extension ThemeTypeExt on ThemeType {
|
||||||
|
static ThemeType fromName(String name) {
|
||||||
|
switch (name) {
|
||||||
|
case "light":
|
||||||
|
return ThemeType.light;
|
||||||
|
case "chan":
|
||||||
|
return ThemeType.chan;
|
||||||
|
case "dark":
|
||||||
|
return ThemeType.dark;
|
||||||
|
case "oceanBreeze":
|
||||||
|
return ThemeType.oceanBreeze;
|
||||||
|
case "oledBlack":
|
||||||
|
return ThemeType.oledBlack;
|
||||||
|
case "fruitSorbet":
|
||||||
|
return ThemeType.fruitSorbet;
|
||||||
|
case "forest":
|
||||||
|
return ThemeType.forest;
|
||||||
|
case "darkChans":
|
||||||
|
return ThemeType.darkChans;
|
||||||
|
default:
|
||||||
|
throw ArgumentError("Invalid theme name");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
StackColorTheme get colorTheme {
|
StackColorTheme get colorTheme {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case ThemeType.light:
|
case ThemeType.light:
|
||||||
|
|
Loading…
Reference in a new issue