desktop theme toggle

This commit is contained in:
julian 2022-11-07 15:48:16 -06:00
parent c962f597fd
commit b3a343d28a

View file

@ -1,16 +1,19 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.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/ui/color_theme_provider.dart';
import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/color_theme.dart';
import 'package:stackwallet/utilities/theme/dark_colors.dart';
import 'package:stackwallet/utilities/theme/light_colors.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/custom_buttons/draggable_switch_button.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart';
import '../../../providers/global/prefs_provider.dart';
import '../../../utilities/constants.dart';
import '../../../widgets/custom_buttons/draggable_switch_button.dart';
class AppearanceOptionSettings extends ConsumerStatefulWidget { class AppearanceOptionSettings extends ConsumerStatefulWidget {
const AppearanceOptionSettings({Key? key}) : super(key: key); const AppearanceOptionSettings({Key? key}) : super(key: key);
@ -140,7 +143,10 @@ class _AppearanceOptionSettings
], ],
), ),
), ),
ThemeToggle(), const Padding(
padding: EdgeInsets.all(10),
child: ThemeToggle(),
),
], ],
), ),
), ),
@ -150,7 +156,7 @@ class _AppearanceOptionSettings
} }
} }
class ThemeToggle extends StatefulWidget { class ThemeToggle extends ConsumerStatefulWidget {
const ThemeToggle({ const ThemeToggle({
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -159,190 +165,229 @@ class ThemeToggle extends StatefulWidget {
// final void Function(bool)? onChanged; // final void Function(bool)? onChanged;
@override @override
State<StatefulWidget> createState() => _ThemeToggle(); ConsumerState<ThemeToggle> createState() => _ThemeToggle();
} }
class _ThemeToggle extends State<ThemeToggle> { class _ThemeToggle extends ConsumerState<ThemeToggle> {
// late bool externalCallsEnabled; // late bool externalCallsEnabled;
late String _selectedTheme;
@override
void initState() {
_selectedTheme =
DB.instance.get<dynamic>(boxName: DB.boxNameTheme, key: "colorScheme")
as String? ??
"light";
super.initState();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Row( return Row(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
Padding( MaterialButton(
padding: const EdgeInsets.all(8.0), splashColor: Colors.transparent,
child: RawMaterialButton(
elevation: 0,
hoverColor: Colors.transparent, hoverColor: Colors.transparent,
padding: const EdgeInsets.all(0),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
side: BorderSide(
color:
Theme.of(context).extension<StackColors>()!.infoItemIcons,
width: 2,
),
// side: !externalCallsEnabled
// ? BorderSide.none
// : BorderSide(
// color: Theme.of(context)
// .extension<StackColors>()!
// .infoItemIcons,
// width: 2,
// ),
borderRadius: BorderRadius.circular( borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius * 2, Constants.size.circularBorderRadius,
), ),
), ),
onPressed: () {}, //onPressed onPressed: () {
child: Padding( DB.instance.put<dynamic>(
padding: const EdgeInsets.all(8.0), boxName: DB.boxNameTheme,
child: Stack( key: "colorScheme",
value: ThemeType.light.name,
);
ref.read(colorThemeProvider.state).state =
StackColors.fromStackColorTheme(
LightColors(),
);
setState(() {
_selectedTheme = "light";
});
},
child: SizedBox(
width: 200,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [ children: [
Column( Container(
crossAxisAlignment: CrossAxisAlignment.start, decoration: BoxDecoration(
children: [ border: Border.all(
Padding( width: 2.5,
padding: const EdgeInsets.only( color: _selectedTheme == "light"
left: 24, ? Theme.of(context)
.extension<StackColors>()!
.infoItemIcons
: Theme.of(context).extension<StackColors>()!.popupBG,
),
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
), ),
child: SvgPicture.asset( child: SvgPicture.asset(
Assets.svg.themeLight, Assets.svg.themeLight,
), ),
), ),
Padding( const SizedBox(
padding: const EdgeInsets.only( height: 12,
left: 50,
top: 12,
), ),
child: Text( Row(
children: [
SizedBox(
width: 20,
height: 20,
child: Radio(
activeColor: Theme.of(context)
.extension<StackColors>()!
.radioButtonIconEnabled,
value: "light",
groupValue: _selectedTheme,
onChanged: (newValue) {
if (newValue is String && newValue == "light") {
DB.instance.put<dynamic>(
boxName: DB.boxNameTheme,
key: "colorScheme",
value: ThemeType.light.name,
);
ref.read(colorThemeProvider.state).state =
StackColors.fromStackColorTheme(
LightColors(),
);
setState(() {
_selectedTheme = "light";
});
}
},
),
),
const SizedBox(
width: 14,
),
Text(
"Light", "Light",
style: STextStyles.desktopTextExtraSmall(context) style:
.copyWith( STextStyles.desktopTextExtraSmall(context).copyWith(
color: Theme.of(context) color: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
.textDark, .textDark,
), ),
), ),
)
], ],
), ),
// if (externalCallsEnabled)
Positioned(
bottom: 0,
left: 6,
child: SvgPicture.asset(
Assets.svg.checkCircle,
width: 20,
height: 20,
color: Theme.of(context)
.extension<StackColors>()!
.infoItemIcons,
),
),
// if (!externalCallsEnabled)
// Positioned(
// bottom: 0,
// left: 6,
// child: Container(
// width: 20,
// height: 20,
// decoration: BoxDecoration(
// borderRadius: BorderRadius.circular(1000),
// color: Theme.of(context)
// .extension<StackColors>()!
// .textFieldDefaultBG,
// ),
// ),
// ),
], ],
), ),
), ),
), ),
),
const SizedBox( const SizedBox(
width: 1, width: 20,
), ),
Expanded( MaterialButton(
child: Padding( splashColor: Colors.transparent,
padding: const EdgeInsets.all(8.0),
child: RawMaterialButton(
elevation: 0,
hoverColor: Colors.transparent, hoverColor: Colors.transparent,
padding: const EdgeInsets.all(0),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
// side: !externalCallsEnabled
// ? BorderSide.none
// : BorderSide(
// color: Theme.of(context)
// .extension<StackColors>()!
// .infoItemIcons,
// width: 2,
// ),
borderRadius: BorderRadius.circular( borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius * 2, Constants.size.circularBorderRadius,
), ),
), ),
onPressed: () {}, //onPressed onPressed: () {
child: Padding( DB.instance.put<dynamic>(
padding: const EdgeInsets.all(8.0), boxName: DB.boxNameTheme,
child: Stack( key: "colorScheme",
value: ThemeType.dark.name,
);
ref.read(colorThemeProvider.state).state =
StackColors.fromStackColorTheme(
DarkColors(),
);
setState(() {
_selectedTheme = "dark";
});
},
child: SizedBox(
width: 200,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [ children: [
Column( Container(
crossAxisAlignment: CrossAxisAlignment.start, decoration: BoxDecoration(
children: [ border: Border.all(
SvgPicture.asset( width: 2.5,
color: _selectedTheme == "dark"
? Theme.of(context)
.extension<StackColors>()!
.infoItemIcons
: Theme.of(context).extension<StackColors>()!.popupBG,
),
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
child: SvgPicture.asset(
Assets.svg.themeDark, Assets.svg.themeDark,
), ),
Padding(
padding: const EdgeInsets.only(
left: 45,
top: 12,
), ),
child: Text( const SizedBox(
height: 12,
),
Row(
children: [
SizedBox(
width: 20,
height: 20,
child: Radio(
activeColor: Theme.of(context)
.extension<StackColors>()!
.radioButtonIconEnabled,
value: "dark",
groupValue: _selectedTheme,
onChanged: (newValue) {
if (newValue is String && newValue == "dark") {
DB.instance.put<dynamic>(
boxName: DB.boxNameTheme,
key: "colorScheme",
value: ThemeType.dark.name,
);
ref.read(colorThemeProvider.state).state =
StackColors.fromStackColorTheme(
DarkColors(),
);
setState(() {
_selectedTheme = "dark";
});
}
},
),
),
const SizedBox(
width: 14,
),
Text(
"Dark", "Dark",
style: STextStyles.desktopTextExtraSmall(context) style:
.copyWith( STextStyles.desktopTextExtraSmall(context).copyWith(
color: Theme.of(context) color: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
.textDark, .textDark,
), ),
), ),
),
], ],
), ),
// if (externalCallsEnabled)
// Positioned(
// bottom: 0,
// left: 0,
// child: SvgPicture.asset(
// Assets.svg.checkCircle,
// width: 20,
// height: 20,
// color: Theme.of(context)
// .extension<StackColors>()!
// .infoItemIcons,
// ),
// ),
// if (!externalCallsEnabled)
Positioned(
bottom: 0,
left: 0,
child: Container(
width: 20,
height: 20,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(1000),
color: Theme.of(context)
.extension<StackColors>()!
.textFieldDefaultBG,
),
),
),
], ],
), ),
), ),
), ),
),
),
], ],
); );
} }