2022-10-26 14:26:09 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
|
|
|
|
import 'package:adguard_home_manager/screens/settings/customization/color_item.dart';
|
|
|
|
import 'package:adguard_home_manager/screens/settings/customization/theme_mode_button.dart';
|
|
|
|
|
|
|
|
import 'package:adguard_home_manager/widgets/custom_switch_list_tile.dart';
|
|
|
|
import 'package:adguard_home_manager/widgets/section_label.dart';
|
|
|
|
|
2023-10-29 02:47:14 +01:00
|
|
|
import 'package:adguard_home_manager/functions/generate_color_translation.dart';
|
|
|
|
import 'package:adguard_home_manager/functions/desktop_mode.dart';
|
2022-10-26 14:26:09 +02:00
|
|
|
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
|
|
|
import 'package:adguard_home_manager/constants/colors.dart';
|
|
|
|
|
|
|
|
class Customization extends StatelessWidget {
|
|
|
|
const Customization({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
|
|
|
|
|
|
|
return CustomizationWidget(
|
|
|
|
appConfigProvider: appConfigProvider
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CustomizationWidget extends StatefulWidget {
|
|
|
|
final AppConfigProvider appConfigProvider;
|
|
|
|
|
|
|
|
const CustomizationWidget({
|
|
|
|
Key? key,
|
|
|
|
required this.appConfigProvider,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<CustomizationWidget> createState() => _CustomizationWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CustomizationWidgetState extends State<CustomizationWidget> {
|
|
|
|
int selectedTheme = 0;
|
|
|
|
bool dynamicColor = true;
|
|
|
|
int selectedColor = 0;
|
2022-10-26 15:22:50 +02:00
|
|
|
bool useThemeColorInsteadGreenRed = false;
|
2022-10-26 14:26:09 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
2022-10-29 14:22:19 +02:00
|
|
|
selectedTheme = widget.appConfigProvider.selectedThemeNumber;
|
2022-10-26 14:26:09 +02:00
|
|
|
dynamicColor = widget.appConfigProvider.useDynamicColor;
|
|
|
|
selectedColor = widget.appConfigProvider.staticColor;
|
2022-10-26 15:22:50 +02:00
|
|
|
useThemeColorInsteadGreenRed = widget.appConfigProvider.useThemeColorForStatus;
|
2022-10-26 14:26:09 +02:00
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
|
|
|
|
2023-10-29 02:47:14 +01:00
|
|
|
final width = MediaQuery.of(context).size.width;
|
|
|
|
|
2022-10-26 14:26:09 +02:00
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(AppLocalizations.of(context)!.customization),
|
2023-03-16 23:29:18 +01:00
|
|
|
centerTitle: false,
|
2023-10-29 02:47:14 +01:00
|
|
|
surfaceTintColor: isDesktop(width) ? Colors.transparent : null,
|
2022-10-26 14:26:09 +02:00
|
|
|
),
|
|
|
|
body: ListView(
|
|
|
|
children: [
|
2022-10-29 14:22:19 +02:00
|
|
|
SectionLabel(
|
|
|
|
label: AppLocalizations.of(context)!.theme,
|
2022-11-05 03:56:04 +01:00
|
|
|
padding: const EdgeInsets.only(top: 10, left: 16, right: 16, bottom: 5),
|
2022-10-29 14:22:19 +02:00
|
|
|
),
|
|
|
|
Column(
|
2022-10-26 14:26:09 +02:00
|
|
|
children: [
|
2022-10-29 14:22:19 +02:00
|
|
|
CustomSwitchListTile(
|
|
|
|
value: selectedTheme == 0 ? true : false,
|
2022-10-26 14:26:09 +02:00
|
|
|
onChanged: (value) {
|
2022-10-29 14:22:19 +02:00
|
|
|
selectedTheme = value == true ? 0 : 1;
|
|
|
|
appConfigProvider.setSelectedTheme(value == true ? 0 : 1);
|
|
|
|
},
|
|
|
|
title: AppLocalizations.of(context)!.systemDefined,
|
2022-10-26 14:26:09 +02:00
|
|
|
),
|
2022-10-29 14:22:19 +02:00
|
|
|
const SizedBox(height: 10),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
children: [
|
|
|
|
ThemeModeButton(
|
|
|
|
icon: Icons.light_mode,
|
|
|
|
value: 1,
|
|
|
|
selected: selectedTheme,
|
|
|
|
label: AppLocalizations.of(context)!.light,
|
|
|
|
onChanged: (value) {
|
|
|
|
selectedTheme = value;
|
|
|
|
appConfigProvider.setSelectedTheme(value);
|
|
|
|
},
|
|
|
|
disabled: selectedTheme == 0 ? true : false,
|
|
|
|
),
|
|
|
|
ThemeModeButton(
|
|
|
|
icon: Icons.dark_mode,
|
|
|
|
value: 2,
|
|
|
|
selected: selectedTheme,
|
|
|
|
label: AppLocalizations.of(context)!.dark,
|
|
|
|
onChanged: (value) {
|
|
|
|
selectedTheme = value;
|
|
|
|
appConfigProvider.setSelectedTheme(value);
|
|
|
|
},
|
|
|
|
disabled: selectedTheme == 0 ? true : false,
|
|
|
|
),
|
|
|
|
],
|
2022-10-26 14:26:09 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SectionLabel(
|
|
|
|
label: AppLocalizations.of(context)!.color,
|
2022-11-05 03:56:04 +01:00
|
|
|
padding: const EdgeInsets.only(top: 45, left: 16, right: 16, bottom: 5),
|
2022-10-26 14:26:09 +02:00
|
|
|
),
|
2023-05-21 18:59:04 +02:00
|
|
|
if (appConfigProvider.androidDeviceInfo != null && appConfigProvider.androidDeviceInfo!.version.sdkInt >= 31) CustomSwitchListTile(
|
2022-10-26 14:26:09 +02:00
|
|
|
value: dynamicColor,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() => dynamicColor = value);
|
|
|
|
appConfigProvider.setUseDynamicColor(value);
|
|
|
|
},
|
|
|
|
title: AppLocalizations.of(context)!.useDynamicTheme,
|
|
|
|
),
|
2023-05-21 18:59:04 +02:00
|
|
|
if (!(appConfigProvider.androidDeviceInfo != null && appConfigProvider.androidDeviceInfo!.version.sdkInt >= 31)) const SizedBox(height: 20),
|
2022-10-26 14:26:09 +02:00
|
|
|
if (dynamicColor == false) ...[
|
|
|
|
SizedBox(
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
height: 70,
|
|
|
|
child: ListView.builder(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
itemCount: colors.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
if (index == 0) {
|
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
const SizedBox(width: 15),
|
|
|
|
ColorItem(
|
|
|
|
color: colors[index],
|
|
|
|
numericValue: index,
|
|
|
|
selectedValue: selectedColor,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() => selectedColor = value);
|
|
|
|
appConfigProvider.setStaticColor(value);
|
|
|
|
}
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 10),
|
|
|
|
width: 1,
|
|
|
|
height: 60,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.grey,
|
|
|
|
borderRadius: BorderRadius.circular(1)
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (index == colors.length-1) {
|
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
ColorItem(
|
|
|
|
color: colors[index],
|
|
|
|
numericValue: index,
|
|
|
|
selectedValue: selectedColor,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() => selectedColor = value);
|
|
|
|
appConfigProvider.setStaticColor(value);
|
|
|
|
}
|
|
|
|
),
|
|
|
|
const SizedBox(width: 15)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return ColorItem(
|
|
|
|
color: colors[index],
|
|
|
|
numericValue: index,
|
|
|
|
selectedValue: selectedColor,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() => selectedColor = value);
|
|
|
|
appConfigProvider.setStaticColor(value);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
left: 25,
|
|
|
|
top: 10
|
|
|
|
),
|
|
|
|
child: Text(
|
2022-10-26 15:22:50 +02:00
|
|
|
colorTranslation(context, selectedColor),
|
2022-10-26 14:26:09 +02:00
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).listTileTheme.iconColor,
|
|
|
|
fontSize: 16
|
|
|
|
),
|
|
|
|
),
|
2022-10-26 15:22:50 +02:00
|
|
|
)
|
|
|
|
],
|
|
|
|
CustomSwitchListTile(
|
|
|
|
value: useThemeColorInsteadGreenRed,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() => useThemeColorInsteadGreenRed = value);
|
|
|
|
appConfigProvider.setUseThemeColorForStatus(value);
|
|
|
|
},
|
|
|
|
title: AppLocalizations.of(context)!.useThemeColorStatus,
|
|
|
|
subtitle: AppLocalizations.of(context)!.useThemeColorStatusDescription,
|
2022-10-26 14:26:09 +02:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|