Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
6 changes: 0 additions & 6 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ PODS:
- audio_session (0.0.1):
- Flutter
- Flutter (1.0.0)
- flutter_keyboard_visibility (0.0.1):
- Flutter
- image_picker_ios (0.0.1):
- Flutter
- just_audio (0.0.1):
Expand All @@ -18,7 +16,6 @@ PODS:
DEPENDENCIES:
- audio_session (from `.symlinks/plugins/audio_session/ios`)
- Flutter (from `Flutter`)
- flutter_keyboard_visibility (from `.symlinks/plugins/flutter_keyboard_visibility/ios`)
- image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`)
- just_audio (from `.symlinks/plugins/just_audio/ios`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
Expand All @@ -30,8 +27,6 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/audio_session/ios"
Flutter:
:path: Flutter
flutter_keyboard_visibility:
:path: ".symlinks/plugins/flutter_keyboard_visibility/ios"
image_picker_ios:
:path: ".symlinks/plugins/image_picker_ios/ios"
just_audio:
Expand All @@ -46,7 +41,6 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
audio_session: 4f3e461722055d21515cf3261b64c973c062f345
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069
image_picker_ios: b786a5dcf033a8336a657191401bfdf12017dabb
just_audio: baa7252489dbcf47a4c7cc9ca663e9661c99aafa
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
Expand Down
91 changes: 49 additions & 42 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,41 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
camera:
dependency: transitive
description:
name: camera
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.1"
camera_android:
dependency: transitive
description:
name: camera_android
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.2"
camera_avfoundation:
dependency: transitive
description:
name: camera_avfoundation
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.10"
camera_platform_interface:
dependency: transitive
description:
name: camera_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.2"
camera_web:
dependency: transitive
description:
name: camera_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.1"
characters:
dependency: transitive
description:
Expand Down Expand Up @@ -97,48 +132,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_keyboard_visibility:
dependency: transitive
description:
name: flutter_keyboard_visibility
url: "https://pub.dartlang.org"
source: hosted
version: "5.4.0"
flutter_keyboard_visibility_linux:
dependency: transitive
description:
name: flutter_keyboard_visibility_linux
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
flutter_keyboard_visibility_macos:
dependency: transitive
description:
name: flutter_keyboard_visibility_macos
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
flutter_keyboard_visibility_platform_interface:
dependency: transitive
description:
name: flutter_keyboard_visibility_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
flutter_keyboard_visibility_web:
dependency: transitive
description:
name: flutter_keyboard_visibility_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
flutter_keyboard_visibility_windows:
dependency: transitive
description:
name: flutter_keyboard_visibility_windows
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
Expand Down Expand Up @@ -408,6 +401,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.4"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.1"
record:
dependency: transitive
description:
Expand Down Expand Up @@ -490,6 +490,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
stream_transform:
dependency: transitive
description:
name: stream_transform
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
string_scanner:
dependency: transitive
description:
Expand Down
178 changes: 87 additions & 91 deletions lib/chat_package.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
library chat_package;

import 'dart:developer';

import 'package:chat_package/components/message/message_widget.dart';
import 'package:chat_package/components/new_chat_input_field/new_chat_input_field.dart';
import 'package:chat_package/models/chat_message.dart';
import 'package:chat_package/models/media/chat_media.dart';
import 'package:chat_package/models/media/media_type.dart';
import 'package:chat_package/utils/constants.dart';
import 'package:chat_package/components/chat_input_field/chat_input_field.dart';
import 'package:flutter/material.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
// import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
import 'package:image_picker/image_picker.dart';

class ChatScreen extends StatefulWidget {
Expand Down Expand Up @@ -99,6 +97,27 @@ class ChatScreen extends StatefulWidget {
/// this is an optional parameter to override the default attachment bottom sheet
final Function(BuildContext context)? attachmentClick;

//TODO check for dublickates
//send button
final Color? sendButtonColor;
final bool? disableRecording;
final IconData? sendButtonTextIcon;
final IconData? sendButtonRecordIcon;
final Color? sendButtonIconColor;
//text field
//text field
final String? textFieldHintText;
final TextStyle? textFieldHintTextStyle;
final bool? disableCamera;
final bool? disableAttachment;

final IconData? cameraIcon;
final IconData? attachmentIcon;

final String? capturedMediaHintText;

final Function(String path, String caption)? handleMediaSubmitted;

ChatScreen({
Key? key,
this.senderColor,
Expand Down Expand Up @@ -127,6 +146,23 @@ class ChatScreen extends StatefulWidget {
this.messageContainerTextStyle,
this.sendDateTextStyle,
this.attachmentClick,

///
this.sendButtonColor,
this.disableRecording,
this.sendButtonRecordIcon,
this.sendButtonTextIcon,
this.sendButtonIconColor,

///text field
this.textFieldHintTextStyle,
this.textFieldHintText,
this.disableCamera,
this.disableAttachment,
this.cameraIcon,
this.attachmentIcon,
this.capturedMediaHintText,
this.handleMediaSubmitted,
}) : super(key: key);

@override
Expand All @@ -138,105 +174,65 @@ class _ChatScreenState extends State<ChatScreen> {

@override
Widget build(BuildContext context) {
return Column(
return Stack(
children: [
Expanded(
child: ListView.builder(
padding: const EdgeInsets.symmetric(horizontal: kDefaultPadding),
controller: widget.scrollController ?? _controller,
itemCount: widget.messages.length,
itemBuilder: (context, index) => MessageWidget(
message: widget.messages[index],
activeAudioSliderColor:
widget.activeAudioSliderColor ?? kSecondaryColor,
inActiveAudioSliderColor:
widget.inActiveAudioSliderColor ?? kLightColor,
senderColor: widget.senderColor ?? kPrimaryColor,
messageContainerTextStyle: widget.messageContainerTextStyle,
sendDateTextStyle: widget.sendDateTextStyle,
),
ListView.builder(
padding: const EdgeInsets.only(
left: kDefaultPadding, right: kDefaultPadding, bottom: 100),
controller: widget.scrollController ?? _controller,
itemCount: widget.messages.length,
itemBuilder: (context, index) => MessageWidget(
message: widget.messages[index],
activeAudioSliderColor:
widget.activeAudioSliderColor ?? kSecondaryColor,
inActiveAudioSliderColor:
widget.inActiveAudioSliderColor ?? kLightColor,
senderColor: widget.senderColor ?? kPrimaryColor,
messageContainerTextStyle: widget.messageContainerTextStyle,
sendDateTextStyle: widget.sendDateTextStyle,
),
),
KeyboardVisibilityProvider(
child: ChatInputField(
imageAttachmentCancelText: widget.imageAttachmentCancelText,
imageAttachmentFromCameraText: widget.imageAttachmentFromCameraText,
imageAttachmentFromGalleryText:
widget.imageAttachmentFromGalleryText,
chatInputFieldColor: widget.chatInputFieldColor,
recordingNoteHintText: widget.recordingNoteHintText,
sendMessageHintText: widget.sendMessageHintText,
disableInput: widget.disableInput,
chatInputFieldDecoration: widget.chatInputFieldDecoration,
chatInputFieldPadding: widget.chatInputFieldPadding,
imageAttachmentTextStyle: widget.imageAttachmentTextStyle,
imageAttachmentFromGalleryIcon:
widget.imageAttachmentFromGalleryIcon,
imageAttachmentFromCameraIcon: widget.imageAttachmentFromCameraIcon,
imageAttachmentCancelIcon: widget.imageAttachmentCancelIcon,
attachmentClick: widget.attachmentClick,
handleRecord: widget.handleRecord ??
(source, canceled) {
if (!canceled && source != null) {
Positioned(
bottom: 20,
left: 5,
right: 5,
child: NewChatInputField(
sendButtonColor: widget.sendButtonColor,
disableRecording: widget.disableRecording,
sendButtonRecordIcon: widget.sendButtonRecordIcon,
sendButtonTextIcon: widget.sendButtonTextIcon,
sendButtonIconColor: widget.sendButtonIconColor,
textFieldHintText: widget.textFieldHintText,
textFieldHintTextStyle: widget.textFieldHintTextStyle,
disableCamera: widget.disableCamera,
disableAttachment: widget.disableAttachment,
cameraIcon: widget.cameraIcon,
attachmentIcon: widget.attachmentIcon,
capturedMediaHintText: widget.capturedMediaHintText,
handleMediaSubmitted: widget.handleMediaSubmitted ??
(path, caption) {
setState(() {
widget.messages.add(
ChatMessage(
isSender: true,
text: caption,
chatMedia: ChatMedia(
url: source,
mediaType: MediaType.audioMediaType(),
url: path,
mediaType: MediaType.imageMediaType(),
),
),
);
widget.scrollController?.jumpTo(
widget.scrollController!.position.maxScrollExtent +
90);
});
}
},
handleImageSelect: widget.handleImageSelect ??
(file) async {
// final bytes = await file.readAsBytes();
// final image = await decodeImageFromList(bytes);
// final name = file.path.split('/').last;
setState(() {
widget.messages.add(
ChatMessage(
isSender: true,
chatMedia: ChatMedia(
url: file.path,
mediaType: MediaType.imageMediaType(),
),
),
);
});

setState(() {
widget.scrollController?.jumpTo(
widget.scrollController!.position.maxScrollExtent +
300);
});
},
onSlideToCancelRecord: widget.onSlideToCancelRecord ??
() {
log('slide to cancel');
},
onTextSubmit: (text) {
if (widget.onSubmit != null) {
widget.onSubmit!(text);
} else {
if (text != null) {
setState(() {
widget.messages
.add(ChatMessage(isSender: true, text: text));

widget.scrollController?.jumpTo(
widget.scrollController!.position.maxScrollExtent + 50);
});
}
}
},
),

setState(() {
(widget.scrollController ?? _controller).animateTo(
(widget.scrollController ?? _controller)
.position
.maxScrollExtent,
duration: Duration(milliseconds: 300),
curve: Curves.easeOut);
});
}),
),
],
);
Expand Down
Loading