Skip to content

Commit

Permalink
chore: updated package implementation calls to satisfy version updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Ephraim Nartey committed Nov 25, 2024
1 parent e85f00f commit b3fe248
Show file tree
Hide file tree
Showing 16 changed files with 2,939 additions and 1,152 deletions.
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({Key? key, required this.title}) : super(key: key);

final String title;

Expand Down Expand Up @@ -88,7 +88,7 @@ class _MyHomePageState extends State<MyHomePage> {

final imageData = await photo.readAsBytes();
final decodedImage = image.decodeImage(imageData);
final scaledImage = image.copyResize(decodedImage, width: 500);
final scaledImage = image.copyResize(decodedImage!, width: 500);
final jpg = image.encodeJpg(scaledImage, quality: 90);

final filePath = (await getTemporaryDirectory()).uri.resolve(
Expand Down
8 changes: 4 additions & 4 deletions lib/data/remote/service/chatwoot_client_auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class ChatwootClientAuthServiceImpl extends ChatwootClientAuthService {
createResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.CREATE_CONTACT_FAILED);
}
} on DioError catch (e) {
} on DioException catch (e) {
throw ChatwootClientException(
e.message, ChatwootClientExceptionType.CREATE_CONTACT_FAILED);
e.message ?? '', ChatwootClientExceptionType.CREATE_CONTACT_FAILED);
}
}

Expand All @@ -67,9 +67,9 @@ class ChatwootClientAuthServiceImpl extends ChatwootClientAuthService {
createResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.CREATE_CONVERSATION_FAILED);
}
} on DioError catch (e) {
} on DioException catch (e) {
throw ChatwootClientException(
e.message, ChatwootClientExceptionType.CREATE_CONVERSATION_FAILED);
e.message ?? '', ChatwootClientExceptionType.CREATE_CONVERSATION_FAILED);
}
}
}
24 changes: 12 additions & 12 deletions lib/data/remote/service/chatwoot_client_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class ChatwootClientServiceImpl extends ChatwootClientService {
createResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.SEND_MESSAGE_FAILED);
}
} on DioError catch (e) {
} on DioException catch (e) {
throw ChatwootClientException(
e.message, ChatwootClientExceptionType.SEND_MESSAGE_FAILED);
e.message ?? '', ChatwootClientExceptionType.SEND_MESSAGE_FAILED);
}
}

Expand All @@ -79,9 +79,9 @@ class ChatwootClientServiceImpl extends ChatwootClientService {
createResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.GET_MESSAGES_FAILED);
}
} on DioError catch (e) {
} on DioException catch (e) {
throw ChatwootClientException(
e.message, ChatwootClientExceptionType.GET_MESSAGES_FAILED);
e.message ?? '', ChatwootClientExceptionType.GET_MESSAGES_FAILED);
}
}

Expand All @@ -98,9 +98,9 @@ class ChatwootClientServiceImpl extends ChatwootClientService {
createResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.GET_CONTACT_FAILED);
}
} on DioError catch (e) {
} on DioException catch (e) {
throw ChatwootClientException(
e.message, ChatwootClientExceptionType.GET_CONTACT_FAILED);
e.message ?? '', ChatwootClientExceptionType.GET_CONTACT_FAILED);
}
}

Expand All @@ -119,9 +119,9 @@ class ChatwootClientServiceImpl extends ChatwootClientService {
createResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.GET_CONVERSATION_FAILED);
}
} on DioError catch (e) {
} on DioException catch (e) {
throw ChatwootClientException(
e.message, ChatwootClientExceptionType.GET_CONVERSATION_FAILED);
e.message ?? '', ChatwootClientExceptionType.GET_CONVERSATION_FAILED);
}
}

Expand All @@ -139,9 +139,9 @@ class ChatwootClientServiceImpl extends ChatwootClientService {
updateResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.UPDATE_CONTACT_FAILED);
}
} on DioError catch (e) {
} on DioException catch (e) {
throw ChatwootClientException(
e.message, ChatwootClientExceptionType.UPDATE_CONTACT_FAILED);
e.message ?? '', ChatwootClientExceptionType.UPDATE_CONTACT_FAILED);
}
}

Expand All @@ -160,9 +160,9 @@ class ChatwootClientServiceImpl extends ChatwootClientService {
updateResponse.statusMessage ?? "unknown error",
ChatwootClientExceptionType.UPDATE_MESSAGE_FAILED);
}
} on DioError catch (e) {
} on DioException catch (e) {
throw ChatwootClientException(
e.message, ChatwootClientExceptionType.UPDATE_MESSAGE_FAILED);
e.message ?? '', ChatwootClientExceptionType.UPDATE_MESSAGE_FAILED);
}
}

Expand Down
21 changes: 9 additions & 12 deletions lib/ui/chatwoot_chat_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,21 @@ class ChatwootChat extends StatefulWidget {
final double? onEndReachedThreshold;

/// See [Message.onMessageLongPress]
final void Function(types.Message)? onMessageLongPress;
final void Function(BuildContext context, types.Message)? onMessageLongPress;

/// See [Message.onMessageTap]
final void Function(types.Message)? onMessageTap;

/// See [Input.onSendPressed]
final void Function(types.PartialText)? onSendPressed;

/// See [Input.onTextChanged]
final void Function(String)? onTextChanged;

/// Show avatars for received messages.
final bool showUserAvatars;

/// Show user names for received messages.
final bool showUserNames;

final ChatwootChatTheme theme;
final ChatwootChatTheme? theme;

/// See [ChatwootL10n]
final ChatwootL10n l10n;
Expand Down Expand Up @@ -128,10 +125,9 @@ class ChatwootChat extends StatefulWidget {
this.onMessageLongPress,
this.onMessageTap,
this.onSendPressed,
this.onTextChanged,
this.showUserAvatars = true,
this.showUserNames = true,
this.theme = const ChatwootChatTheme(),
this.theme,
this.l10n = const ChatwootL10n(),
this.timeFormat,
this.dateFormat,
Expand Down Expand Up @@ -333,7 +329,7 @@ class _ChatwootChatState extends State<ChatwootChat> {
});
}

void _handleMessageTap(types.Message message) async {
void _handleMessageTap(BuildContext context, types.Message message) async {
if (message.status == types.Status.error && message is types.TextMessage) {
_handleResendMessage(message);
}
Expand All @@ -345,7 +341,9 @@ class _ChatwootChatState extends State<ChatwootChat> {
types.PreviewData previewData,
) {
final index = _messages.indexWhere((element) => element.id == message.id);
final updatedMessage = _messages[index].copyWith(previewData: previewData);
final updatedMetaData = _messages[index].metadata ?? Map();
updatedMetaData["previewData"] = previewData;
final updatedMessage = _messages[index].copyWith(metadata: updatedMetaData);

WidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
Expand Down Expand Up @@ -402,7 +400,7 @@ class _ChatwootChatState extends State<ChatwootChat> {
final horizontalPadding = widget.isPresentedInDialog ? 8.0 : 16.0;
return Scaffold(
appBar: widget.appBar,
backgroundColor: widget.theme.backgroundColor,
backgroundColor: widget.theme?.backgroundColor,
body: Column(
children: [
Flexible(
Expand All @@ -418,12 +416,11 @@ class _ChatwootChatState extends State<ChatwootChat> {
onEndReached: widget.onEndReached,
onEndReachedThreshold: widget.onEndReachedThreshold,
onMessageLongPress: widget.onMessageLongPress,
onTextChanged: widget.onTextChanged,
showUserAvatars: widget.showUserAvatars,
showUserNames: widget.showUserNames,
timeFormat: widget.timeFormat ?? DateFormat.Hm(),
dateFormat: widget.timeFormat ?? DateFormat("EEEE MMMM d"),
theme: widget.theme,
theme: widget.theme ?? ChatwootChatTheme(),
l10n: widget.l10n,
),
),
Expand Down
57 changes: 56 additions & 1 deletion lib/ui/chatwoot_chat_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import 'package:flutter_chat_ui/flutter_chat_ui.dart';
const CHATWOOT_COLOR_PRIMARY = Color(0xff1f93ff);
const CHATWOOT_BG_COLOR = Color(0xfff4f6fb);
const CHATWOOT_AVATAR_COLORS = [CHATWOOT_COLOR_PRIMARY];
const NEUTRAL_2 = Colors.grey;
const NEUTRAL_0 = Colors.black26;
const NEUTRAL_7 = Colors.black;
const NEUTRAL_7_WITH_OPACITY = Colors.black54;
const PRIMARY = CHATWOOT_COLOR_PRIMARY;

/// Default chatwoot chat theme which extends [ChatTheme]
@immutable
Expand All @@ -27,7 +32,7 @@ class ChatwootChatTheme extends ChatTheme {
fontWeight: FontWeight.w500,
height: 1.5,
),
Color errorColor = ERROR,
Color errorColor = Colors.red,
Widget? errorIcon,
Color inputBackgroundColor = Colors.white,
BorderRadius inputBorderRadius = const BorderRadius.all(
Expand Down Expand Up @@ -108,6 +113,38 @@ class ChatwootChatTheme extends ChatTheme {
fontWeight: FontWeight.w800,
height: 1.333,
),
EdgeInsets? attachmentButtonMargin,
EdgeInsets dateDividerMargin = const EdgeInsets.all(8),
Color inputSurfaceTintColor = Colors.blueAccent,
double inputElevation= 0,
EdgeInsets inputMargin = const EdgeInsets.all(8),
EdgeInsets inputPadding= const EdgeInsets.all(8),
InputDecoration inputTextDecoration= const InputDecoration(),
double messageInsetsHorizontal= 8,
double messageInsetsVertical= 8,
double messageMaxWidth= 500,
TextStyle receivedEmojiMessageTextStyle= const TextStyle(),
EdgeInsets sendButtonMargin= const EdgeInsets.all(8),
TextStyle sentEmojiMessageTextStyle= const TextStyle(),
EdgeInsets statusIconPadding= const EdgeInsets.all(8),
SystemMessageTheme systemMessageTheme= const SystemMessageTheme(
margin: const EdgeInsets.all(8),
textStyle: const TextStyle()
),
TypingIndicatorTheme typingIndicatorTheme= const TypingIndicatorTheme(
animatedCirclesColor: CHATWOOT_COLOR_PRIMARY,
animatedCircleSize: 8,
bubbleBorder: const BorderRadius.all(const Radius.circular(8)),
bubbleColor: CHATWOOT_COLOR_PRIMARY,
countAvatarColor: CHATWOOT_COLOR_PRIMARY,
countTextColor: NEUTRAL_7,
multipleUserTextStyle: const TextStyle()
),
UnreadHeaderTheme unreadHeaderTheme= const UnreadHeaderTheme(
color: CHATWOOT_COLOR_PRIMARY,
textStyle: const TextStyle()
),
Color userAvatarImageBackgroundColor= Colors.grey,
}) : super(
attachmentButtonIcon: attachmentButtonIcon,
backgroundColor: backgroundColor,
Expand Down Expand Up @@ -142,5 +179,23 @@ class ChatwootChatTheme extends ChatTheme {
userAvatarNameColors: userAvatarNameColors,
userAvatarTextStyle: userAvatarTextStyle,
userNameTextStyle: userNameTextStyle,
attachmentButtonMargin: attachmentButtonMargin,
dateDividerMargin: dateDividerMargin,
inputSurfaceTintColor: inputSurfaceTintColor,
inputElevation: inputElevation,
inputMargin: inputMargin,
inputPadding: inputPadding,
inputTextDecoration: inputTextDecoration,
messageInsetsHorizontal: messageInsetsHorizontal,
messageInsetsVertical: messageInsetsVertical,
messageMaxWidth: messageMaxWidth,
receivedEmojiMessageTextStyle: receivedEmojiMessageTextStyle,
sendButtonMargin: sendButtonMargin,
sentEmojiMessageTextStyle: sentEmojiMessageTextStyle,
statusIconPadding: statusIconPadding,
systemMessageTheme: systemMessageTheme,
typingIndicatorTheme: typingIndicatorTheme,
unreadHeaderTheme: unreadHeaderTheme,
userAvatarImageBackgroundColor: userAvatarImageBackgroundColor,
);
}
27 changes: 24 additions & 3 deletions lib/ui/chatwoot_l10n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ class ChatwootL10n extends ChatL10n {
/// Message when agent resolves conversation
final String conversationResolvedMessage;

/// Message when agent resolves conversation
final String and;

/// Message when agent resolves conversation
final String isTyping;

/// Message when agent resolves conversation
final String others;

/// Message when agent resolves conversation
final String unreadMessagesLabel;

/// Creates a new chatwoot l10n
const ChatwootL10n(
{this.attachmentButtonAccessibilityLabel = "",
Expand All @@ -39,13 +51,22 @@ class ChatwootL10n extends ChatL10n {
this.typingText = "typing...",
this.inputPlaceholder = "Type your message",
this.sendButtonAccessibilityLabel = "Send Message",
this.conversationResolvedMessage =
"Your ticket has been marked as resolved"})
this.conversationResolvedMessage = "Your ticket has been marked as resolved",
this.and = "and",
this.isTyping = "is typing...",
this.others = "others",
this.unreadMessagesLabel = "Your ticket has been marked as resolved"
})
: super(
attachmentButtonAccessibilityLabel:
attachmentButtonAccessibilityLabel,
emptyChatPlaceholder: emptyChatPlaceholder,
fileButtonAccessibilityLabel: fileButtonAccessibilityLabel,
inputPlaceholder: inputPlaceholder,
sendButtonAccessibilityLabel: sendButtonAccessibilityLabel);
sendButtonAccessibilityLabel: sendButtonAccessibilityLabel,
and: and,
isTyping: isTyping,
others: others,
unreadMessagesLabel: unreadMessagesLabel
);
}
17 changes: 10 additions & 7 deletions test/chatwoot_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ void main() {
final testBaseUrl = "https://testbaseurl.com";
late ProviderContainer mockProviderContainer;
final mockLocalStorage = MockLocalStorage();
final mockLocalStorageProvider = Provider.family((ref,params)=>mockLocalStorage);
final mockRepository = MockChatwootRepository();
final mockRepositoryProvider = Provider.family((ref,params)=>mockRepository);

final testUser = ChatwootUser(
identifier: "identifier",
Expand All @@ -38,13 +40,14 @@ void main() {
setUp(() async {
when(mockRepository.initialize(testUser))
.thenAnswer((realInvocation) => Future.microtask(() {}));
mockProviderContainer = ProviderContainer();
mockProviderContainer.updateOverrides([
localStorageProvider
.overrideWithProvider((ref, param) => mockLocalStorage),
chatwootRepositoryProvider
.overrideWithProvider((ref, param) => mockRepository)
]);
mockProviderContainer = ProviderContainer(
overrides:[
localStorageProvider
.overrideWithProvider(mockLocalStorageProvider),
chatwootRepositoryProvider
.overrideWithProvider(mockRepositoryProvider)
]
);
ChatwootClient.providerContainerMap.update(
testClientInstanceKey, (_) => mockProviderContainer,
ifAbsent: () => mockProviderContainer);
Expand Down
Loading

0 comments on commit b3fe248

Please sign in to comment.