Centralized theme worker, simplified readme, unification on some spots, catches in voice mode, added tests

This commit is contained in:
JHubi1 2024-08-20 00:23:05 +02:00
parent 6a5a123026
commit e57927524d
No known key found for this signature in database
GPG Key ID: F538DC3FC5B07498
22 changed files with 587 additions and 791 deletions

252
README.md
View File

@ -9,26 +9,11 @@ A modern and easy-to-use client for Ollama. Have the greatest experience while k
> This app does not host a Ollama server on device, but rather connects to one and uses its api endpoint.
> You don't know what Ollama is? Learn more at [ollama.com](https://ollama.com/).
- [Ollama App](#ollama-app)
- [Installation](#installation)
- [Initial Setup](#initial-setup)
- [Chat View](#chat-view)
- [Multimodal Input](#multimodal-input)
- [Model Selector](#model-selector)
- [Side Menu](#side-menu)
- [Settings](#settings)
- [Host](#host)
- [Custom headers](#custom-headers)
- [Behavior](#behavior)
- [Interface](#interface)
- [Voice](#voice)
- [Export](#export)
- [About (and Updates)](#about-and-updates)
- [Multilingual Interface](#multilingual-interface)
- [Custom Builds](#custom-builds)
- [Actually Building](#actually-building)
## Getting Started
## Installation
Ollama App has a pretty simple and intuitive interface to be as open as possible. Everything just works out of the but, you just have to follow the two next steps.
### Installation
You'll find the latest recommended version of the Ollama App under [the releases tab](https://github.com/JHubi1/ollama-app/releases). Download the APK and install it on your Android device. That's it, now proceed to [Initial Setup](#initial-setup).
@ -36,232 +21,27 @@ Alternatively, you can also download the app from any of the following stores:
[<img src="assets/stores/IzzyOnDroid.png" width="215" style="padding: 5px" />](https://apt.izzysoft.de/fdroid/index/apk/com.freakurl.apps.ollama/)
## Initial Setup
### Setup
After installing the app and opening it for the first time, you'll encounter this popup:
The most difficult part is setting up the host. To learn more visit the [wiki guide on how to do so](https://github.com/JHubi1/ollama-app/wiki/Getting-Started#setting-up-the-host). After setting up, you normally don't have to enter it again.
<img src="assets/screenshots/flutter_01.png" alt="welcome instructions" height="720" />
Go through the welcome dialog one by one, you should read their content, but you don't have to.
| ![initial notification](assets/screenshots/flutter_02.png) | ![open sidebar](assets/screenshots/flutter_26.png) | ![set host input](assets/screenshots/flutter_03.png) |
|-|-|-|
After going through that, you'll get a small snack bar notifying you that you have to set the host. For that, open the sidebar (swipe from the left to right or click the icon in the top left corner) and click on settings. There you'll find all app-related settings, you should go through them, but for the initial setup, only the first one is important.
In the big host text field, you have to enter the base URL of your instance. The port is required unless the port number matches the protocol (443 for HTTPS or 80 for HTTP). After that, click the save icon right next to the text field.
To learn more about the host setting, visit [Settings](#host)
> [!IMPORTANT]
> The Ollama server needs additional steps to be asccessible from without the local machine. To learn more, visit issue #5
That's it, you can now just chat. Enter a message into the box at the bottom and click the send icon.
## Chat View
This is the main view of the app, simple and, most importantly, working.
> [!NOTE]
> To start chatting, you first have to select a model in the [Model Selector](#model-selector). Do that first, then come back here.
The chat mode is straightforward. Just write a message, wait a few moments, and the answer will get sent into the chat.
The chat view hides a few useful features already included by default. Messages can be deleted by double-tapping the message you desire to wipe from the earth, and all messages sent since then, including the message itself, will get deleted.
Editing a message is almost as simple. After enabling message editing in [Interface Settings](#interface), simply long press on a message and a popup will open and ask for the new content.
<img src="assets/screenshots/flutter_19.png" alt="message editing dialog" height="720" />
And you're done! Just start chatting with your local AI and have fun!
> [!TIP]
> Messages (almost) fully support markdown syntax. That means the AI will be able to recieve and send back the message in markdown.
> The new Voice Mode is now avaliable as an experimental feature. Learn more about it in [the documentation](https://github.com/JHubi1/ollama-app/wiki/Components#voice).
### Multimodal Input
## Documentation
Ollama App supports multimodal models, models that support input via an image. Models supporting the technology are marked with an image icon next to their name in the [Model Selector](#model-selector).
The documentation for components, functions, etc. has moved to the [Wiki Page](https://github.com/JHubi1/ollama-app/wiki) of this repository. These steps there will be updated with future versions.
After selecting a multimodal model, a new icon appears at the bottom left of the message bar; a camera icon. Clicking on it reveals the following bottom sheet:
## Translations and Contribution
| ![new attachment button](assets/screenshots/flutter_32.png) | ![attachment dialog](assets/screenshots/flutter_28.png) | ![attachment dialog](assets/screenshots/flutter_31.png) |
|-|-|-|
You want to help me make this project even better? Great, help is always appresheated.
Select one of them, take or select your photo and it'll get added to the chat. Adding multiple images is allowed, just repeat the steps.
Ollama App is created using [Flutter](https://flutter.dev), a modern and robust frontend framework designed to make a single codebase run on multiple target platforms. The framework itself is based on the [Dart](https://dart.dev) programming language.
Even though the images will appear in the chat already after sending, they won't be submitted to the AI until a new text message is sent. When you send a message the AI will answer the message in consideration of the image.
Read more in the [Contribution Guide](https://github.com/JHubi1/ollama-app/wiki/Contributing).
## Model Selector
## Star History
You can access the model selector by tapping on the `<selector>` text in the top middle or the name of the currently selected model in the same spot. Then you'll get the following popup dialog:
<img src="assets/screenshots/flutter_15.png" alt="model selector" height="720" />
This will display all the models currently installed on your Ollama server instance.
The models with a star next to them are recommended models. They have been selected by me (hehe) to be listed as that. Read more under [Custom Builds](#custom-builds).
The `Add` button does nothing at the moment, it just opens a snack bar listing steps on how to add a model to an instance. For safety reasons, I didn't add the ability to add a model directly via name in the app.
Models supporting [Multimodal Input](#multimodal-input) are marked with an image icon next to their name, like `llava` in the image above.
## Side Menu
The button on the top left opens the menu. In it, you have two options: `New Chat` and `Settings`. The first option creates a new chat, and the second one opens the [Settings](#settings) where you can change how everything works.
Below that are all the chats. To delete one, swipe it from left to right. To rename the chat tab and hold it until a popup dialog appears. In it, you can change the title or tab the sparkle icon to let AI find one for you. This is not affected by the "generate title" setting.
| ![side menu](assets/screenshots/flutter_26.png)| ![side menu with chat](assets/screenshots/flutter_33.png) | ![rename dialog of chat](assets/screenshots/flutter_20.png) |
|-|-|-|
> [!NOTE]
> The button on the top right corner deletes the chat. It has the same effect as swiping the chat in the sidebar.
## Settings
Ollama App offers a lot of configuration options. We'll go through every option one by one.
### Host
The host is the main address of your Ollama server. It may include a port, a protocol and a hostname. Paths are not recommended.
| ![false host](assets/screenshots/flutter_03.png) | ![looking for host](assets/screenshots/flutter_04.png) | ![right host](assets/screenshots/flutter_05.png) |
|-|-|-|
The port is required unless the port number matches the protocol (443 for HTTPS or 80 for HTTP). After that, click the save icon right next to the text field to set the host.
The host address will be checked, so no worry about entering the wrong one. If you set the host once, and your server is offline, the requests will fail, but the host will stay saved if you don't change it yourself. To do that, just go into the side menu and open settings to do so.
#### Custom headers
<img src="assets/screenshots/flutter_27.png" alt="settings screen" height="720" />
Ollama App supports adding custom headers. This can be useful in case you want to secure your instance with authentification or something similar. Simply press the plus icon next to the host input and set one as a JSON object. This could be for example:
```json
{
"Authorization": "Bearer <token>"
}
```
### Behavior
<img src="assets/screenshots/flutter_06.png" alt="settings screen" height="720" />
The behavior settings include settings connected to the system prompt. They won't be applied until you create a new chat.
The system prompt is sent to the assistant at the start of the conversation. It leads the assistant in a direction and it'll talk like you told him to in this message. To reset the system prompt to default, empty its value, click the save icon and close the screen.
The option to disable markdown is not safe and the assistant can still potentially add markdown to its response.
### Interface
<img src="assets/screenshots/flutter_07.png" alt="settings screen" height="720" />
The interface settings are focused, as the name might imply, on the interface of the Ollama App. The following list will document all options
1. Targeted at the [Model Selector](#model-selector).
1. Show model tags in the model selector. This can be useful if you have multiple versions of the same model installed
2. Clear the chat if the model is changed. This is highly recommended, disabling this option could lead to unintended behavior
2. Used in the [Chat View](#chat-view)
1. Set the request mode. Streaming is recommended, but sometimes it's not available, then select "Request"
2. Whether to generate titles of chats with the Ollama AI or not. Could higher potential quota costs
3. Whether long-pressing messages opens the edit dialog or not
4. Whether to ask before deletion of chats. Useful if important data is potentially stored in chats or not
5. Whether to show tips in the main sidebar
3. Backend loading options
1. Keep model always loaded (`keep_alive` to `-1`)
2. Never keep model (`keep_alive` to `0`)
3. Time to keep models alive
4. Appearance settings
1. Whether to enable haptic feedback or not
2. Whether to start windows maximized (only desktop)
3. Theme of app
4. Follow the device theme/color
### Voice
> [!WARNING]
> This is still an experimental feature! Some functions may not work as intended!
| ![no permissions](assets/screenshots/flutter_09.png) | ![enabled](assets/screenshots/flutter_11.png) | ![language dialog](assets/screenshots/flutter_12.png) |
|-|-|-|
Tap the "Permissions not granted" button to allow the needed permissions. They're needed to allow Speach To Text to function.
After that, enable Voice Mode by switching the toggle. To bring it to work, you now have to press "No language selected" and select a language in the language dialog. That's it.
Then, press the button on the spot where the attachment icon would be with a multimodal model or press the photo icon and the "Voice" button.
<img src="assets/screenshots/flutter_29.png" alt="settings screen" height="720" />
> [!NOTE]
> Documentation will be properly added once this feature leaves experimental phase
### Export
<img src="assets/screenshots/flutter_13.png" alt="settings screen" height="720" />
The export function allows you to export and save all chats to a file. This can be very useful if you want to back up your data or want to sync it between devices.
> [!WARNING]
> The import functionallity deletes all currently saved chats from disk and replaces them with the ones from the file. This cannot be undone.
### About (and Updates)
<img src="assets/screenshots/flutter_14.png" alt="settings screen" height="720" />
The About screen holds a lot of useful information.
You can access the GitHub repository or the issue page of the app directly from this screen.
One more useful thing is the update checker. It looks for updates in the repo and will prompt you to download them directly from GitHub. Be careful though, the used GitHub API has a rate limit. You can only send a few requests before the rate limit kicks in.
## Multilingual Interface
Ollama App does support multiple languages. Currently available are:
- [x] English (fallback)
- [x] German
- [ ] Chinese (simplified)
- [ ] Italian
- [ ] Turkish
The tick is set if the language is translated with 100%. This might not be up to date, check the project page to get the latest progress.
In case the language you're looking for isn't listed, you can check if the development is in progress on the [Crowdin project page](https://crowdin.com/project/ollama-app). If not, you can always contribute.
## Custom Builds
Now it's going to get interesting. The app is built in a way so you can easily create custom builds. Currently, there are these values that can be customized:
```
// use host or not, if false dialog is shown
const useHost = false;
// host of ollama, must be accessible from the client, without trailing slash, will always be accepted as valid
const fixedHost = "http://example.com:11434";
// use model or not, if false selector is shown
const useModel = false;
// model name as string, must be valid ollama model!
const fixedModel = "gemma";
// recommended models, shown with as star in model selector
const recommendedModels = ["gemma", "llama3"];
// allow opening of settings
const allowSettings = true;
// allow multiple chats
const allowMultipleChats = true;
```
They can be found at the top of `lib/main.dart`. `useHost` and `useModel` decide whether you want `fixedHost` and `fixedModel` to control anything. `fixedHost` and `fixedModel` decide about the value that has to be used. That can be practical in case you try to create an app specific to your instance.
`recommendedModels` is a list of models that will be listed as recommended in the [Model Selector](#model-selector). They are more like personal preferences. If empty, no model will be preferred.
`allowSettings` will disable the settings screen. But it will also disable the welcome dialog at first startup and the ability to rename chats.
`allowMultipleChats` simply removes the `New Chat` option in the [Side Menu](#side-menu). And will load up the only available chat on app startup.
### Actually Building
But how do you create a custom build?
First, follow [the Flutter installation guide](https://docs.flutter.dev/get-started/install) by selecting Android as the first app type. Then follow [these steps](https://docs.flutter.dev/deployment/android#signing-the-app) till you have your custom `key.properties`. Place it into the `android` folder at the root of the project.
Make sure dart is available as a command or added as the default program for `.dart`. Then execute `scripts/build.dart` and wait for it to finish processing. Then go to `build/.output`. There you'll find everything you need, the normal Android app and the experimental Windows build.
![Star History Chart](https://api.star-history.com/svg?repos=JHubi1/ollama-app&type=Timeline)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 152 KiB

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 KiB

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

After

Width:  |  Height:  |  Size: 98 KiB

View File

@ -473,6 +473,26 @@
"description": "Text displayed for cancel button, should be capitalized",
"context": "Visible in the settings view"
},
"settingsTemporaryFixes": "Temporary interface fixes",
"@settingsTemporaryFixes": {
"description": "Text displayed as description for temporary fixes section",
"context": "Visible in the settings view"
},
"settingsTemporaryFixesDescription": "Enable temporary fixes for interface issues.\nLong press on the individual options to learn more.",
"@settingsTemporaryFixesDescription": {
"description": "Description of the temporary fixes section",
"context": "Visible in the settings view"
},
"settingsTemporaryFixesInstructions": "Do not toggle any of these settings unless you know what you are doing! The given solutions might not work as expected.\nThey cannot be seen as final or should be judged as such. Issues might occur.",
"@settingsTemporaryFixesInstructions": {
"description": "Instructions and warnings for the temporary fixes",
"context": "Visible in the settings view"
},
"settingsTemporaryFixesNoFixes": "No fixes available",
"@settingsTemporaryFixesNoFixes": {
"description": "Text displayed when no fixes are available",
"context": "Visible in the settings view"
},
"settingsVoicePermissionLoading": "Loading voice permissions ...",
"@settingsVoicePermissionLoading": {
"description": "Text displayed while loading voice permissions",

View File

@ -4,7 +4,6 @@ import 'dart:math';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
@ -15,6 +14,7 @@ import 'worker/setter.dart';
import 'worker/haptic.dart';
import 'worker/sender.dart';
import 'worker/desktop.dart';
import 'worker/theme.dart';
import 'package:shared_preferences/shared_preferences.dart';
// ignore: depend_on_referenced_packages
@ -23,7 +23,6 @@ import 'package:flutter_chat_ui/flutter_chat_ui.dart';
import 'package:uuid/uuid.dart';
import 'package:image_picker/image_picker.dart';
import 'package:visibility_detector/visibility_detector.dart';
// import 'package:http/http.dart' as http;
import 'package:flutter_markdown/flutter_markdown.dart';
// ignore: depend_on_referenced_packages
import 'package:markdown/markdown.dart' as md;
@ -38,26 +37,24 @@ import 'package:url_launcher/url_launcher.dart';
// client configuration
// use host or not, if false dialog is shown
const useHost = false;
const bool useHost = false;
// host of ollama, must be accessible from the client, without trailing slash
// ! will always be accepted as valid, even if [useHost] is false
const fixedHost = "http://example.com:11434";
const String fixedHost = "http://example.com:11434";
// use model or not, if false selector is shown
const useModel = false;
const bool useModel = false;
// model name as string, must be valid ollama model!
const fixedModel = "gemma";
// recommended models, shown with as star in model selector
const recommendedModels = ["gemma", "llama3"];
const String fixedModel = "gemma";
// recommended models, shown with a star in model selector
const List<String> recommendedModels = ["gemma", "llama3"];
// allow opening of settings
const allowSettings = true;
const bool allowSettings = true;
// allow multiple chats
const allowMultipleChats = true;
const bool allowMultipleChats = true;
// client configuration end
SharedPreferences? prefs;
ThemeData? theme;
ThemeData? themeDark;
String? model;
String? host;
@ -77,6 +74,7 @@ bool desktopTitleVisible = true;
bool logoVisible = true;
bool menuVisible = false;
bool sendable = false;
double sidebarIconSize = 1;
SpeechToText speech = SpeechToText();
FlutterTts voice = FlutterTts();
@ -146,79 +144,8 @@ class _AppState extends State<App> {
Widget build(BuildContext context) {
return DynamicColorBuilder(
builder: (ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
if (!(prefs?.getBool("useDeviceTheme") ?? false) ||
lightDynamic == null ||
darkDynamic == null) {
theme = ThemeData.from(
colorScheme: const ColorScheme(
brightness: Brightness.light,
primary: Colors.black,
onPrimary: Colors.white,
secondary: Colors.white,
onSecondary: Colors.black,
error: Colors.red,
onError: Colors.white,
surface: Colors.white,
onSurface: Colors.black));
themeDark = ThemeData.from(
colorScheme: const ColorScheme(
brightness: Brightness.dark,
primary: Colors.white,
onPrimary: Colors.black,
secondary: Colors.black,
onSecondary: Colors.white,
error: Colors.red,
onError: Colors.black,
surface: Colors.black,
onSurface: Colors.white));
} else {
theme = ThemeData.from(colorScheme: lightDynamic);
themeDark = ThemeData.from(colorScheme: darkDynamic);
}
WidgetsBinding.instance.addPostFrameCallback((_) {
WidgetsBinding.instance.platformDispatcher.onPlatformBrightnessChanged =
() {
// invert colors used, because brightness not updated yet
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor:
(prefs?.getString("brightness") ?? "system") == "system"
? ((MediaQuery.of(context).platformBrightness ==
Brightness.light)
? (themeDark ?? ThemeData.dark()).colorScheme.surface
: (theme ?? ThemeData()).colorScheme.surface)
: (prefs?.getString("brightness") == "dark"
? (themeDark ?? ThemeData()).colorScheme.surface
: (theme ?? ThemeData.dark()).colorScheme.surface),
systemNavigationBarIconBrightness:
(((prefs?.getString("brightness") ?? "system") == "system" &&
MediaQuery.of(context).platformBrightness ==
Brightness.dark) ||
prefs?.getString("brightness") == "light")
? Brightness.dark
: Brightness.light));
};
// brightness changed function not run at first startup
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor:
(prefs?.getString("brightness") ?? "system") == "system"
? ((MediaQuery.of(context).platformBrightness ==
Brightness.light)
? (theme ?? ThemeData.dark()).colorScheme.surface
: (themeDark ?? ThemeData()).colorScheme.surface)
: (prefs?.getString("brightness") == "dark"
? (themeDark ?? ThemeData()).colorScheme.surface
: (theme ?? ThemeData.dark()).colorScheme.surface),
systemNavigationBarIconBrightness:
(((prefs?.getString("brightness") ?? "system") == "system" &&
MediaQuery.of(context).platformBrightness ==
Brightness.light) ||
prefs?.getString("brightness") == "light")
? Brightness.dark
: Brightness.light));
});
colorSchemeLight = lightDynamic;
colorSchemeDark = darkDynamic;
return MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
@ -234,13 +161,9 @@ class _AppState extends State<App> {
return const Locale("en");
},
title: "Ollama",
theme: theme,
darkTheme: themeDark,
themeMode: ((prefs?.getString("brightness") ?? "system") == "system")
? ThemeMode.system
: ((prefs!.getString("brightness") == "dark")
? ThemeMode.dark
: ThemeMode.light),
theme: themeLight(),
darkTheme: themeDark(),
themeMode: themeMode(),
home: const MainApp());
});
}
@ -267,15 +190,36 @@ class _MainAppState extends State<MainApp> {
: (Padding(
padding: padding,
child: InkWell(
enableFeedback: false,
customBorder: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(50))),
onTap: () {},
onTap: () async {
// ester egg? gimmick? not sure if it should be kept
return;
// ignore: dead_code
if (sidebarIconSize != 1) return;
setState(() {
sidebarIconSize = 0.8;
});
await Future.delayed(const Duration(milliseconds: 200));
setState(() {
sidebarIconSize = 1.2;
});
await Future.delayed(const Duration(milliseconds: 200));
setState(() {
sidebarIconSize = 1;
});
},
child: Padding(
padding: const EdgeInsets.only(top: 16, bottom: 16),
child: Row(children: [
const Padding(
padding: EdgeInsets.only(left: 16, right: 12),
child: ImageIcon(AssetImage("assets/logo512.png"))),
Padding(
padding: const EdgeInsets.only(left: 16, right: 12),
child: AnimatedScale(
scale: sidebarIconSize,
duration: const Duration(milliseconds: 400),
child: const ImageIcon(
AssetImage("assets/logo512.png")))),
Expanded(
child: Text(AppLocalizations.of(context)!.appTitle,
softWrap: false,
@ -296,6 +240,7 @@ class _MainAppState extends State<MainApp> {
? (Padding(
padding: padding,
child: InkWell(
enableFeedback: false,
customBorder: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(50))),
onTap: () {
@ -329,6 +274,7 @@ class _MainAppState extends State<MainApp> {
? (Padding(
padding: padding,
child: InkWell(
enableFeedback: false,
customBorder: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(50))),
onTap: () {
@ -373,6 +319,7 @@ class _MainAppState extends State<MainApp> {
: (Padding(
padding: padding,
child: InkWell(
enableFeedback: false,
customBorder: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(50))),
onTap: () {
@ -451,6 +398,7 @@ class _MainAppState extends State<MainApp> {
var child = Padding(
padding: padding,
child: InkWell(
enableFeedback: false,
customBorder: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(50))),
onTap: () {
@ -681,149 +629,153 @@ class _MainAppState extends State<MainApp> {
return;
}
if (!chatAllowed) return;
showDialog(
if (!desktopLayoutRequired(
context)) {
Navigator.of(context).pop();
}
showModalBottomSheet(
context: context,
builder: (context) {
return Dialog(
alignment:
Alignment.bottomLeft,
insetPadding:
const EdgeInsets.only(
left: 12,
bottom: 12),
child: Container(
width: 100,
padding:
const EdgeInsets
.only(
left: 16,
right: 16,
top: 16),
child: Column(
mainAxisSize:
MainAxisSize
.min,
children: [
SizedBox(
width: double
.infinity,
child: OutlinedButton
.icon(
onPressed:
() {
Navigator.of(context).pop();
if (prefs!.getBool("askBeforeDeletion") ??
false) {
showDialog(
context: context,
builder: (context) {
return StatefulBuilder(builder: (context, setLocalState) {
return AlertDialog(
title: Text(AppLocalizations.of(context)!.deleteDialogTitle),
content: Column(mainAxisSize: MainAxisSize.min, children: [
Text(AppLocalizations.of(context)!.deleteDialogDescription),
]),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(AppLocalizations.of(context)!.deleteDialogCancel)),
TextButton(
onPressed: () {
Navigator.of(context).pop();
for (var i = 0; i < (prefs!.getStringList("chats") ?? []).length; i++) {
if (jsonDecode((prefs!.getStringList("chats") ?? [])[i])["uuid"] == jsonDecode(item)["uuid"]) {
List<String> tmp = prefs!.getStringList("chats")!;
tmp.removeAt(i);
prefs!.setStringList("chats", tmp);
break;
}
return Padding(
padding:
const EdgeInsets.only(
left: 16,
right: 16,
top: 16),
child: Column(
mainAxisSize:
MainAxisSize.min,
children: [
SizedBox(
width: double
.infinity,
child: OutlinedButton
.icon(
onPressed:
() {
Navigator.of(context)
.pop();
if (prefs!.getBool("askBeforeDeletion") ??
false) {
showDialog(
context: context,
builder: (context) {
return StatefulBuilder(builder: (context, setLocalState) {
return AlertDialog(
title: Text(AppLocalizations.of(context)!.deleteDialogTitle),
content: Column(mainAxisSize: MainAxisSize.min, children: [
Text(AppLocalizations.of(context)!.deleteDialogDescription),
]),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(AppLocalizations.of(context)!.deleteDialogCancel)),
TextButton(
onPressed: () {
Navigator.of(context).pop();
for (var i = 0; i < (prefs!.getStringList("chats") ?? []).length; i++) {
if (jsonDecode((prefs!.getStringList("chats") ?? [])[i])["uuid"] == jsonDecode(item)["uuid"]) {
List<String> tmp = prefs!.getStringList("chats")!;
tmp.removeAt(i);
prefs!.setStringList("chats", tmp);
break;
}
if (chatUuid == jsonDecode(item)["uuid"]) {
messages = [];
chatUuid = null;
if (!desktopLayoutRequired(context)) {
Navigator.of(context).pop();
}
}
if (chatUuid == jsonDecode(item)["uuid"]) {
messages = [];
chatUuid = null;
if (!desktopLayoutRequired(context)) {
Navigator.of(context).pop();
}
setState(() {});
},
child: Text(AppLocalizations.of(context)!.deleteDialogDelete))
]);
});
}
setState(() {});
},
child: Text(AppLocalizations.of(context)!.deleteDialogDelete))
]);
});
} else {
for (var i = 0; i < (prefs!.getStringList("chats") ?? []).length; i++) {
if (jsonDecode((prefs!.getStringList("chats") ?? [])[i])["uuid"] == jsonDecode(item)["uuid"]) {
List<String> tmp = prefs!.getStringList("chats")!;
tmp.removeAt(i);
prefs!.setStringList("chats", tmp);
break;
}
}
if (chatUuid == jsonDecode(item)["uuid"]) {
messages = [];
chatUuid = null;
if (!desktopLayoutRequired(context)) {
Navigator.of(context).pop();
}
}
setState(() {});
}
},
icon: const Icon(Icons
.delete_forever_rounded),
label:
Text(AppLocalizations.of(context)!.deleteChat))),
const SizedBox(
height: 8),
SizedBox(
width: double
.infinity,
child: OutlinedButton
.icon(
onPressed:
() async {
Navigator.of(context).pop();
String
oldTitle =
jsonDecode(item)["title"];
var newTitle = await prompt(context,
title: AppLocalizations.of(context)!.dialogEnterNewTitle,
value: oldTitle,
uuid: jsonDecode(item)["uuid"]);
var tmp =
(prefs!.getStringList("chats") ?? []);
});
} else {
for (var i = 0;
i < tmp.length;
i < (prefs!.getStringList("chats") ?? []).length;
i++) {
if (jsonDecode((prefs!.getStringList("chats") ?? [])[i])["uuid"] == jsonDecode(item)["uuid"]) {
var tmp2 = jsonDecode(tmp[i]);
tmp2["title"] = newTitle;
tmp[i] = jsonEncode(tmp2);
List<String> tmp = prefs!.getStringList("chats")!;
tmp.removeAt(i);
prefs!.setStringList("chats", tmp);
break;
}
}
prefs!.setStringList("chats",
tmp);
if (chatUuid ==
jsonDecode(item)["uuid"]) {
messages = [];
chatUuid = null;
if (!desktopLayoutRequired(context)) {
Navigator.of(context).pop();
}
}
setState(() {});
},
icon: const Icon(Icons
.edit_rounded),
label:
Text(AppLocalizations.of(context)!.renameChat))),
const SizedBox(
height: 16)
])),
);
}
},
icon: const Icon(Icons
.delete_forever_rounded),
label: Text(
AppLocalizations.of(context)!.deleteChat))),
const SizedBox(
height: 8),
SizedBox(
width: double
.infinity,
child: OutlinedButton
.icon(
onPressed:
() async {
Navigator.of(context)
.pop();
String
oldTitle =
jsonDecode(item)["title"];
var newTitle = await prompt(
context,
title: AppLocalizations.of(context)!.dialogEnterNewTitle,
value: oldTitle,
uuid: jsonDecode(item)["uuid"]);
var tmp =
(prefs!.getStringList("chats") ?? []);
for (var i = 0;
i < tmp.length;
i++) {
if (jsonDecode((prefs!.getStringList("chats") ?? [])[i])["uuid"] ==
jsonDecode(item)["uuid"]) {
var tmp2 = jsonDecode(tmp[i]);
tmp2["title"] = newTitle;
tmp[i] = jsonEncode(tmp2);
break;
}
}
prefs!.setStringList(
"chats",
tmp);
setState(
() {});
},
icon: const Icon(Icons
.edit_rounded),
label: Text(
AppLocalizations.of(context)!.renameChat))),
const SizedBox(
height: 16)
]));
});
},
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
icon: Transform.translate(
offset: const Offset(-8, -8),
child: const Icon(allowMultipleChats
// ignore const suggestion, because values could be not const
// ignore: prefer_const_constructors
child: Icon(allowMultipleChats
? allowSettings
? Icons.more_horiz_rounded
: Icons.close_rounded
@ -937,15 +889,19 @@ class _MainAppState extends State<MainApp> {
// ignore: use_build_context_synchronously
context: context,
builder: (context) {
return const PopScope(
// ignore: prefer_const_constructors
return PopScope(
canPop: false,
// ignore: prefer_const_constructors
child: Dialog.fullscreen(
backgroundColor: Colors.black,
// ignore: prefer_const_constructors
child: Padding(
padding: EdgeInsets.all(16),
padding: const EdgeInsets.all(16),
// ignore: prefer_const_constructors
child: Text(
"*Build Error:*\n\nuseHost: $useHost\nallowSettings: $allowSettings\n\nYou created this build? One of them must be set to true or the app is not functional!\n\nYou received this build by someone else? Please contact them and report the issue.",
style: TextStyle(
style: const TextStyle(
color: Colors.red,
fontFamily: "monospace")))));
});
@ -978,6 +934,8 @@ class _MainAppState extends State<MainApp> {
@override
Widget build(BuildContext context) {
resetSystemNavigation(context);
Widget selector = InkWell(
onTap: () {
if (host == null) {
@ -1020,7 +978,6 @@ class _MainAppState extends State<MainApp> {
children: desktopFeature()
? desktopLayoutRequired(context)
? [
// bottom left tile
SizedBox(
width: 304, height: 200, child: MoveWindow()),
SizedBox(
@ -1251,7 +1208,7 @@ class _MainAppState extends State<MainApp> {
String text = p0.text;
if (text.trim() == "") {
text =
"_Empty AI response, try restarting conversation_"; // Warning icon: U+26A0
"_Empty AI response, try restarting conversation_";
greyed = true;
}
return Padding(
@ -1462,8 +1419,6 @@ class _MainAppState extends State<MainApp> {
data: "![${p0.name}](${p0.uri})"));
},
disableImageGallery: true,
// keyboardDismissBehavior:
// ScrollViewKeyboardDismissBehavior.onDrag,
emptyState: Center(
child: VisibilityDetector(
key: const Key("logoVisible"),
@ -1797,9 +1752,8 @@ class _MainAppState extends State<MainApp> {
});
},
l10n: ChatL10nEn(
inputPlaceholder:
AppLocalizations.of(context)!
.messageInputPlaceholder,
inputPlaceholder: AppLocalizations.of(context)!
.messageInputPlaceholder,
attachmentButtonAccessibilityLabel:
AppLocalizations.of(context)!
.tooltipAttachment,
@ -1823,10 +1777,10 @@ class _MainAppState extends State<MainApp> {
theme: (Theme.of(context).brightness ==
Brightness.light)
? DefaultChatTheme(
backgroundColor: (theme ?? ThemeData())
.colorScheme
.surface,
primaryColor: (theme ?? ThemeData()).colorScheme.primary,
backgroundColor:
themeLight().colorScheme.surface,
primaryColor:
themeLight().colorScheme.primary,
attachmentButtonIcon: !multimodal
? (prefs?.getBool("voiceModeEnabled") ?? false)
? Icon(Icons.headphones_rounded, color: Theme.of(context).iconTheme.color)
@ -1851,9 +1805,9 @@ class _MainAppState extends State<MainApp> {
),
sendButtonMargin: EdgeInsets.zero,
attachmentButtonMargin: EdgeInsets.zero,
inputBackgroundColor: (theme ?? ThemeData()).colorScheme.onSurface.withAlpha(10),
inputTextColor: (theme ?? ThemeData()).colorScheme.onSurface,
inputBorderRadius: const BorderRadius.all(Radius.circular(64)),
inputBackgroundColor: themeLight().colorScheme.onSurface.withAlpha(10),
inputTextColor: themeLight().colorScheme.onSurface,
inputBorderRadius: BorderRadius.circular(32),
inputPadding: const EdgeInsets.all(16),
inputMargin: EdgeInsets.only(left: (MediaQuery.of(context).viewInsets.bottom == 0.0 && !desktopFeature()) ? 8 : 6, right: (MediaQuery.of(context).viewInsets.bottom == 0.0 && !desktopFeature()) ? 8 : 6, bottom: (MediaQuery.of(context).viewInsets.bottom == 0.0 && !desktopFeature()) ? 0 : 8),
messageMaxWidth: (MediaQuery.of(context).size.width >= 1000)
@ -1864,9 +1818,9 @@ class _MainAppState extends State<MainApp> {
: 700
: 440)
: DarkChatTheme(
backgroundColor: (themeDark ?? ThemeData.dark()).colorScheme.surface,
primaryColor: (themeDark ?? ThemeData.dark()).colorScheme.primary.withAlpha(40),
secondaryColor: (themeDark ?? ThemeData.dark()).colorScheme.primary.withAlpha(20),
backgroundColor: themeDark().colorScheme.surface,
primaryColor: themeDark().colorScheme.primary.withAlpha(40),
secondaryColor: themeDark().colorScheme.primary.withAlpha(20),
attachmentButtonIcon: !multimodal
? (prefs?.getBool("voiceModeEnabled") ?? false)
? Icon(Icons.headphones_rounded, color: Theme.of(context).iconTheme.color)
@ -1891,8 +1845,8 @@ class _MainAppState extends State<MainApp> {
),
sendButtonMargin: EdgeInsets.zero,
attachmentButtonMargin: EdgeInsets.zero,
inputBackgroundColor: (themeDark ?? ThemeData()).colorScheme.onSurface.withAlpha(40),
inputTextColor: (themeDark ?? ThemeData()).colorScheme.onSurface,
inputBackgroundColor: themeDark().colorScheme.onSurface.withAlpha(40),
inputTextColor: themeDark().colorScheme.onSurface,
inputBorderRadius: const BorderRadius.all(Radius.circular(64)),
inputPadding: const EdgeInsets.all(16),
inputMargin: EdgeInsets.only(left: 8, right: 8, bottom: (MediaQuery.of(context).viewInsets.bottom == 0.0 && !desktopFeature()) ? 0 : 8),

View File

@ -1,12 +1,13 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:ollama_app/worker/theme.dart';
import 'main.dart';
import 'worker/haptic.dart';
import 'worker/update.dart';
import 'worker/desktop.dart';
import 'package:ollama_app/worker/setter.dart';
import 'worker/setter.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'settings/behavior.dart';
@ -31,6 +32,7 @@ Widget toggle(BuildContext context, String text, bool value,
var space = ""; // Invisible character: U+2063
var spacePlus = " $space";
return InkWell(
enableFeedback: false,
splashFactory: NoSplash.splashFactory,
highlightColor: Colors.transparent,
hoverColor: Colors.transparent,
@ -71,26 +73,24 @@ Widget toggle(BuildContext context, String text, bool value,
color: disabled ? Colors.grey : null,
backgroundColor:
(Theme.of(context).brightness == Brightness.light)
? (theme ?? ThemeData()).colorScheme.surface
: (themeDark ?? ThemeData.dark())
.colorScheme
.surface))),
? themeLight().colorScheme.surface
: themeDark().colorScheme.surface))),
Container(
padding: const EdgeInsets.only(left: 16),
color: (Theme.of(context).brightness == Brightness.light)
? (theme ?? ThemeData()).colorScheme.surface
: (themeDark ?? ThemeData.dark()).colorScheme.surface,
? themeLight().colorScheme.surface
: themeDark().colorScheme.surface,
child: SizedBox(
height: 40,
child: Switch(
value: value,
onChanged: disabled
? (p0) {
selectionHaptic();
if (onDisabledTap != null) {
onDisabledTap();
}
}
? (onDisabledTap != null)
? (p0) {
selectionHaptic();
onDisabledTap();
}
: null
: onChanged,
activeTrackColor: disabled
? Theme.of(context).colorScheme.primary.withAlpha(50)
@ -171,6 +171,7 @@ Widget button(String text, IconData? icon, void Function()? onPressed,
? const EdgeInsets.only(top: 8, bottom: 8)
: EdgeInsets.zero,
child: InkWell(
enableFeedback: false,
onTap: disabled
? () {
selectionHaptic();
@ -178,7 +179,11 @@ Widget button(String text, IconData? icon, void Function()? onPressed,
onDisabledTap();
}
}
: onPressed,
: (onPressed == null && (onLongTap != null || onDoubleTap != null))
? () {
selectionHaptic();
}
: onPressed,
onLongPress: (description != null && context != null)
? desktopLayoutNotRequired(context)
? null
@ -305,7 +310,11 @@ class _ScreenSettingsState extends State<ScreenSettings> {
void initState() {
super.initState();
WidgetsFlutterBinding.ensureInitialized();
checkHost();
if ((Uri.parse(hostInputController.text.trim().removeSuffix("/").trim())
.toString() !=
fixedHost)) {
checkHost();
}
updatesSupported(setState, true);
}

View File

@ -1,17 +1,18 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:ollama_app/worker/haptic.dart';
import 'package:ollama_app/worker/setter.dart';
import 'package:speech_to_text/speech_to_text.dart' as stt;
import 'package:ollama_dart/ollama_dart.dart' as llama;
import 'package:datetime_loop/datetime_loop.dart';
// import 'package:volume_controller/volume_controller.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'main.dart';
import 'worker/sender.dart';
import 'worker/haptic.dart';
import 'worker/setter.dart';
import 'worker/theme.dart';
import 'settings/voice.dart';
class ScreenVoice extends StatefulWidget {
@ -34,47 +35,6 @@ class _ScreenVoiceState extends State<ScreenVoice> {
bool intendedStop = false;
void setBrightness() {
WidgetsBinding.instance.platformDispatcher.onPlatformBrightnessChanged =
() {
// invert colors used, because brightness not updated yet
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor:
(prefs!.getString("brightness") ?? "system") == "system"
? ((MediaQuery.of(context).platformBrightness ==
Brightness.light)
? (themeDark ?? ThemeData.dark()).colorScheme.surface
: (theme ?? ThemeData()).colorScheme.surface)
: (prefs!.getString("brightness") == "dark"
? (themeDark ?? ThemeData()).colorScheme.surface
: (theme ?? ThemeData.dark()).colorScheme.surface),
systemNavigationBarIconBrightness:
(((prefs!.getString("brightness") ?? "system") == "system" &&
MediaQuery.of(context).platformBrightness ==
Brightness.dark) ||
prefs!.getString("brightness") == "light")
? Brightness.dark
: Brightness.light));
};
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor:
(prefs!.getString("brightness") ?? "system") == "system"
? ((MediaQuery.of(context).platformBrightness ==
Brightness.light)
? (theme ?? ThemeData.dark()).colorScheme.surface
: (themeDark ?? ThemeData()).colorScheme.surface)
: (prefs!.getString("brightness") == "dark"
? (themeDark ?? ThemeData()).colorScheme.surface
: (theme ?? ThemeData.dark()).colorScheme.surface),
systemNavigationBarIconBrightness:
(((prefs!.getString("brightness") ?? "system") == "system" &&
MediaQuery.of(context).platformBrightness ==
Brightness.light) ||
prefs!.getString("brightness") == "light")
? Brightness.dark
: Brightness.light));
}
void process() async {
setState(() {
speaking = true;
@ -171,75 +131,19 @@ class _ScreenVoiceState extends State<ScreenVoice> {
aiText = currentText;
lightHaptic();
});
// var volume = await VolumeController().getVolume();
// var voicesTmp1 = await voice.getLanguages;
// var voices = jsonEncode(voicesTmp1);
// var isVoiceAvailable = (await voice.isLanguageAvailable(
// (prefs!.getString("voiceLanguage") ?? "en_US")
// .replaceAll("_", "-")))
// .toString();
// var voices2Tmp1 = await speech.locales();
// var voices2Tmp2 = [];
// for (var voice in voices2Tmp1) {
// voices2Tmp2.add(voice.localeId.replaceAll("_", "-"));
// }
// var voices2 = jsonEncode(voices2Tmp2);
// await showDialog(
// // ignore: use_build_context_synchronously
// context: context,
// builder: (context) {
// return Dialog.fullscreen(
// child: ListView(children: [
// const Row(
// crossAxisAlignment: CrossAxisAlignment.center,
// mainAxisSize: MainAxisSize.max,
// children: [
// Expanded(child: Divider(color: Colors.red)),
// SizedBox(width: 8),
// Text("START", style: TextStyle(color: Colors.red)),
// SizedBox(width: 8),
// Expanded(child: Divider(color: Colors.red))
// ]),
// Text((prefs!.getString("voiceLanguage") ?? "en_US")
// .replaceAll("_", "-")),
// const Divider(),
// Text(volume.toString()),
// const Divider(),
// Text(voices),
// const Divider(),
// Text(voicesTmp1
// .contains((prefs!.getString("voiceLanguage") ?? "en_US")
// .replaceAll("_", "-"))
// .toString()),
// const Divider(),
// Text(isVoiceAvailable),
// const Divider(),
// Text(voices2),
// const Divider(),
// Text(voices2Tmp2
// .contains((prefs!.getString("voiceLanguage") ?? "en_US")
// .replaceAll("_", "-"))
// .toString()),
// const Divider(),
// Text(speech.isAvailable.toString()),
// const Row(
// crossAxisAlignment: CrossAxisAlignment.center,
// mainAxisSize: MainAxisSize.max,
// children: [
// Expanded(child: Divider(color: Colors.red)),
// SizedBox(width: 8),
// Text("END", style: TextStyle(color: Colors.red)),
// SizedBox(width: 8),
// Expanded(child: Divider(color: Colors.red))
// ])
// ]));
// });
if (done) {
aiThinking = false;
heavyHaptic();
if (currentText.isEmpty) {
text = "";
speaking = false;
try {
setState(() {});
} catch (_) {}
return;
}
if ((await voice.getLanguages as List).contains(
(prefs!.getString("voiceLanguage") ?? "en_US")
.replaceAll("_", "-"))) {
@ -270,21 +174,10 @@ class _ScreenVoiceState extends State<ScreenVoice> {
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
WidgetsBinding.instance.platformDispatcher.onPlatformBrightnessChanged =
() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor:
(themeDark ?? ThemeData.dark()).colorScheme.surface,
systemNavigationBarIconBrightness: Brightness.dark));
};
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor:
(themeDark ?? ThemeData.dark()).colorScheme.surface,
systemNavigationBarIconBrightness: Brightness.dark));
setState(() {});
});
resetSystemNavigation(context,
statusBarColor: themeDark().colorScheme.surface,
systemNavigationBarColor: themeDark().colorScheme.surface,
delay: const Duration(milliseconds: 10));
void load() async {
var tmp = await speech.locales();
@ -306,10 +199,11 @@ class _ScreenVoiceState extends State<ScreenVoice> {
@override
Widget build(BuildContext context) {
return Theme(
data: themeDark!,
data: themeDark(),
child: PopScope(
canPop: !aiThinking,
onPopInvoked: (didPop) {
if (!didPop) return;
speaking = false;
voice.stop();
if (chatUuid != null) {
@ -317,13 +211,12 @@ class _ScreenVoiceState extends State<ScreenVoice> {
}
settingsOpen = false;
logoVisible = true;
setBrightness();
resetSystemNavigation(context);
},
child: Scaffold(
appBar: AppBar(
leading: IconButton(
onPressed: () {
speaking = false;
Navigator.of(context).pop();
},
icon: const Icon(Icons.close_rounded,
@ -332,7 +225,11 @@ class _ScreenVoiceState extends State<ScreenVoice> {
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Text(model!.split(":")[0],
child: Text(
(model ??
AppLocalizations.of(context)!
.noSelectedModel)
.split(":")[0],
textAlign: TextAlign.center,
overflow: TextOverflow.fade,
style: const TextStyle(
@ -345,11 +242,11 @@ class _ScreenVoiceState extends State<ScreenVoice> {
speaking = false;
settingsOpen = false;
logoVisible = true;
setBrightness();
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) =>
const ScreenSettingsVoice()));
resetSystemNavigation(context);
},
icon: const Icon(
Icons.settings_rounded,
@ -411,8 +308,9 @@ class _ScreenVoiceState extends State<ScreenVoice> {
process();
},
child: CircleAvatar(
backgroundColor: themeDark!
.colorScheme.primary
backgroundColor: themeDark()
.colorScheme
.primary
.withAlpha(
!speaking ? 200 : 255),
child: AnimatedSwitcher(
@ -421,19 +319,23 @@ class _ScreenVoiceState extends State<ScreenVoice> {
child: speaking
? aiThinking
? Icon(Icons.auto_awesome_rounded,
color: themeDark!
color: themeDark()
.colorScheme
.secondary,
key: const ValueKey(
"aiThinking"))
: sttDone
? Icon(Icons.volume_up_rounded,
color: themeDark!
color: themeDark()
.colorScheme
.secondary,
key: const ValueKey(
"tts"))
: Icon(Icons.mic_rounded, color: themeDark!.colorScheme.secondary, key: const ValueKey("stt"))
: Icon(Icons.mic_rounded,
color: themeDark()
.colorScheme
.secondary,
key: const ValueKey("stt"))
: null)))),
);
}))),

View File

@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'main.dart';
import 'worker/theme.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
import 'package:transparent_image/transparent_image.dart';
@ -17,57 +17,6 @@ class _ScreenWelcomeState extends State<ScreenWelcome> {
final _pageController = PageController();
int page = 0;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
await Future.delayed(const Duration(milliseconds: 10));
WidgetsBinding.instance.platformDispatcher.onPlatformBrightnessChanged =
() {
// invert colors used, because brightness not updated yet
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor:
(prefs!.getString("brightness") ?? "system") == "system"
? ((MediaQuery.of(context).platformBrightness ==
Brightness.light)
? Colors.grey[900]
: Colors.grey[100])
: (prefs!.getString("brightness") == "dark"
? Colors.grey[900]
: Colors.grey[100]),
systemNavigationBarIconBrightness:
(((prefs!.getString("brightness") ?? "system") == "system" &&
MediaQuery.of(context).platformBrightness ==
Brightness.dark) ||
prefs!.getString("brightness") == "light")
? Brightness.dark
: Brightness.light));
};
// brightness changed function not run at first startup
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor:
(prefs!.getString("brightness") ?? "system") == "system"
// ignore: use_build_context_synchronously
? ((MediaQuery.of(context).platformBrightness ==
Brightness.light)
? Colors.grey[100]
: Colors.grey[900])
: (prefs!.getString("brightness") == "dark"
? Colors.grey[900]
: Colors.grey[100]),
systemNavigationBarIconBrightness:
(((prefs!.getString("brightness") ?? "system") == "system" &&
// ignore: use_build_context_synchronously
MediaQuery.of(context).platformBrightness ==
Brightness.light) ||
prefs!.getString("brightness") == "light")
? Brightness.dark
: Brightness.light));
});
}
@override
Widget build(BuildContext context) {
precacheImage(const AssetImage("assets/welcome/1.png"), context);
@ -76,6 +25,20 @@ class _ScreenWelcomeState extends State<ScreenWelcome> {
precacheImage(const AssetImage("assets/welcome/1dark.png"), context);
precacheImage(const AssetImage("assets/welcome/2dark.png"), context);
precacheImage(const AssetImage("assets/welcome/3dark.png"), context);
resetSystemNavigation(context,
systemNavigationBarColor:
(prefs!.getString("brightness") ?? "system") == "system"
// ignore: use_build_context_synchronously
? ((MediaQuery.of(context).platformBrightness ==
Brightness.light)
? Colors.grey[100]
: Colors.grey[900])
: (prefs!.getString("brightness") == "dark"
? Colors.grey[900]
: Colors.grey[100]),
delay: const Duration(milliseconds: 10));
return Scaffold(
bottomNavigationBar: BottomSheet(
enableDrag: false,
@ -94,73 +57,26 @@ class _ScreenWelcomeState extends State<ScreenWelcome> {
effect: ExpandingDotsEffect(
activeDotColor: (Theme.of(context).brightness ==
Brightness.light)
? (theme ?? ThemeData()).colorScheme.primary
: (themeDark ?? ThemeData.dark())
.colorScheme
.primary)),
? themeLight().colorScheme.primary
: themeDark().colorScheme.primary)),
]));
}),
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
floatingActionButton: FloatingActionButton(
onPressed: () {
if (page < 2) {
_pageController.nextPage(
duration: const Duration(milliseconds: 250),
curve: Curves.easeInOut);
} else {
prefs!.setBool("welcomeFinished", true);
WidgetsBinding.instance.platformDispatcher
.onPlatformBrightnessChanged = () {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor:
(prefs!.getString("brightness") ?? "system") == "system"
? ((MediaQuery.of(context).platformBrightness ==
Brightness.light)
? (themeDark ?? ThemeData.dark())
.colorScheme
.surface
: (theme ?? ThemeData()).colorScheme.surface)
: (prefs!.getString("brightness") == "dark"
? (themeDark ?? ThemeData()).colorScheme.surface
: (theme ?? ThemeData.dark())
.colorScheme
.surface),
systemNavigationBarIconBrightness:
(((prefs!.getString("brightness") ?? "system") ==
"system" &&
MediaQuery.of(context).platformBrightness ==
Brightness.dark) ||
prefs!.getString("brightness") == "light")
? Brightness.dark
: Brightness.light));
};
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor:
(prefs!.getString("brightness") ?? "system") == "system"
? ((MediaQuery.of(context).platformBrightness ==
Brightness.light)
? (theme ?? ThemeData.dark()).colorScheme.surface
: (themeDark ?? ThemeData()).colorScheme.surface)
: (prefs!.getString("brightness") == "dark"
? (themeDark ?? ThemeData()).colorScheme.surface
: (theme ?? ThemeData.dark())
.colorScheme
.surface),
systemNavigationBarIconBrightness:
(((prefs!.getString("brightness") ?? "system") ==
"system" &&
MediaQuery.of(context).platformBrightness ==
Brightness.light) ||
prefs!.getString("brightness") == "light")
? Brightness.dark
: Brightness.light));
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => const MainApp()));
}
},
child: Icon((page < 2) ? Icons.arrow_forward : Icons.check_rounded),
),
onPressed: () {
if (page < 2) {
_pageController.nextPage(
duration: const Duration(milliseconds: 250),
curve: Curves.easeInOut);
} else {
prefs!.setBool("welcomeFinished", true);
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => const MainApp()));
}
},
child: (page < 2)
? const Icon(Icons.arrow_forward)
: const Icon(Icons.check_rounded)),
body: SafeArea(
child: Column(children: [
Expanded(

View File

@ -12,6 +12,8 @@ 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';
import 'package:url_launcher/url_launcher.dart';
class ScreenSettingsInterface extends StatefulWidget {
@ -132,6 +134,7 @@ class _ScreenSettingsInterfaceState extends State<ScreenSettingsInterface> {
.settingsKeepModelLoadedAlways,
int.parse(prefs!.getString("keepAlive") ?? "300") == -1,
(value) {
selectionHaptic();
setState(() {
if (value) {
prefs!.setString("keepAlive", "-1");
@ -146,6 +149,7 @@ class _ScreenSettingsInterfaceState extends State<ScreenSettingsInterface> {
.settingsKeepModelLoadedNever,
int.parse(prefs!.getString("keepAlive") ?? "300") == 0,
(value) {
selectionHaptic();
setState(() {
if (value) {
prefs!.setString("keepAlive", "0");
@ -165,6 +169,7 @@ class _ScreenSettingsInterfaceState extends State<ScreenSettingsInterface> {
: AppLocalizations.of(context)!
.settingsKeepModelLoadedFor,
Icons.snooze_rounded, () async {
selectionHaptic();
bool loaded = false;
await showDialog(
context: context,
@ -412,19 +417,74 @@ class _ScreenSettingsInterfaceState extends State<ScreenSettingsInterface> {
})
: const SizedBox.shrink(),
titleDivider(),
toggle(context, "Fix to code block not scrollable",
(prefs!.getBool("fixCodeblockScroll") ?? false),
(value) {
prefs!.setBool("fixCodeblockScroll", value);
if ((prefs!.getBool("fixCodeblockScroll") ?? false) ==
false) {
prefs!.remove("fixCodeblockScroll");
}
button(AppLocalizations.of(context)!.settingsTemporaryFixes,
Icons.fast_forward_rounded, () {
selectionHaptic();
setState(() {});
}, onLongTap: () {
launchUrl(Uri.parse(
"https://github.com/JHubi1/ollama-app/issues/26"));
showModalBottomSheet(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (context, setState) {
return Container(
width: double.infinity,
padding: EdgeInsets.only(
left: 16,
right: 16,
top: 16,
bottom: desktopLayout(context) ? 16 : 0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
button(
AppLocalizations.of(context)!
.settingsTemporaryFixesDescription,
Icons.info_rounded,
null,
color: Colors.grey.harmonizeWith(
Theme.of(context)
.colorScheme
.primary)),
button(
AppLocalizations.of(context)!
.settingsTemporaryFixesInstructions,
Icons.warning_rounded,
null,
color: Colors.orange.harmonizeWith(
Theme.of(context)
.colorScheme
.primary)),
titleDivider(),
// Text(
// AppLocalizations.of(context)!
// .settingsTemporaryFixesNoFixes,
// style: const TextStyle(
// color: Colors.grey)),
toggle(
context,
"Fixing code block not scrollable",
(prefs!.getBool(
"fixCodeblockScroll") ??
false), (value) {
selectionHaptic();
prefs!.setBool(
"fixCodeblockScroll", value);
if ((prefs!.getBool(
"fixCodeblockScroll") ??
false) ==
false) {
prefs!.remove("fixCodeblockScroll");
}
setState(() {});
}, onLongTap: () {
selectionHaptic();
launchUrl(Uri.parse(
"https://github.com/JHubi1/ollama-app/issues/26"));
}),
const SizedBox(height: 16)
]),
);
});
});
}),
const SizedBox(height: 16)
]),

View File

@ -2,6 +2,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:ollama_app/worker/haptic.dart';
import 'package:ollama_app/worker/theme.dart';
import '../main.dart';
// import '../worker/haptic.dart';
@ -281,21 +282,21 @@ class _ScreenSettingsVoiceState extends State<ScreenSettingsVoice> {
!(prefs?.getBool("useDeviceTheme") ??
false))
? ((MediaQuery.of(context).platformBrightness == Brightness.light)
? (theme ?? ThemeData()).colorScheme.secondary
: (themeDark ?? ThemeData.dark()).colorScheme.secondary)
? themeLight().colorScheme.secondary
: themeDark().colorScheme.secondary)
: null,
labelStyle: (usedIndex == index &&
!(prefs?.getBool("useDeviceTheme") ??
false))
? TextStyle(
color: (MediaQuery.of(context).platformBrightness == Brightness.light) ? (theme ?? ThemeData()).colorScheme.secondary : (themeDark ?? ThemeData.dark()).colorScheme.secondary)
color: (MediaQuery.of(context).platformBrightness == Brightness.light) ? themeLight().colorScheme.secondary : themeDark().colorScheme.secondary)
: null,
selectedColor: (prefs?.getBool("useDeviceTheme") ??
false)
? null
: (MediaQuery.of(context).platformBrightness == Brightness.light)
? (theme ?? ThemeData()).colorScheme.primary
: (themeDark ?? ThemeData.dark()).colorScheme.primary,
? themeLight().colorScheme.primary
: themeDark().colorScheme.primary,
onSelected:
(bool
selected) {

View File

@ -111,6 +111,9 @@ Future<String> send(String value, BuildContext context, Function setState,
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(AppLocalizations.of(context)!.noHostSelected),
showCloseIcon: true));
if (onStream != null) {
onStream("", true);
}
return "";
}
@ -120,6 +123,9 @@ Future<String> send(String value, BuildContext context, Function setState,
content: Text(AppLocalizations.of(context)!.noModelSelected),
showCloseIcon: true));
}
if (onStream != null) {
onStream("", true);
}
return "";
}

View File

@ -8,6 +8,7 @@ import 'desktop.dart';
import 'haptic.dart';
import '../main.dart';
import 'sender.dart';
import 'theme.dart';
import 'package:dartx/dartx.dart';
import 'package:ollama_dart/ollama_dart.dart' as llama;
@ -215,10 +216,10 @@ void setModel(BuildContext context, Function setState) {
? ((MediaQuery.of(context)
.platformBrightness ==
Brightness.light)
? (theme ?? ThemeData())
? themeLight()
.colorScheme
.secondary
: (themeDark ?? ThemeData.dark())
: themeDark()
.colorScheme
.secondary)
: null,
@ -230,11 +231,10 @@ void setModel(BuildContext context, Function setState) {
color: (MediaQuery.of(context)
.platformBrightness ==
Brightness.light)
? (theme ?? ThemeData())
? themeLight()
.colorScheme
.secondary
: (themeDark ??
ThemeData.dark())
: themeDark()
.colorScheme
.secondary)
: null,
@ -245,10 +245,10 @@ void setModel(BuildContext context, Function setState) {
: (MediaQuery.of(context)
.platformBrightness ==
Brightness.light)
? (theme ?? ThemeData())
?themeLight()
.colorScheme
.primary
: (themeDark ?? ThemeData.dark())
: themeDark()
.colorScheme
.primary,
onSelected: (bool selected) {

100
lib/worker/theme.dart Normal file
View File

@ -0,0 +1,100 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import '../main.dart';
ColorScheme? colorSchemeLight;
ColorScheme? colorSchemeDark;
void resetSystemNavigation(BuildContext context,
{Color? color,
Color? statusBarColor,
Color? systemNavigationBarColor,
Duration? delay}) {
ColorScheme getColorScheme() {
final ColorScheme schemeLight = themeLight().colorScheme;
final ColorScheme schemeDark = themeDark().colorScheme;
if (themeMode() == ThemeMode.system) {
if (MediaQuery.of(context).platformBrightness == Brightness.light) {
return schemeLight;
} else {
return schemeDark;
}
} else {
if (themeMode() == ThemeMode.light) {
return schemeLight;
} else {
return schemeDark;
}
}
}
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (delay != null) {
await Future.delayed(delay);
}
color ??= getColorScheme().surface;
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarIconBrightness:
(((statusBarColor != null) ? statusBarColor : color)!
.computeLuminance() >
0.179)
? Brightness.dark
: Brightness.light,
statusBarColor:
(((statusBarColor != null) ? statusBarColor : color)!.value !=
getColorScheme().surface.value)
? (statusBarColor != null)
? statusBarColor
: color
: Colors.transparent,
systemNavigationBarColor:
(systemNavigationBarColor != null) ? systemNavigationBarColor : color,
));
});
}
ThemeData themeLight() {
if (!(prefs?.getBool("useDeviceTheme") ?? false) ||
colorSchemeLight == null) {
return ThemeData.from(
colorScheme: const ColorScheme(
brightness: Brightness.light,
primary: Colors.black,
onPrimary: Colors.white,
secondary: Colors.white,
onSecondary: Colors.black,
error: Colors.red,
onError: Colors.white,
surface: Colors.white,
onSurface: Colors.black));
} else {
return ThemeData.from(colorScheme: colorSchemeLight!);
}
}
ThemeData themeDark() {
if (!(prefs?.getBool("useDeviceTheme") ?? false) || colorSchemeDark == null) {
return ThemeData.from(
colorScheme: const ColorScheme(
brightness: Brightness.dark,
primary: Colors.white,
onPrimary: Colors.black,
secondary: Colors.black,
onSecondary: Colors.white,
error: Colors.red,
onError: Colors.black,
surface: Colors.black,
onSurface: Colors.white));
} else {
return ThemeData.from(colorScheme: colorSchemeDark!);
}
}
ThemeMode themeMode() {
return ((prefs?.getString("brightness") ?? "system") == "system")
? ThemeMode.system
: ((prefs!.getString("brightness") == "dark")
? ThemeMode.dark
: ThemeMode.light);
}

7
scripts/base64.dart Normal file
View File

@ -0,0 +1,7 @@
// ignore_for_file: avoid_print
import 'dart:convert';
void main(List<String> args) {
print(base64Encode(utf8.encode(args.join(" "))));
}

View File

@ -3,10 +3,7 @@
import 'dart:io';
void main() async {
if (Directory.current.path.endsWith('scripts')) {
Directory.current = Directory.current.parent;
}
Directory.current = Directory(Platform.script.toFilePath()).parent.parent;
String flutterExecutable = Platform.isWindows ? 'flutter.bat' : 'flutter';
print("Build script for Ollama App by JHubi1");

10
test/functions.dart Normal file
View File

@ -0,0 +1,10 @@
import 'dart:math';
String random(int length) {
var rand = Random();
var codeUnits = List.generate(length, (index) {
return rand.nextInt(33) + 89;
});
return String.fromCharCodes(codeUnits);
}

View File

@ -1,30 +1,48 @@
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:ollama_app/main.dart';
import 'functions.dart';
import 'package:ollama_app/screen_settings.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MainApp());
testWidgets("Widget: button", (WidgetTester tester) async {
String text = random(10);
bool clicked = false;
await tester.pumpWidget(MaterialApp(
home: Scaffold(
body: button(text, Icons.add_rounded, () {
clicked = true;
}))));
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
expect(find.text(text), findsOneWidget);
expect(find.byIcon(Icons.add_rounded), findsOneWidget);
expect(clicked, false);
// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.tap(find.text(text));
await tester.pump();
expect(clicked, true);
});
testWidgets("Widget: toggle", (WidgetTester tester) async {
String text = random(10);
bool toggled = false;
await tester.pumpWidget(
MaterialApp(home: Scaffold(body: Builder(builder: (context) {
return toggle(context, text, toggled, (value) {
toggled = value;
});
}))));
// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
expect(find.textContaining(text), findsOneWidget);
expect(find.byType(Switch), findsOneWidget);
expect(toggled, false);
await tester.tap(find.textContaining(text));
await tester.pump();
expect(toggled, true);
toggled = false;
await tester.tap(find.byType(Switch));
await tester.pump();
expect(toggled, true);
});
}

View File

@ -10,6 +10,10 @@
"settingsUseSystem",
"settingsUseSystemDescription",
"settingsPreloadModels",
"settingsTemporaryFixes",
"settingsTemporaryFixesDescription",
"settingsTemporaryFixesInstructions",
"settingsTemporaryFixesNoFixes",
"settingsVoiceTtsNotSupported",
"settingsVoiceTtsNotSupportedDescription",
"settingsVoiceNotEnabled"
@ -26,6 +30,10 @@
"settingsUseSystem",
"settingsUseSystemDescription",
"settingsPreloadModels",
"settingsTemporaryFixes",
"settingsTemporaryFixesDescription",
"settingsTemporaryFixesInstructions",
"settingsTemporaryFixesNoFixes",
"settingsVoiceTtsNotSupported",
"settingsVoiceTtsNotSupportedDescription",
"settingsVoiceNotEnabled"
@ -42,6 +50,10 @@
"settingsUseSystem",
"settingsUseSystemDescription",
"settingsPreloadModels",
"settingsTemporaryFixes",
"settingsTemporaryFixesDescription",
"settingsTemporaryFixesInstructions",
"settingsTemporaryFixesNoFixes",
"settingsVoiceTtsNotSupported",
"settingsVoiceTtsNotSupportedDescription",
"settingsVoiceNotEnabled"
@ -58,6 +70,10 @@
"settingsUseSystem",
"settingsUseSystemDescription",
"settingsPreloadModels",
"settingsTemporaryFixes",
"settingsTemporaryFixesDescription",
"settingsTemporaryFixesInstructions",
"settingsTemporaryFixesNoFixes",
"settingsVoiceTtsNotSupported",
"settingsVoiceTtsNotSupportedDescription",
"settingsVoiceNotEnabled"