Skip to content

Commit

Permalink
(auto_hide) chore: migate
Browse files Browse the repository at this point in the history
  • Loading branch information
lollipopkit committed Jan 9, 2025
1 parent 618a9b0 commit 09112ab
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 34 deletions.
4 changes: 2 additions & 2 deletions lib/view/page/home/appbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class _CustomAppBar extends CustomAppBar {
// Use a SizedBox to avoid the title jumping when switching chats.
child: SizedBox(
key: Key(entity.id),
width: (_size?.width ?? 300) * 0.5,
width: (_windowSize?.width ?? 300) * 0.5,
child: Text(
_curChat?.name ?? l10n.untitled,
maxLines: 1,
Expand Down Expand Up @@ -95,7 +95,7 @@ final class _CustomAppBar extends CustomAppBar {
children: [
title,
SizedBox(
width: (_size?.width ?? 300) * 0.5,
width: (_windowSize?.width ?? 300) * 0.5,
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
Expand Down
33 changes: 19 additions & 14 deletions lib/view/page/home/bottom/bottom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ final class _HomeBottomState extends State<_HomeBottom> {
boxShadow: RNodes.dark.value ? _boxShadow : _boxShadowDark,
),
child: AnimatedPadding(
padding: EdgeInsets.only(bottom: MediaQuery.viewInsetsOf(context).bottom),
padding: EdgeInsets.only(
bottom: MediaQuery.viewInsetsOf(context).bottom),
curve: Curves.fastEaseInToSlowEaseOut,
duration: Durations.short1,
child: Column(
Expand All @@ -57,12 +58,14 @@ final class _HomeBottomState extends State<_HomeBottom> {
tooltip: l10n.newChat,
),
IconButton(
onPressed: () => _onTapRenameChat(_curChatId.value, context),
onPressed: () =>
_onTapRenameChat(_curChatId.value, context),
icon: const Icon(Icons.edit, size: 19),
tooltip: l10n.rename,
),
IconButton(
onPressed: () => _onTapDeleteChat(_curChatId.value, context),
onPressed: () =>
_onTapDeleteChat(_curChatId.value, context),
icon: const Icon(Icons.delete, size: 19),
tooltip: l10n.delete,
),
Expand Down Expand Up @@ -180,17 +183,19 @@ final class _HomeBottomState extends State<_HomeBottom> {
buttonItems: buttonItems,
);
},
suffix: _loadingChatIds.listenVal((chats) {
final isWorking = chats.contains(_curChatId.value);
return isWorking
? IconButton(
onPressed: () => _onStopStreamSub(_curChatId.value),
icon: const Icon(Icons.stop),
)
: IconButton(
onPressed: () => _onCreateRequest(context, _curChatId.value),
icon: const Icon(Icons.send, size: 19),
);
suffix: _curChatId.listenVal((chatId) {
return _loadingChatIds.listenVal((chats) {
final isWorking = chats.contains(chatId);
return isWorking
? IconButton(
onPressed: () => _onStopStreamSub(chatId),
icon: const Icon(Icons.stop),
)
: IconButton(
onPressed: () => _onCreateRequest(context, _curChatId.value),
icon: const Icon(Icons.send, size: 19),
);
});
}),
);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/view/page/home/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class _ChatPageState extends State<_ChatPage>
Widget _buildFAB() {
return AutoHide(
key: _chatFabAutoHideKey,
controller: _chatScrollCtrl,
scrollController: _chatScrollCtrl,
hideController: _autoHideCtrl,
direction: AxisDirection.right,
offset: 75,
child: ListenBuilder(
Expand Down
6 changes: 1 addition & 5 deletions lib/view/page/home/ctrl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void _onStopStreamSub(String chatId) async {
_chatStreamSubs[chatId]?.cancel();
_loadingChatIds.value.remove(chatId);
_loadingChatIds.notify();
_chatFabAutoHideKey.currentState?.autoHideEnabled = true;
_autoHideCtrl.autoHideEnabled = true;
}

void _onShareChat(BuildContext context) async {
Expand Down Expand Up @@ -611,7 +611,3 @@ Future<bool> _askToolConfirm(
void _onChatScroll() {
Funcs.throttle(_chatFabRN.notify, id: 'chat_fab_rn', duration: 30);
}

void _onIsWideChanged() {
_curPage.value = HomePageEnum.chat;
}
4 changes: 2 additions & 2 deletions lib/view/page/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ class _HomePageState extends State<HomePage>

@override
void didChangeDependencies() {
_size = MediaQuery.sizeOf(context);
_windowSize = MediaQuery.sizeOf(context);
RNodes.dark.value = context.isDark;
_isWide.value = (_size?.width ?? 0) > 639;
_isWide.value = (_windowSize?.width ?? 0) > 639;
super.didChangeDependencies();
_homeBottomRN.notify();
}
Expand Down
6 changes: 3 additions & 3 deletions lib/view/page/home/req.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void _onCreateRequest(BuildContext context, String chatId) async {

_loadingChatIds.value.add(chatId);
_loadingChatIds.notify();
_chatFabAutoHideKey.currentState?.autoHideEnabled = false;
_autoHideCtrl.autoHideEnabled = false;

return await _onCreateText(context, chatId, input, _filePicked.value?.url);
}
Expand Down Expand Up @@ -242,7 +242,7 @@ Future<void> _onCreateText(
_onStopStreamSub(chatId);
_loadingChatIds.value.remove(chatId);
_loadingChatIds.notify();
_chatFabAutoHideKey.currentState?.autoHideEnabled = true;
_autoHideCtrl.autoHideEnabled = true;

_storeChat(chatId);
// Wait for db to store the chat
Expand Down Expand Up @@ -569,7 +569,7 @@ void _onErr(Object e, StackTrace s, String chatId, String action) {
_onStopStreamSub(chatId);
_loadingChatIds.value.remove(chatId);
_loadingChatIds.notify();
_chatFabAutoHideKey.currentState?.autoHideEnabled = true;
_autoHideCtrl.autoHideEnabled = true;

final msg = '$e\n\n```$s```';
final workingChat = _allHistories[chatId];
Expand Down
2 changes: 1 addition & 1 deletion lib/view/page/home/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class _ChatSearchDelegate extends SearchDelegate<ChatHistory> {
return FutureWidget(
future: _filterChats(query),
loading: SizedBox(
width: _size?.width ?? 300,
width: _windowSize?.width ?? 300,
child: SizedLoading.medium,
),
error: (error, trace) {
Expand Down
11 changes: 8 additions & 3 deletions lib/view/page/home/var.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ final _curPage = HomePageEnum.chat.vn;

final _imeFocus = FocusNode();

Size? _size;
Size? _windowSize;
final _isWide = false.vn..addListener(_onIsWideChanged);
void _onIsWideChanged() {
_curPage.value = HomePageEnum.chat;
}

/// Set it as final, so we can scroll to it.
/// Mobile has higher density.
final _historyItemHeight = isDesktop ? 73.0 : 79.0;
// The pixel tollerance

/// The pixel tollerance
final _historyLocateTollerance = _historyItemHeight / 3;

const _durationShort = Durations.short4;
Expand All @@ -61,3 +64,5 @@ KeyboardCtrlListener? _keyboardSendListener;

/// If current `ts > this + duration`, then no delete confirmation required.
var _noChatDeleteConfirmTS = 0;

final _autoHideCtrl = AutoHideController();
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "v1.0.225"
resolved-ref: "9ca92213fea15b8c245ed2cc2958e14baea5cdbe"
ref: "v1.0.229"
resolved-ref: "73f53f155b28b4be6d5c4f84a94ebe9f96570580"
url: "https://github.com/lppcg/fl_lib"
source: git
version: "0.0.1"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies:
fl_lib:
git:
url: https://github.com/lppcg/fl_lib
ref: v1.0.225
ref: v1.0.229

dependency_overrides:
# fl_lib:
Expand Down

0 comments on commit 09112ab

Please sign in to comment.