Updated theme change, no restart needed

This commit is contained in:
JHubi1 2024-08-22 20:12:37 +02:00
parent e10062206d
commit ec92a0eb38
No known key found for this signature in database
GPG Key ID: 7BF82570CBBBD050
5 changed files with 39 additions and 133 deletions

View File

@ -80,7 +80,8 @@ SpeechToText speech = SpeechToText();
FlutterTts voice = FlutterTts(); FlutterTts voice = FlutterTts();
bool voiceSupported = false; bool voiceSupported = false;
Function? setMainState; void Function(void Function())? setGlobalState;
void Function(void Function())? setMainAppState;
void main() { void main() {
runApp(const App()); runApp(const App());
@ -146,25 +147,28 @@ class _AppState extends State<App> {
builder: (ColorScheme? lightDynamic, ColorScheme? darkDynamic) { builder: (ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
colorSchemeLight = lightDynamic; colorSchemeLight = lightDynamic;
colorSchemeDark = darkDynamic; colorSchemeDark = darkDynamic;
return MaterialApp( return StatefulBuilder(builder: (context, setState) {
localizationsDelegates: AppLocalizations.localizationsDelegates, setMainAppState = setState;
supportedLocales: AppLocalizations.supportedLocales, return MaterialApp(
localeListResolutionCallback: (deviceLocales, supportedLocales) { localizationsDelegates: AppLocalizations.localizationsDelegates,
if (deviceLocales != null) { supportedLocales: AppLocalizations.supportedLocales,
for (final locale in deviceLocales) { localeListResolutionCallback: (deviceLocales, supportedLocales) {
var newLocale = Locale(locale.languageCode); if (deviceLocales != null) {
if (supportedLocales.contains(newLocale)) { for (final locale in deviceLocales) {
return locale; var newLocale = Locale(locale.languageCode);
if (supportedLocales.contains(newLocale)) {
return locale;
}
} }
} }
} return const Locale("en");
return const Locale("en"); },
}, title: "Ollama",
title: "Ollama", theme: themeLight(),
theme: themeLight(), darkTheme: themeDark(),
darkTheme: themeDark(), themeMode: themeMode(),
themeMode: themeMode(), home: const MainApp());
home: const MainApp()); });
}); });
} }
} }
@ -1226,7 +1230,7 @@ class _MainAppState extends State<MainApp> {
? (model != null) ? (model != null)
? () { ? () {
selectionHaptic(); selectionHaptic();
setMainState = setState; setGlobalState = setState;
settingsOpen = true; settingsOpen = true;
logoVisible = false; logoVisible = false;
Navigator.of(context).push( Navigator.of(context).push(
@ -1308,7 +1312,7 @@ class _MainAppState extends State<MainApp> {
Navigator.of( Navigator.of(
context) context)
.pop(); .pop();
setMainState = setGlobalState =
setState; setState;
settingsOpen = settingsOpen =
true; true;

View File

@ -207,7 +207,7 @@ class _ScreenVoiceState extends State<ScreenVoice> {
speaking = false; speaking = false;
voice.stop(); voice.stop();
if (chatUuid != null) { if (chatUuid != null) {
loadChat(chatUuid!, setMainState!); loadChat(chatUuid!, setGlobalState!);
} }
settingsOpen = false; settingsOpen = false;
logoVisible = true; logoVisible = true;

View File

@ -1,5 +1,3 @@
import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
@ -10,7 +8,6 @@ import '../screen_settings.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:bitsdojo_window/bitsdojo_window.dart'; import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:restart_app/restart_app.dart';
import 'package:duration_picker/duration_picker.dart'; import 'package:duration_picker/duration_picker.dart';
import 'package:dynamic_color/dynamic_color.dart'; import 'package:dynamic_color/dynamic_color.dart';
@ -178,7 +175,11 @@ class _ScreenSettingsInterfaceState extends State<ScreenSettingsInterface> {
context: context, context: context,
builder: (context) { builder: (context) {
return Dialog( return Dialog(
surfaceTintColor: (Theme.of(context).brightness == Brightness.dark) ? Colors.grey[800] : null, surfaceTintColor:
(Theme.of(context).brightness ==
Brightness.dark)
? Colors.grey[800]
: null,
alignment: desktopLayout(context) alignment: desktopLayout(context)
? null ? null
: Alignment.bottomRight, : Alignment.bottomRight,
@ -306,61 +307,12 @@ class _ScreenSettingsInterfaceState extends State<ScreenSettingsInterface> {
selected: { selected: {
prefs!.getString("brightness") ?? "system" prefs!.getString("brightness") ?? "system"
}, },
onSelectionChanged: (p0) { onSelectionChanged: (p0) async {
selectionHaptic(); selectionHaptic();
var tmp = await prefs!
prefs!.getString("brightness") ?? "system"; .setString("brightness", p0.elementAt(0));
prefs!.setString("brightness", p0.elementAt(0)); setMainAppState!(() {});
setState(() {}); setState(() {});
showDialog(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (context, setLocalState) {
return PopScope(
onPopInvoked: (didPop) {
prefs!.setString("brightness", tmp);
setState(() {});
},
child: AlertDialog(
surfaceTintColor: (Theme.of(context).brightness == Brightness.dark) ? Colors.grey[800] : null,
title: Text(AppLocalizations.of(
context)!
.settingsBrightnessRestartTitle),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(AppLocalizations.of(
context)!
.settingsBrightnessRestartDescription),
]),
actions: [
TextButton(
onPressed: () {
selectionHaptic();
Navigator.of(context).pop();
},
child: Text(AppLocalizations
.of(context)!
.settingsBrightnessRestartCancel)),
TextButton(
onPressed: () async {
selectionHaptic();
await prefs!.setString(
"brightness",
p0.elementAt(0));
if (desktopFeature()) {
exit(0);
} else {
Restart.restartApp();
}
},
child: Text(AppLocalizations
.of(context)!
.settingsBrightnessRestartRestart))
]));
});
});
}), }),
const SizedBox(height: 8), const SizedBox(height: 8),
!kIsWeb !kIsWeb
@ -383,53 +335,12 @@ class _ScreenSettingsInterfaceState extends State<ScreenSettingsInterface> {
? "device" ? "device"
: "ollama" : "ollama"
}, },
onSelectionChanged: (p0) { onSelectionChanged: (p0) async {
selectionHaptic(); selectionHaptic();
showDialog( await prefs!.setBool("useDeviceTheme",
context: context, p0.elementAt(0) == "device");
builder: (context) { setMainAppState!(() {});
return StatefulBuilder( setState(() {});
builder: (context, setLocalState) {
return AlertDialog(
surfaceTintColor: (Theme.of(context).brightness == Brightness.dark) ? Colors.grey[800] : null,
title: Text(
AppLocalizations.of(context)!
.settingsThemeRestartTitle),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(AppLocalizations.of(
context)!
.settingsThemeRestartDescription),
]),
actions: [
TextButton(
onPressed: () {
selectionHaptic();
Navigator.of(context).pop();
},
child: Text(AppLocalizations
.of(context)!
.settingsThemeRestartCancel)),
TextButton(
onPressed: () async {
selectionHaptic();
await prefs!.setBool(
"useDeviceTheme",
p0.elementAt(0) ==
"device");
if (desktopFeature()) {
exit(0);
} else {
Restart.restartApp();
}
},
child: Text(AppLocalizations
.of(context)!
.settingsThemeRestartRestart))
]);
});
});
}) })
: const SizedBox.shrink(), : const SizedBox.shrink(),
titleDivider(), titleDivider(),

View File

@ -741,14 +741,6 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.1.8" version: "2.1.8"
restart_app:
dependency: "direct main"
description:
name: restart_app
sha256: b37daeb1c02fcab30e19d9e30b6fdd215bd53577efd927042eb77cf6f09daadb
url: "https://pub.dev"
source: hosted
version: "1.2.1"
scroll_to_index: scroll_to_index:
dependency: transitive dependency: transitive
description: description:

View File

@ -25,7 +25,6 @@ dependencies:
transparent_image: ^2.0.1 transparent_image: ^2.0.1
simple_icons: ^10.1.3 simple_icons: ^10.1.3
url_launcher: ^6.2.6 url_launcher: ^6.2.6
restart_app: ^1.2.1
flutter_markdown: ^0.7.1 flutter_markdown: ^0.7.1
file_picker: ^8.0.3 file_picker: ^8.0.3
file_selector: ^1.0.3 file_selector: ^1.0.3