feat: add chatTitle to baseScreenBuilder

This commit is contained in:
Freek van de Ven 2025-02-13 14:25:48 +01:00 committed by FlutterJoey
parent 8604ccada7
commit 281188c2b7
8 changed files with 20 additions and 17 deletions

View file

@ -10,6 +10,7 @@
- Added flutter_hooks as a dependency for easier state management
- Added FlutterChatDetailNavigatorUserstory that can be used to start the userstory from the chat detail screen without having the chat overview screen
- Changed the ChatDetailScreen to use the chatId instead of the ChatModel, the screen will now fetch the chat from the ChatService
- Changed baseScreenBuilder to include a chatTitle that can be used to show provide the title logic to apps that use the baseScreenBuilder
## 4.0.0
- Move to the new user story architecture

View file

@ -101,10 +101,12 @@ typedef TextInputBuilder = Widget Function(
);
/// The base screen builder
/// [title] is the title of the screen and can be null while loading
typedef BaseScreenBuilder = Widget Function(
BuildContext context,
ScreenType screenType,
PreferredSizeWidget appBar,
String? title,
Widget body,
);

View file

@ -120,6 +120,7 @@ class ChatDetailScreen extends HookWidget {
context,
mapScreenType,
appBar,
chatTitle.value,
body,
);
}

View file

@ -44,10 +44,13 @@ class ChatProfileScreen extends HookWidget {
return () => chatScope.popHandler.remove(onExit);
});
var appBar = _AppBar(
user: userModel,
chat: chatModel,
);
var chatTitle = userModel != null
? "${userModel!.fullname}"
: chatModel != null
? chatModel?.chatName ?? options.translations.groupNameEmpty
: "";
var appBar = _AppBar(title: chatTitle);
var body = _Body(
user: userModel,
@ -67,6 +70,7 @@ class ChatProfileScreen extends HookWidget {
context,
mapScreenType,
appBar,
chatTitle,
body,
);
}
@ -74,27 +78,17 @@ class ChatProfileScreen extends HookWidget {
class _AppBar extends StatelessWidget implements PreferredSizeWidget {
const _AppBar({
required this.user,
required this.chat,
required this.title,
});
final UserModel? user;
final ChatModel? chat;
final String title;
@override
Widget build(BuildContext context) {
var chatScope = ChatScope.of(context);
var options = chatScope.options;
var theme = Theme.of(context);
return AppBar(
iconTheme: theme.appBarTheme.iconTheme,
title: Text(
user != null
? "${user!.fullname}"
: chat != null
? chat?.chatName ?? options.translations.groupNameEmpty
: "",
),
title: Text(title),
);
}

View file

@ -35,6 +35,7 @@ class ChatScreen extends HookWidget {
Widget build(BuildContext context) {
var chatScope = ChatScope.of(context);
var options = chatScope.options;
var translations = options.translations;
useEffect(() {
if (onExit == null) return null;
@ -57,6 +58,7 @@ class ChatScreen extends HookWidget {
context,
mapScreenType,
const _AppBar(),
translations.chatsTitle,
_Body(
onPressChat: onPressChat,
onPressStartChat: onPressStartChat,

View file

@ -100,6 +100,7 @@ class _NewChatScreenState extends State<NewChatScreen> {
},
focusNode: _textFieldFocusNode,
),
options.translations.newChatTitle,
_Body(
isSearching: _isSearching,
onPressCreateGroupChat: widget.onPressCreateGroupChat,

View file

@ -58,6 +58,7 @@ class NewGroupChatOverview extends HookWidget {
context,
mapScreenType,
const _AppBar(),
options.translations.newGroupChatTitle,
_Body(
users: users,
onComplete: onComplete,

View file

@ -98,6 +98,7 @@ class _NewGroupChatScreenState extends State<NewGroupChatScreen> {
},
focusNode: _textFieldFocusNode,
),
options.translations.newGroupChatTitle,
_Body(
onSelectedUser: handleUserTap,
selectedUsers: selectedUsers,