mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 01:37:54 +00:00
system brightness toggle WIP
This commit is contained in:
parent
d9d6a8c156
commit
75ea516005
4 changed files with 225 additions and 28 deletions
|
@ -8,6 +8,7 @@ import 'package:cw_core/wallet_info.dart';
|
|||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_libmonero/monero/monero.dart';
|
||||
import 'package:flutter_libmonero/wownero/wownero.dart';
|
||||
|
@ -56,6 +57,7 @@ import 'package:stackwallet/utilities/db_version_migration.dart';
|
|||
import 'package:stackwallet/utilities/enums/backup_frequency_type.dart';
|
||||
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
import 'package:stackwallet/utilities/prefs.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';
|
||||
|
@ -161,6 +163,8 @@ void main() async {
|
|||
(await StackFileSystem.applicationHiveDirectory()).path);
|
||||
|
||||
await Hive.openBox<dynamic>(DB.boxNameDBInfo);
|
||||
await Hive.openBox<dynamic>(DB.boxNamePrefs);
|
||||
await Prefs.instance.init();
|
||||
|
||||
// Desktop migrate handled elsewhere (currently desktop_login_view.dart)
|
||||
if (!Util.isDesktop) {
|
||||
|
@ -335,8 +339,25 @@ class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
|
|||
|
||||
@override
|
||||
void initState() {
|
||||
final colorScheme = DB.instance
|
||||
.get<dynamic>(boxName: DB.boxNameTheme, key: "colorScheme") as String?;
|
||||
final String? colorScheme;
|
||||
if (ref.read(prefsChangeNotifierProvider).enableSystemBrightness) {
|
||||
final brightness =
|
||||
SchedulerBinding.instance.platformDispatcher.platformBrightness;
|
||||
switch (brightness) {
|
||||
case Brightness.dark:
|
||||
colorScheme =
|
||||
ref.read(prefsChangeNotifierProvider).systemBrightnessDarkTheme;
|
||||
break;
|
||||
case Brightness.light:
|
||||
colorScheme =
|
||||
ref.read(prefsChangeNotifierProvider).systemBrightnessLightTheme;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
colorScheme =
|
||||
DB.instance.get<dynamic>(boxName: DB.boxNameTheme, key: "colorScheme")
|
||||
as String?;
|
||||
}
|
||||
|
||||
StackColorTheme colorTheme;
|
||||
switch (colorScheme) {
|
||||
|
|
|
@ -102,42 +102,105 @@ class AppearanceSettingsView extends ConsumerWidget {
|
|||
height: 10,
|
||||
),
|
||||
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,
|
||||
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(
|
||||
"Choose Theme",
|
||||
"System brightness",
|
||||
style: STextStyles.titleBold12(context),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: ThemeOptionsView(),
|
||||
),
|
||||
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(
|
||||
prefsChangeNotifierProvider
|
||||
.select((value) => value.enableSystemBrightness),
|
||||
))
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
if (!ref.watch(
|
||||
prefsChangeNotifierProvider
|
||||
.select((value) => value.enableSystemBrightness),
|
||||
))
|
||||
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: [
|
||||
Text(
|
||||
"Choose Theme",
|
||||
style:
|
||||
STextStyles.titleBold12(context),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: ThemeOptionsView(),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
@ -118,6 +118,44 @@ class _AppearanceOptionSettings
|
|||
thickness: 0.5,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
"System brightness",
|
||||
style: STextStyles.desktopTextExtraSmall(context)
|
||||
.copyWith(
|
||||
color: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.textDark),
|
||||
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;
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(10.0),
|
||||
child: Divider(
|
||||
thickness: 0.5,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Row(
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:stackwallet/utilities/constants.dart';
|
|||
import 'package:stackwallet/utilities/enums/backup_frequency_type.dart';
|
||||
import 'package:stackwallet/utilities/enums/languages_enum.dart';
|
||||
import 'package:stackwallet/utilities/enums/sync_type_enum.dart';
|
||||
import 'package:stackwallet/utilities/theme/color_theme.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class Prefs extends ChangeNotifier {
|
||||
|
@ -41,6 +42,9 @@ class Prefs extends ChangeNotifier {
|
|||
_userId = await _getUserId();
|
||||
_signupEpoch = await _getSignupEpoch();
|
||||
_enableCoinControl = await _getEnableCoinControl();
|
||||
_enableSystemBrightness = await _getEnableSystemBrightness();
|
||||
_systemBrightnessLightTheme = await _getSystemBrightnessLightTheme();
|
||||
_systemBrightnessDarkTheme = await _getSystemBrightnessDarkTheme();
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
@ -669,4 +673,75 @@ class Prefs extends ChangeNotifier {
|
|||
boxName: DB.boxNamePrefs, key: "enableCoinControl") as bool? ??
|
||||
false;
|
||||
}
|
||||
|
||||
// follow system brightness
|
||||
|
||||
bool _enableSystemBrightness = false;
|
||||
|
||||
bool get enableSystemBrightness => _enableSystemBrightness;
|
||||
|
||||
set enableSystemBrightness(bool enableSystemBrightness) {
|
||||
if (_enableSystemBrightness != enableSystemBrightness) {
|
||||
DB.instance.put<dynamic>(
|
||||
boxName: DB.boxNamePrefs,
|
||||
key: "enableSystemBrightness",
|
||||
value: enableSystemBrightness);
|
||||
_enableSystemBrightness = enableSystemBrightness;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _getEnableSystemBrightness() async {
|
||||
return await DB.instance.get<dynamic>(
|
||||
boxName: DB.boxNamePrefs, key: "enableSystemBrightness") as bool? ??
|
||||
false;
|
||||
}
|
||||
|
||||
// system brightness light theme name
|
||||
|
||||
String _systemBrightnessLightTheme = ThemeType.light.name;
|
||||
|
||||
String get systemBrightnessLightTheme => _systemBrightnessLightTheme;
|
||||
|
||||
set systemBrightnessLightTheme(String systemBrightnessLightTheme) {
|
||||
if (this.systemBrightnessLightTheme != systemBrightnessLightTheme) {
|
||||
DB.instance.put<dynamic>(
|
||||
boxName: DB.boxNamePrefs,
|
||||
key: "systemBrightnessLightTheme",
|
||||
value: systemBrightnessLightTheme);
|
||||
_systemBrightnessLightTheme = systemBrightnessLightTheme;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> _getSystemBrightnessLightTheme() async {
|
||||
return await DB.instance.get<dynamic>(
|
||||
boxName: DB.boxNamePrefs,
|
||||
key: "systemBrightnessLightTheme") as String? ??
|
||||
ThemeType.light.name;
|
||||
}
|
||||
|
||||
// system brightness dark theme name
|
||||
|
||||
String _systemBrightnessDarkTheme = ThemeType.dark.name;
|
||||
|
||||
String get systemBrightnessDarkTheme => _systemBrightnessDarkTheme;
|
||||
|
||||
set systemBrightnessDarkTheme(String systemBrightnessDarkTheme) {
|
||||
if (this.systemBrightnessDarkTheme != systemBrightnessDarkTheme) {
|
||||
DB.instance.put<dynamic>(
|
||||
boxName: DB.boxNamePrefs,
|
||||
key: "systemBrightnessDarkTheme",
|
||||
value: systemBrightnessDarkTheme);
|
||||
_systemBrightnessDarkTheme = systemBrightnessDarkTheme;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> _getSystemBrightnessDarkTheme() async {
|
||||
return await DB.instance.get<dynamic>(
|
||||
boxName: DB.boxNamePrefs,
|
||||
key: "systemBrightnessDarkTheme") as String? ??
|
||||
ThemeType.dark.name;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue