Skip to content

Commit

Permalink
Changed location of default theme variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 committed Jul 18, 2024
1 parent 9bea89e commit 8c40ba8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
13 changes: 6 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import 'package:elastic_dashboard/services/log.dart';
import 'package:elastic_dashboard/services/nt_connection.dart';
import 'package:elastic_dashboard/services/nt_widget_builder.dart';
import 'package:elastic_dashboard/services/settings.dart';
import 'package:elastic_dashboard/widgets/settings_dialog.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -191,7 +190,7 @@ class Elastic extends StatefulWidget {
class _ElasticState extends State<Elastic> {
late Color teamColor = Color(
widget.preferences.getInt(PrefKeys.teamColor) ?? Colors.blueAccent.value);
late FlexSchemeVariant flexSchemeVariant = FlexSchemeVariant.values
late FlexSchemeVariant themeVariant = FlexSchemeVariant.values
.firstWhereOrNull((element) =>
element.variantName ==
widget.preferences.getString(PrefKeys.themeVariant)) ??
Expand All @@ -204,7 +203,7 @@ class _ElasticState extends State<Elastic> {
colorScheme: SeedColorScheme.fromSeeds(
primaryKey: teamColor,
brightness: Brightness.dark,
variant: Settings.themeVariant,
variant: themeVariant,
),
);
return MaterialApp(
Expand All @@ -220,10 +219,10 @@ class _ElasticState extends State<Elastic> {
widget.preferences.setInt(PrefKeys.teamColor, color.value);
}),
onThemeVariantChanged: (variant) async {
flexSchemeVariant = variant;
if (variant == SettingsDialog.defaultVariant) {
await widget.preferences.setString(
PrefKeys.themeVariant, SettingsDialog.defaultVariantName);
themeVariant = variant;
if (variant == Defaults.themeVariant) {
await widget.preferences
.setString(PrefKeys.themeVariant, Defaults.defaultVariantName);
} else {
await widget.preferences
.setString(PrefKeys.themeVariant, variant.variantName);
Expand Down
13 changes: 3 additions & 10 deletions lib/services/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ class Settings {
'https://github.com/Gold872/elastic-dashboard';
static const String releasesLink = '$repositoryLink/releases/latest';

// static String ipAddress = '127.0.0.1';
// static int teamNumber = 9999;
// static int gridSize = 128;
// static bool layoutLocked = false;
// static double cornerRadius = 15.0;
// static bool showGrid = true;
// static bool autoResizeToDS = false;

static FlexSchemeVariant themeVariant = FlexSchemeVariant.material3Legacy;

// window_manager doesn't support drag disable/maximize
// disable on some platforms, this is a dumb workaround for it
static bool isWindowDraggable = true;
Expand All @@ -26,6 +16,9 @@ class Settings {
class Defaults {
static IPAddressMode ipAddressMode = IPAddressMode.driverStation;

static FlexSchemeVariant themeVariant = FlexSchemeVariant.material3Legacy;
static const String defaultVariantName = 'Material-3 Legacy (Default)';

static const String ipAddress = '127.0.0.1';
static const int teamNumber = 9999;
static const int gridSize = 128;
Expand Down
11 changes: 4 additions & 7 deletions lib/widgets/settings_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ import 'package:elastic_dashboard/widgets/dialog_widgets/dialog_toggle_switch.da

class SettingsDialog extends StatefulWidget {
final NTConnection ntConnection;
static const FlexSchemeVariant defaultVariant =
FlexSchemeVariant.material3Legacy;
static const String defaultVariantName = 'Material-3 Legacy (Default)';

static final List<String> themeVariants = FlexSchemeVariant.values
.whereNot((variant) => variant == defaultVariant)
.whereNot((variant) => variant == Defaults.themeVariant)
.map((variant) => variant.variantName)
.toList()
..add(defaultVariantName)
..add(Defaults.defaultVariantName)
..sort();

final SharedPreferences preferences;
Expand Down Expand Up @@ -172,15 +170,14 @@ class _SettingsDialogState extends State<SettingsDialog> {
(e) => e.variantName == variantName) ??
FlexSchemeVariant.material3Legacy;

Settings.themeVariant = variant;
widget.onThemeVariantChanged?.call(variant);
setState(() {});
},
choices:
themeVariantsOverride ?? SettingsDialog.themeVariants,
initialValue:
widget.preferences.getString(PrefKeys.themeVariant) ??
SettingsDialog.defaultVariantName),
Defaults.defaultVariantName),
),
],
),
Expand Down

0 comments on commit 8c40ba8

Please sign in to comment.