Skip to content

Commit

Permalink
Merge pull request #93 from Iconica-Development/3.0.1
Browse files Browse the repository at this point in the history
fix: routing issues
  • Loading branch information
freekvandeven authored Jun 17, 2024
2 parents 5e4a9c7 + 2f2e2be commit 15f1574
Show file tree
Hide file tree
Showing 45 changed files with 423 additions and 429 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 3.0.1

- fix bug where you could make multiple groups quickly by routing back to the previous screen
- fix bug where you would route back to the user selection screen insterad of routing back to the chat overview screen
- Add onPopInvoked callback to the userstory to add custom behaviour for the back button on the chatscreen
- Handle overflows for users with a long name.
- Remove the scaffold backgrounds because they should be inherited from the scaffold theme

## 3.0.0

- Add theming
Expand Down
16 changes: 8 additions & 8 deletions packages/flutter_chat/lib/flutter_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
///
library flutter_chat;

export 'package:flutter_chat/src/chat_entry_widget.dart';
export 'package:flutter_chat/src/flutter_chat_navigator_userstory.dart';
export 'package:flutter_chat/src/flutter_chat_userstory.dart';
export 'package:flutter_chat/src/models/chat_configuration.dart';
export 'package:flutter_chat/src/routes.dart';
export 'package:flutter_chat_interface/flutter_chat_interface.dart';
export 'package:flutter_chat_local/local_chat_service.dart';
export 'package:flutter_chat_view/flutter_chat_view.dart';
export "package:flutter_chat/src/chat_entry_widget.dart";
export "package:flutter_chat/src/flutter_chat_navigator_userstory.dart";
export "package:flutter_chat/src/flutter_chat_userstory.dart";
export "package:flutter_chat/src/models/chat_configuration.dart";
export "package:flutter_chat/src/routes.dart";
export "package:flutter_chat_interface/flutter_chat_interface.dart";
export "package:flutter_chat_local/local_chat_service.dart";
export "package:flutter_chat_view/flutter_chat_view.dart";
8 changes: 4 additions & 4 deletions packages/flutter_chat/lib/src/chat_entry_widget.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async';
import "dart:async";

import 'package:flutter/material.dart';
import 'package:flutter_chat/flutter_chat.dart';
import "package:flutter/material.dart";
import "package:flutter_chat/flutter_chat.dart";

/// A widget representing an entry point for a chat UI.
class ChatEntryWidget extends StatefulWidget {
Expand Down Expand Up @@ -104,7 +104,7 @@ class _ChatEntryWidgetState extends State<ChatEntryWidget> {
),
child: Center(
child: Text(
'${snapshot.data ?? 0}',
"${snapshot.data ?? 0}",
style: widget.textStyle,
),
),
Expand Down
97 changes: 54 additions & 43 deletions packages/flutter_chat/lib/src/flutter_chat_navigator_userstory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//
// SPDX-License-Identifier: BSD-3-Clause

import 'package:flutter/material.dart';
import 'package:flutter_chat/flutter_chat.dart';
import "package:flutter/material.dart";
import "package:flutter_chat/flutter_chat.dart";

/// Navigates to the chat user story screen.
///
Expand All @@ -30,48 +30,53 @@ Widget _chatScreenRoute(
ChatUserStoryConfiguration configuration,
BuildContext context,
) =>
ChatScreen(
unreadMessageTextStyle: configuration.unreadMessageTextStyle,
service: configuration.chatService,
options: configuration.chatOptionsBuilder(context),
onNoChats: () async => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => _newChatScreenRoute(
configuration,
context,
),
),
),
onPressStartChat: () async {
if (configuration.onPressStartChat != null) {
return await configuration.onPressStartChat?.call();
}

return Navigator.of(context).push(
PopScope(
canPop: configuration.onPopInvoked == null,
onPopInvoked: (didPop) =>
configuration.onPopInvoked?.call(didPop, context),
child: ChatScreen(
unreadMessageTextStyle: configuration.unreadMessageTextStyle,
service: configuration.chatService,
options: configuration.chatOptionsBuilder(context),
onNoChats: () async => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => _newChatScreenRoute(
configuration,
context,
),
),
);
},
onPressChat: (chat) async =>
configuration.onPressChat?.call(context, chat) ??
await Navigator.of(context).push(
),
onPressStartChat: () async {
if (configuration.onPressStartChat != null) {
return await configuration.onPressStartChat?.call();
}

return Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => _chatDetailScreenRoute(
builder: (context) => _newChatScreenRoute(
configuration,
context,
chat.id!,
),
),
),
onDeleteChat: (chat) async =>
configuration.onDeleteChat?.call(context, chat) ??
configuration.chatService.chatOverviewService.deleteChat(chat),
deleteChatDialog: configuration.deleteChatDialog,
translations: configuration.translations,
);
},
onPressChat: (chat) async =>
configuration.onPressChat?.call(context, chat) ??
await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => _chatDetailScreenRoute(
configuration,
context,
chat.id!,
),
),
),
onDeleteChat: (chat) async =>
configuration.onDeleteChat?.call(context, chat) ??
configuration.chatService.chatOverviewService.deleteChat(chat),
deleteChatDialog: configuration.deleteChatDialog,
translations: configuration.translations,
),
);

/// Constructs the chat detail screen route widget.
Expand Down Expand Up @@ -218,7 +223,7 @@ Widget _newChatScreenRoute(
if (configuration.onPressCreateChat != null) return;
var chat = await configuration.chatService.chatOverviewService
.getChatByUser(user);
debugPrint('Chat is ${chat.id}');
debugPrint("Chat is ${chat.id}");
if (chat.id == null) {
chat = await configuration.chatService.chatOverviewService
.storeChatIfNot(
Expand All @@ -230,10 +235,13 @@ Widget _newChatScreenRoute(
if (context.mounted) {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => _chatDetailScreenRoute(
configuration,
context,
chat.id!,
builder: (context) => PopScope(
canPop: false,
child: _chatDetailScreenRoute(
configuration,
context,
chat.id!,
),
),
),
);
Expand Down Expand Up @@ -279,17 +287,20 @@ Widget _newGroupChatOverviewScreenRoute(
GroupChatModel(
canBeDeleted: true,
title: groupChatName,
imageUrl: 'https://picsum.photos/200/300',
imageUrl: "https://picsum.photos/200/300",
users: users,
),
);
if (context.mounted) {
await Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => _chatDetailScreenRoute(
configuration,
context,
chat.id!,
builder: (context) => PopScope(
canPop: false,
child: _chatDetailScreenRoute(
configuration,
context,
chat.id!,
),
),
),
);
Expand Down
53 changes: 23 additions & 30 deletions packages/flutter_chat/lib/src/flutter_chat_userstory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
//
// SPDX-License-Identifier: BSD-3-Clause

import 'package:flutter/material.dart';
import 'package:flutter_chat/flutter_chat.dart';
import 'package:flutter_chat/src/go_router.dart';
import 'package:go_router/go_router.dart';
import "package:flutter/material.dart";
import "package:flutter_chat/flutter_chat.dart";
import "package:flutter_chat/src/go_router.dart";
import "package:go_router/go_router.dart";

List<GoRoute> getChatStoryRoutes(
ChatUserStoryConfiguration configuration,
Expand All @@ -14,7 +14,6 @@ List<GoRoute> getChatStoryRoutes(
GoRoute(
path: ChatUserStoryRoutes.chatScreen,
pageBuilder: (context, state) {
var theme = Theme.of(context);
var service = configuration.chatServiceBuilder?.call(context) ??
configuration.chatService;
var chatScreen = ChatScreen(
Expand Down Expand Up @@ -43,24 +42,27 @@ List<GoRoute> getChatStoryRoutes(
return buildScreenWithoutTransition(
context: context,
state: state,
child: configuration.chatPageBuilder?.call(
context,
chatScreen,
) ??
Scaffold(
backgroundColor: theme.colorScheme.surface,
body: chatScreen,
),
child: PopScope(
canPop: configuration.onPopInvoked == null,
onPopInvoked: (didPop) =>
configuration.onPopInvoked?.call(didPop, context),
child: configuration.chatPageBuilder?.call(
context,
chatScreen,
) ??
Scaffold(
body: chatScreen,
),
),
);
},
),
GoRoute(
path: ChatUserStoryRoutes.chatDetailScreen,
pageBuilder: (context, state) {
var chatId = state.pathParameters['id'];
var chatId = state.pathParameters["id"];
var service = configuration.chatServiceBuilder?.call(context) ??
configuration.chatService;
var theme = Theme.of(context);

var chatDetailScreen = ChatDetailScreen(
chatTitleBuilder: configuration.chatTitleBuilder,
Expand Down Expand Up @@ -122,7 +124,6 @@ List<GoRoute> getChatStoryRoutes(
chatDetailScreen,
) ??
Scaffold(
backgroundColor: theme.colorScheme.surface,
body: chatDetailScreen,
),
);
Expand All @@ -133,7 +134,6 @@ List<GoRoute> getChatStoryRoutes(
pageBuilder: (context, state) {
var service = configuration.chatServiceBuilder?.call(context) ??
configuration.chatService;
var theme = Theme.of(context);

var newChatScreen = NewChatScreen(
options: configuration.chatOptionsBuilder(context),
Expand All @@ -156,7 +156,7 @@ List<GoRoute> getChatStoryRoutes(
}
if (context.mounted) {
await context.push(
ChatUserStoryRoutes.chatDetailViewPath(chat.id ?? ''),
ChatUserStoryRoutes.chatDetailViewPath(chat.id ?? ""),
);
}
},
Expand All @@ -172,7 +172,6 @@ List<GoRoute> getChatStoryRoutes(
newChatScreen,
) ??
Scaffold(
backgroundColor: theme.colorScheme.surface,
body: newChatScreen,
),
);
Expand All @@ -183,7 +182,6 @@ List<GoRoute> getChatStoryRoutes(
pageBuilder: (context, state) {
var service = configuration.chatServiceBuilder?.call(context) ??
configuration.chatService;
var theme = Theme.of(context);

var newGroupChatScreen = NewGroupChatScreen(
options: configuration.chatOptionsBuilder(context),
Expand All @@ -203,7 +201,6 @@ List<GoRoute> getChatStoryRoutes(
newGroupChatScreen,
) ??
Scaffold(
backgroundColor: theme.colorScheme.surface,
body: newGroupChatScreen,
),
);
Expand All @@ -215,7 +212,6 @@ List<GoRoute> getChatStoryRoutes(
var service = configuration.chatServiceBuilder?.call(context) ??
configuration.chatService;
var users = state.extra! as List<ChatUserModel>;
var theme = Theme.of(context);

var newGroupChatOverviewScreen = NewGroupChatOverviewScreen(
options: configuration.chatOptionsBuilder(context),
Expand All @@ -231,13 +227,13 @@ List<GoRoute> getChatStoryRoutes(
GroupChatModel(
canBeDeleted: true,
title: groupChatName,
imageUrl: 'https://picsum.photos/200/300',
imageUrl: "https://picsum.photos/200/300",
users: users,
),
);
if (context.mounted) {
context.go(
ChatUserStoryRoutes.chatDetailViewPath(chat.id ?? ''),
ChatUserStoryRoutes.chatDetailViewPath(chat.id ?? ""),
);
}
},
Expand All @@ -250,7 +246,6 @@ List<GoRoute> getChatStoryRoutes(
newGroupChatOverviewScreen,
) ??
Scaffold(
backgroundColor: theme.colorScheme.surface,
body: newGroupChatOverviewScreen,
),
);
Expand All @@ -259,12 +254,11 @@ List<GoRoute> getChatStoryRoutes(
GoRoute(
path: ChatUserStoryRoutes.chatProfileScreen,
pageBuilder: (context, state) {
var chatId = state.pathParameters['id'];
var userId = state.pathParameters['userId'];
var id = userId == 'null' ? null : userId;
var chatId = state.pathParameters["id"];
var userId = state.pathParameters["userId"];
var id = userId == "null" ? null : userId;
var service = configuration.chatServiceBuilder?.call(context) ??
configuration.chatService;
var theme = Theme.of(context);

var profileScreen = ChatProfileScreen(
translations: configuration.translationsBuilder?.call(context) ??
Expand All @@ -290,7 +284,6 @@ List<GoRoute> getChatStoryRoutes(
profileScreen,
) ??
Scaffold(
backgroundColor: theme.colorScheme.surface,
body: profileScreen,
),
);
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter_chat/lib/src/go_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//
// SPDX-License-Identifier: BSD-3-Clause

import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import "package:flutter/material.dart";
import "package:go_router/go_router.dart";

/// Builds a screen with a fade transition.
///
Expand Down
Loading

0 comments on commit 15f1574

Please sign in to comment.