diff --git a/lib/data/model/chat/history/history.ext.dart b/lib/data/model/chat/history/history.ext.dart index 481626d..98ef480 100644 --- a/lib/data/model/chat/history/history.ext.dart +++ b/lib/data/model/chat/history/history.ext.dart @@ -46,9 +46,7 @@ extension ChatHistoryX on ChatHistory { ); } - void save() { - Stores.history.put(this); - } + void save() => Stores.history.put(this); bool containsKeywords(List keywords) { return items.any( diff --git a/lib/view/page/backup/view.dart b/lib/view/page/backup/view.dart index c2c5c93..056512f 100644 --- a/lib/view/page/backup/view.dart +++ b/lib/view/page/backup/view.dart @@ -32,7 +32,6 @@ final class BackupPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - appBar: CustomAppBar(title: Text(libL10n.backup)), body: _buildBody(context), ); } diff --git a/lib/view/page/home/req.dart b/lib/view/page/home/req.dart index d4234fc..735840c 100644 --- a/lib/view/page/home/req.dart +++ b/lib/view/page/home/req.dart @@ -241,21 +241,29 @@ Future _onCreateText( _autoScroll(chatId); }, + onDone: () async { + _onStopStreamSub(chatId); + _loadingChatIds.remove(chatId); + _loadingChatIds.remove(assistReply.id); + _loadingChatIdRN.notify(); + _chatFabAutoHideKey.currentState?.autoHideEnabled = true; + + _storeChat(chatId); + // Wait for db to store the chat + await Future.delayed(const Duration(milliseconds: 300)); + BakSync.instance.sync(); + }, + onError: (e, s) { + _onErr(e, s, chatId, 'Listen text stream'); + _loadingChatIds.remove(chatId); + _loadingChatIds.remove(assistReply.id); + _loadingChatIdRN.notify(); + _chatFabAutoHideKey.currentState?.autoHideEnabled = true; + }, ); } catch (e, s) { _onErr(e, s, chatId, 'Listen text stream'); _loadingChatIds.remove(chatId); - } finally { - _onStopStreamSub(chatId); - _loadingChatIds.remove(chatId); - _loadingChatIds.remove(assistReply.id); - _loadingChatIdRN.notify(); - _chatFabAutoHideKey.currentState?.autoHideEnabled = true; - - _storeChat(chatId); - // Wait for db to store the chat - await Future.delayed(const Duration(milliseconds: 300)); - BakSync.instance.sync(); } } diff --git a/lib/view/page/settings/def.dart b/lib/view/page/settings/def.dart index 3220e44..35df6f5 100644 --- a/lib/view/page/settings/def.dart +++ b/lib/view/page/settings/def.dart @@ -14,6 +14,7 @@ enum SettingsTab { app, profile, tool, + bak, res, about, ; @@ -22,9 +23,21 @@ enum SettingsTab { app => libL10n.app, profile => l10n.profile, tool => l10n.tool, + bak => libL10n.backup, res => l10n.res, about => libL10n.about, }; + Widget get page => switch (this) { + app => const AppSettingsPage(), + profile => const ProfilePage(), + tool => const ToolPage(), + bak => const BackupPage(), + res => const ResPage(), + about => const AboutPage(), + }; + static List get tabs => values.map((e) => Tab(text: e.i18n)).toList(); + + static List get pages => values.map((e) => e.page).toList(); } diff --git a/lib/view/page/settings/setting.dart b/lib/view/page/settings/setting.dart index cb38e52..e29c117 100644 --- a/lib/view/page/settings/setting.dart +++ b/lib/view/page/settings/setting.dart @@ -14,6 +14,7 @@ import 'package:gpt_box/data/res/rnode.dart'; import 'package:gpt_box/data/res/url.dart'; import 'package:gpt_box/data/store/all.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:gpt_box/view/page/backup/view.dart'; import 'package:gpt_box/view/widget/audio.dart'; import 'package:icons_plus/icons_plus.dart'; import 'package:shortid/shortid.dart'; @@ -66,16 +67,7 @@ class _SettingsPageState extends State isScrollable: true, ), ), - body: TabBarView( - controller: _tabCtrl, - children: const [ - AppSettingsPage(), - ProfilePage(), - ToolPage(), - ResPage(), - AboutPage(), - ], - ), + body: TabBarView(controller: _tabCtrl, children: SettingsTab.pages), ); } }