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
45 changes: 28 additions & 17 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Audio recording -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<!-- Optional: Add this permission if you want to use bluetooth telephony device like headset/earbuds -->
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<!-- Optional: Add this permission if you want to save your recordings in public folders -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<!-- Microphone/audio settings -->
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<!-- Camera capture -->
<uses-permission android:name="android.permission.CAMERA" />

<!-- Optional: to save recordings in public storage (legacy) -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />

<!-- Gallery access -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<!-- On Android 13+ you may also need these for image/video access -->

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />


<application
android:label="xx"
android:name="${applicationName}"
Expand All @@ -17,30 +35,23 @@
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->

<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" />

<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->


<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<!-- Required to query activities that can process text, see:
https://developer.android.com/training/package-visibility and
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.

In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT"/>
Expand Down
97 changes: 36 additions & 61 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,94 +1,69 @@
import 'dart:developer';

import 'package:chat_package/chat_package.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:flutter/material.dart';

void main() {
runApp(MyApp());
}
void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'chat ui example',
title: 'Chat Ui example',
theme: ThemeData(
primarySwatch: Colors.blue,
primaryColor: const Color(0xFF075E54),
scaffoldBackgroundColor: Colors.white,
),
home: MyHomePage(),
home: const ChatPage(),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key? key}) : super(key: key);
class ChatPage extends StatefulWidget {
const ChatPage({super.key});

@override
_MyHomePageState createState() => _MyHomePageState();
State<ChatPage> createState() => _ChatPageState();
}

class _MyHomePageState extends State<MyHomePage> {
List<ChatMessage> messages = [
class _ChatPageState extends State<ChatPage> {
final textEditingController = TextEditingController();
@override
void dispose() {
textEditingController.dispose();
super.dispose();
}

final messages = [
ChatMessage(
text: 'hi omar',
isSender: true,
text: 'this is a banana',
chatMedia: ChatMedia(
url:
'https://images.pexels.com/photos/7194915/pexels-photo-7194915.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260',
mediaType: MediaType.imageMediaType(),
),
),
ChatMessage(
isSender: false,
chatMedia: ChatMedia(
url:
'https://images.pexels.com/photos/7194915/pexels-photo-7194915.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260',
mediaType: MediaType.imageMediaType(),
),
),
ChatMessage(isSender: false, text: 'wow that is cool'),
];
final scrollController = ScrollController();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
resizeToAvoidBottomInset: true,
appBar: AppBar(
title: const Text('Chat'),
backgroundColor: const Color(0xFF075E54),
),
body: ChatScreen(
scrollController: scrollController,
messages: messages,
onSlideToCancelRecord: () {
log('not sent');
scrollController: ScrollController(),
onRecordComplete: (audioMessage) {
messages.add(audioMessage);
setState(() {});
},
onTextSubmit: (textMessage) {
setState(() {
messages.add(textMessage);

scrollController
.jumpTo(scrollController.position.maxScrollExtent + 50);
});
},
handleRecord: (audioMessage, canceled) {
if (!canceled) {
setState(() {
messages.add(audioMessage!);
scrollController
.jumpTo(scrollController.position.maxScrollExtent + 90);
});
}
onImageSelected: (imageMessage) {
messages.add(imageMessage);
setState(() {});
},
handleImageSelect: (imageMessage) async {
if (imageMessage != null) {
setState(() {
messages.add(
imageMessage,
);
scrollController
.jumpTo(scrollController.position.maxScrollExtent + 300);
});
}
textEditingController: TextEditingController(),
onTextSubmit: (textMessage) {
messages.add(textMessage);
setState(() {});
},
),
);
Expand Down
16 changes: 8 additions & 8 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ packages:
source: hosted
version: "4.0.2"
image_picker:
dependency: transitive
dependency: "direct main"
description:
name: image_picker
sha256: b6951e25b795d053a6ba03af5f710069c99349de9341af95155d52665cb4607c
Expand Down Expand Up @@ -248,15 +248,15 @@ packages:
source: hosted
version: "0.2.1+1"
intl:
dependency: transitive
dependency: "direct main"
description:
name: intl
sha256: "910f85bce16fb5c6f614e117efa303e85a1731bb0081edf3604a2ae6e9a3cc91"
url: "https://pub.dev"
source: hosted
version: "0.17.0"
just_audio:
dependency: transitive
dependency: "direct main"
description:
name: just_audio
sha256: f978d5b4ccea08f267dae0232ec5405c1b05d3f3cd63f82097ea46c015d5c09e
Expand Down Expand Up @@ -360,7 +360,7 @@ packages:
source: hosted
version: "1.9.0"
path_provider:
dependency: transitive
dependency: "direct main"
description:
name: path_provider
sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd"
Expand Down Expand Up @@ -408,7 +408,7 @@ packages:
source: hosted
version: "2.3.0"
permission_handler:
dependency: transitive
dependency: "direct main"
description:
name: permission_handler
sha256: bc56bfe9d3f44c3c612d8d393bd9b174eb796d706759f9b495ac254e4294baa5
Expand Down Expand Up @@ -448,7 +448,7 @@ packages:
source: hosted
version: "0.1.3"
photo_view:
dependency: transitive
dependency: "direct main"
description:
name: photo_view
sha256: "8036802a00bae2a78fc197af8a158e3e2f7b500561ed23b4c458107685e645bb"
Expand Down Expand Up @@ -480,7 +480,7 @@ packages:
source: hosted
version: "6.1.5"
record:
dependency: transitive
dependency: "direct main"
description:
name: record
sha256: daeb3f9b3fea9797094433fe6e49a879d8e4ca4207740bc6dc7e4a58764f0817
Expand Down Expand Up @@ -581,7 +581,7 @@ packages:
source: hosted
version: "1.11.1"
stop_watch_timer:
dependency: transitive
dependency: "direct main"
description:
name: stop_watch_timer
sha256: eb690e4f6d983ba12ddfbf51a5d489fdba8b64982b9651cb538650888cec2886
Expand Down
76 changes: 10 additions & 66 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,90 +1,34 @@
name: xx
description: "A new Flutter project."
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: "none" # Remove this line if you wish to publish to pub.dev
publish_to: "none"

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.0+1

environment:
sdk: ^3.5.2

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.8
chat_package:
path: ../.
#todo delete
permission_handler: ^10.2.0
image_picker: ^0.8.6
just_audio: ^0.9.30
record: ^6.0.0
intl: ^0.17.0
photo_view: ^0.14.0
stop_watch_timer: ^2.0.0
path_provider: ^2.0.15

dev_dependencies:
flutter_test:
sdk: flutter

# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^4.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/to/resolution-aware-images

# For details regarding adding assets from package dependencies, see
# https://flutter.dev/to/asset-from-package

# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/to/font-from-package
Loading