Updated theme change, no restart needed
This commit is contained in:
parent
e10062206d
commit
ec92a0eb38
|
@ -80,7 +80,8 @@ SpeechToText speech = SpeechToText();
|
|||
FlutterTts voice = FlutterTts();
|
||||
bool voiceSupported = false;
|
||||
|
||||
Function? setMainState;
|
||||
void Function(void Function())? setGlobalState;
|
||||
void Function(void Function())? setMainAppState;
|
||||
|
||||
void main() {
|
||||
runApp(const App());
|
||||
|
@ -146,25 +147,28 @@ class _AppState extends State<App> {
|
|||
builder: (ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
|
||||
colorSchemeLight = lightDynamic;
|
||||
colorSchemeDark = darkDynamic;
|
||||
return MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
localeListResolutionCallback: (deviceLocales, supportedLocales) {
|
||||
if (deviceLocales != null) {
|
||||
for (final locale in deviceLocales) {
|
||||
var newLocale = Locale(locale.languageCode);
|
||||
if (supportedLocales.contains(newLocale)) {
|
||||
return locale;
|
||||
return StatefulBuilder(builder: (context, setState) {
|
||||
setMainAppState = setState;
|
||||
return MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
localeListResolutionCallback: (deviceLocales, supportedLocales) {
|
||||
if (deviceLocales != null) {
|
||||
for (final locale in deviceLocales) {
|
||||
var newLocale = Locale(locale.languageCode);
|
||||
if (supportedLocales.contains(newLocale)) {
|
||||
return locale;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return const Locale("en");
|
||||
},
|
||||
title: "Ollama",
|
||||
theme: themeLight(),
|
||||
darkTheme: themeDark(),
|
||||
themeMode: themeMode(),
|
||||
home: const MainApp());
|
||||
return const Locale("en");
|
||||
},
|
||||
title: "Ollama",
|
||||
theme: themeLight(),
|
||||
darkTheme: themeDark(),
|
||||
themeMode: themeMode(),
|
||||
home: const MainApp());
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1226,7 +1230,7 @@ class _MainAppState extends State<MainApp> {
|
|||
? (model != null)
|
||||
? () {
|
||||
selectionHaptic();
|
||||
setMainState = setState;
|
||||
setGlobalState = setState;
|
||||
settingsOpen = true;
|
||||
logoVisible = false;
|
||||
Navigator.of(context).push(
|
||||
|
@ -1308,7 +1312,7 @@ class _MainAppState extends State<MainApp> {
|
|||
Navigator.of(
|
||||
context)
|
||||
.pop();
|
||||
setMainState =
|
||||
setGlobalState =
|
||||
setState;
|
||||
settingsOpen =
|
||||
true;
|
||||
|
|
|
@ -207,7 +207,7 @@ class _ScreenVoiceState extends State<ScreenVoice> {
|
|||
speaking = false;
|
||||
voice.stop();
|
||||
if (chatUuid != null) {
|
||||
loadChat(chatUuid!, setMainState!);
|
||||
loadChat(chatUuid!, setGlobalState!);
|
||||
}
|
||||
settingsOpen = false;
|
||||
logoVisible = true;
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.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:bitsdojo_window/bitsdojo_window.dart';
|
||||
import 'package:restart_app/restart_app.dart';
|
||||
import 'package:duration_picker/duration_picker.dart';
|
||||
import 'package:dynamic_color/dynamic_color.dart';
|
||||
|
||||
|
@ -178,7 +175,11 @@ class _ScreenSettingsInterfaceState extends State<ScreenSettingsInterface> {
|
|||
context: context,
|
||||
builder: (context) {
|
||||
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)
|
||||
? null
|
||||
: Alignment.bottomRight,
|
||||
|
@ -306,61 +307,12 @@ class _ScreenSettingsInterfaceState extends State<ScreenSettingsInterface> {
|
|||
selected: {
|
||||
prefs!.getString("brightness") ?? "system"
|
||||
},
|
||||
onSelectionChanged: (p0) {
|
||||
onSelectionChanged: (p0) async {
|
||||
selectionHaptic();
|
||||
var tmp =
|
||||
prefs!.getString("brightness") ?? "system";
|
||||
prefs!.setString("brightness", p0.elementAt(0));
|
||||
await prefs!
|
||||
.setString("brightness", p0.elementAt(0));
|
||||
setMainAppState!(() {});
|
||||
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),
|
||||
!kIsWeb
|
||||
|
@ -383,53 +335,12 @@ class _ScreenSettingsInterfaceState extends State<ScreenSettingsInterface> {
|
|||
? "device"
|
||||
: "ollama"
|
||||
},
|
||||
onSelectionChanged: (p0) {
|
||||
onSelectionChanged: (p0) async {
|
||||
selectionHaptic();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return StatefulBuilder(
|
||||
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))
|
||||
]);
|
||||
});
|
||||
});
|
||||
await prefs!.setBool("useDeviceTheme",
|
||||
p0.elementAt(0) == "device");
|
||||
setMainAppState!(() {});
|
||||
setState(() {});
|
||||
})
|
||||
: const SizedBox.shrink(),
|
||||
titleDivider(),
|
||||
|
|
|
@ -741,14 +741,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -25,7 +25,6 @@ dependencies:
|
|||
transparent_image: ^2.0.1
|
||||
simple_icons: ^10.1.3
|
||||
url_launcher: ^6.2.6
|
||||
restart_app: ^1.2.1
|
||||
flutter_markdown: ^0.7.1
|
||||
file_picker: ^8.0.3
|
||||
file_selector: ^1.0.3
|
||||
|
|
Loading…
Reference in New Issue