diff --git a/README.md b/README.md index 17edb1b..798f722 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,9 @@ This reference application showcases the integration of [**CometChat's Flutter UI Kit**](https://www.cometchat.com/docs/v4/flutter-uikit/overview) within an Flutter framework. It provides developers with examples of implementing real-time messaging and voice and video calling features in their Flutter-based applications. +## 🚀 Try the New v5 UI Kit! +Discover the all-new [v5 UI Kit](https://github.com/cometchat/cometchat-uikit-flutter/tree/v5), featuring a completely revamped design for enhanced usability and visual appeal. With restructured components, advanced styling options, and a streamlined integration process, v5 offers a seamless, customizable experience tailored to your needs. Try it now and elevate your development workflow! + ## Prerequisites - XCode for iOS and Android Studio for Android @@ -18,12 +21,12 @@ This reference application showcases the integration of [**CometChat's Flutter U ## Installation 1. Clone the repository: ``` - git clone https://github.com/cometchat/cometchat-sample-app-flutter.git + git clone https://github.com/cometchat/cometchat-uikit-flutter.git ``` 2. Navigate to the project directory: ```sh - cd cometchat-sample-app-flutter + cd cometchat-uikit-flutter ``` 3. Install flutter dependencies @@ -32,16 +35,23 @@ This reference application showcases the integration of [**CometChat's Flutter U ``` 4. Enter your CometChat _`App ID`_, _`Region`_, and _`Auth Key`_ in the [lib/app_constants.dart](lib/app_constants.dart) file: - https://github.com/cometchat/cometchat-sample-app-flutter/blob/b67064409ec5c875aca74fd2eff5e80968c485c7/lib/app_constants.dart#L1-L5 + https://github.com/cometchat/cometchat-uikit-flutter/blob/68a5a3257ad7cfe3ac06a1c9b7de8f94f8ae4227/lib/app_constants.dart#L1-L5 + +5. If your app is created before August 12th, 2024 then change the sample data URL to `https://assets.cometchat.io/sampleapp/v1/sampledata.json` in the [lib/services/api_services.dart](https://github.com/cometchat/cometchat-uikit-flutter/blob/v4/lib/services/api_services.dart) file: https://github.com/cometchat/cometchat-uikit-flutter/blob/68a5a3257ad7cfe3ac06a1c9b7de8f94f8ae4227/lib/services/api_services.dart#L13-L15 -5. For iOS, install dependencies after navigating to ios : +6. For iOS, install dependencies after navigating to ios : ```sh cd ios pod install ``` -6. Open a Simulator or connect a physical device. + If you are facing any issue with pod install, you can try running the following command: + ```sh + pod update + ``` + +7. Open a Simulator or connect a physical device. -7. Run the app on a device or emulator from the repo root. +8. Run the app on a device or emulator from the repo root. ```sh flutter run ``` diff --git a/android/app/build.gradle b/android/app/build.gradle index 608fff8..a9bf7e5 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -1,3 +1,9 @@ +plugins { + id "com.android.application" + id "kotlin-android" + id "dev.flutter.flutter-gradle-plugin" +} + def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -6,10 +12,7 @@ if (localPropertiesFile.exists()) { } } -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} + def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { @@ -21,20 +24,18 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { + namespace "com.cometchat.cometchat_flutter_sample_app" compileSdkVersion 34 compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '11' } sourceSets { @@ -70,6 +71,4 @@ flutter { source '../..' } -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" -} +dependencies {} diff --git a/android/build.gradle b/android/build.gradle index f7eb7f6..c709783 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,20 +1,7 @@ -buildscript { - ext.kotlin_version = '1.7.10' - repositories { - google() - mavenCentral() - } - - dependencies { - classpath 'com.android.tools.build:gradle:7.3.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects { repositories { google() - mavenCentral() + jcenter() } } @@ -28,4 +15,4 @@ subprojects { tasks.register("clean", Delete) { delete rootProject.buildDir -} +} \ No newline at end of file diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 6b66533..7aeeb11 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip diff --git a/android/settings.gradle b/android/settings.gradle index 44e62bc..e2c71cf 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,11 +1,25 @@ -include ':app' +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + file("local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + }() -def localPropertiesFile = new File(rootProject.projectDir, "local.properties") -def properties = new Properties() + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") -assert localPropertiesFile.exists() -localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} -def flutterSdkPath = properties.getProperty("flutter.sdk") -assert flutterSdkPath != null, "flutter.sdk not set in local.properties" -apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" +plugins { + id "dev.flutter.flutter-plugin-loader" version "1.0.0" + id "com.android.application" version "8.5.0" apply false + id "org.jetbrains.kotlin.android" version "1.9.0" apply false +} + +include ":app" \ No newline at end of file diff --git a/assets/sample_app/sample_data.json b/assets/sample_app/sample_data.json new file mode 100644 index 0000000..df0c8ea --- /dev/null +++ b/assets/sample_app/sample_data.json @@ -0,0 +1,29 @@ +{ + "users":[ + { + "uid": "superhero1", + "name": "Iron Man", + "avatar": "assets/ironman_avatar.png" + }, + { + "uid": "superhero2", + "name": "Captain America", + "avatar": "assets/captainamerica_avatar.png" + }, + { + "uid": "superhero3", + "name": "Spiderman", + "avatar": "assets/spiderman_avatar.png" + }, + { + "uid": "superhero4", + "name": "Wolverine", + "avatar": "assets/wolverine_avatar.png" + }, + { + "uid": "superhero5", + "name": "Cyclops", + "avatar": "assets/cyclops_avatar.png" + } + ] +} \ No newline at end of file diff --git a/assets/wolverine_avatar.png b/assets/wolverine_avatar.png new file mode 100644 index 0000000..4391364 Binary files /dev/null and b/assets/wolverine_avatar.png differ diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 1589af1..b370a29 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -2,18 +2,18 @@ PODS: - cometchat_calls_sdk (4.0.9): - CometChatCallsSDK (= 4.0.6) - Flutter - - cometchat_calls_uikit (4.3.0): + - cometchat_calls_uikit (4.3.2): - Flutter - - cometchat_chat_uikit (4.5.0): + - cometchat_chat_uikit (4.5.2): - Flutter - - cometchat_sdk (4.0.11): - - CometChatSDK (= 4.0.46) + - cometchat_sdk (4.0.12): + - CometChatSDK (= 4.0.48) - Flutter - - cometchat_uikit_shared (4.3.0): + - cometchat_uikit_shared (4.4.2): - Flutter - CometChatCallsSDK (4.0.6): - CometChatWebRTC (= 1.106.1) - - CometChatSDK (4.0.46) + - CometChatSDK (4.0.48) - CometChatWebRTC (1.106.1) - Flutter (1.0.0) - image_picker_ios (0.0.1): @@ -83,12 +83,12 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: cometchat_calls_sdk: f1710462c3adc9a9e866adf8774312905a3d098c - cometchat_calls_uikit: 42579739b2c878ee012e11bf8b3719ea7dd86c88 - cometchat_chat_uikit: 7ee1be90a8ae91a3d2b4d87b381fd5abb10e5084 - cometchat_sdk: e7ff1e2ea4dea67f68e6b91b99d559cec7ff75d3 - cometchat_uikit_shared: 6d85a7fd9fad059b9e4effa5f89b9f203a51cf3b + cometchat_calls_uikit: d0efee5e665dadf82227fd2f304e99d5ef045ba9 + cometchat_chat_uikit: e98366fd4c167febe135a1cd135d9ac9ed6df044 + cometchat_sdk: 5b8784676c1b29bd6ee338a07749aebd0cccde3a + cometchat_uikit_shared: f647d7f4781079f2f6047e34e91b69b6d7ff105a CometChatCallsSDK: 121b36c761d5f244cc9608c44a15a2a8c02ee877 - CometChatSDK: 4d564fc763fabffde62749c85847a2304a76f38e + CometChatSDK: 5c37c8ee0700dbcb97733d439dc7047b3aafbd2b CometChatWebRTC: c08f446967168f6de442b48b824623411651dbb5 Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 image_picker_ios: 99dfe1854b4fa34d0364e74a78448a0151025425 diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 37c1935..20317fc 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -9,11 +9,11 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; - 67C4EE8A59DD25FF272BCA4A /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0F53ABC20EE61E0BC4A0A689 /* Pods_Runner.framework */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; + C50891A5A58042F4F000EA47 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 414A66920CF7157265156AA4 /* Pods_Runner.framework */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -30,14 +30,14 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 0F53ABC20EE61E0BC4A0A689 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 414A66920CF7157265156AA4 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 4A4AA76B53C27770107CCA69 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; - 7D95B335151EB700B64F9332 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -45,8 +45,8 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - CFF913DA5ADB240E11B4AABC /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; - D9B66738B98D5A05E1A645BD /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; + DFD030AC2B095ECF86763099 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; + E8B59EFA115A323E77CB5796 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -54,7 +54,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 67C4EE8A59DD25FF272BCA4A /* Pods_Runner.framework in Frameworks */, + C50891A5A58042F4F000EA47 /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -79,7 +79,7 @@ 97C146F01CF9000F007C117D /* Runner */, 97C146EF1CF9000F007C117D /* Products */, B0C315754F7FD1A7D6B18CA7 /* Pods */, - B687D96CDD0E0B77D11EC3D2 /* Frameworks */, + BA3DECB41BC583BD9A1C04D1 /* Frameworks */, ); sourceTree = ""; }; @@ -109,17 +109,17 @@ B0C315754F7FD1A7D6B18CA7 /* Pods */ = { isa = PBXGroup; children = ( - 7D95B335151EB700B64F9332 /* Pods-Runner.debug.xcconfig */, - D9B66738B98D5A05E1A645BD /* Pods-Runner.release.xcconfig */, - CFF913DA5ADB240E11B4AABC /* Pods-Runner.profile.xcconfig */, + 4A4AA76B53C27770107CCA69 /* Pods-Runner.debug.xcconfig */, + E8B59EFA115A323E77CB5796 /* Pods-Runner.release.xcconfig */, + DFD030AC2B095ECF86763099 /* Pods-Runner.profile.xcconfig */, ); path = Pods; sourceTree = ""; }; - B687D96CDD0E0B77D11EC3D2 /* Frameworks */ = { + BA3DECB41BC583BD9A1C04D1 /* Frameworks */ = { isa = PBXGroup; children = ( - 0F53ABC20EE61E0BC4A0A689 /* Pods_Runner.framework */, + 414A66920CF7157265156AA4 /* Pods_Runner.framework */, ); name = Frameworks; sourceTree = ""; @@ -131,15 +131,15 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( - D3C9588069D7CD3EA04C2765 /* [CP] Check Pods Manifest.lock */, + B497C1A6DCDBF32AE9B16B6F /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, - 1383DC7B26A34FA4578AFF3A /* [CP] Embed Pods Frameworks */, - AB1BE6B9B6D99D9537E56FEF /* [CP] Copy Pods Resources */, + 7431373AEB8DF932543C7CFB /* [CP] Embed Pods Frameworks */, + B0E95EBFB05EB65B5BEC9536 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -198,38 +198,38 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 1383DC7B26A34FA4578AFF3A /* [CP] Embed Pods Frameworks */ = { + 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); - inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", + inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); - name = "[CP] Embed Pods Frameworks"; - outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", + name = "Thin Binary"; + outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; - showEnvVarsInLog = 0; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; }; - 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { + 7431373AEB8DF932543C7CFB /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; - alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); - inputPaths = ( - "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); - name = "Thin Binary"; - outputPaths = ( + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; + showEnvVarsInLog = 0; }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; @@ -246,7 +246,7 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; }; - AB1BE6B9B6D99D9537E56FEF /* [CP] Copy Pods Resources */ = { + B0E95EBFB05EB65B5BEC9536 /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -263,7 +263,7 @@ shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n"; showEnvVarsInLog = 0; }; - D3C9588069D7CD3EA04C2765 /* [CP] Check Pods Manifest.lock */ = { + B497C1A6DCDBF32AE9B16B6F /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( diff --git a/lib/login.dart b/lib/login.dart index 97a7859..f0c77d3 100644 --- a/lib/login.dart +++ b/lib/login.dart @@ -1,11 +1,11 @@ -import 'package:cometchat_calls_uikit/cometchat_calls_uikit.dart'; -import 'package:cometchat_flutter_sample_app/login_with_uid.dart'; +import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart'; +import 'package:cometchat_flutter_sample_app/dashboard.dart'; +import 'package:cometchat_flutter_sample_app/models/material_button_user_model.dart'; +import 'package:cometchat_flutter_sample_app/services/api_services.dart'; import 'package:cometchat_flutter_sample_app/sign_up.dart'; import 'package:cometchat_flutter_sample_app/utils/alert.dart'; import 'package:flutter/material.dart'; -import 'package:cometchat_chat_uikit/cometchat_chat_uikit.dart'; - -import 'dashboard.dart'; +import 'login_with_uid.dart'; class Login extends StatefulWidget { const Login({Key? key}) : super(key: key); @@ -15,46 +15,56 @@ class Login extends StatefulWidget { } class _LoginState extends State { - List userModelList = [ - MaterialButtonUserModel( - "superhero1", "SUPERHERO1", "assets/ironman_avatar.png"), - MaterialButtonUserModel( - "superhero2", "SUPERHERO2", "assets/captainamerica_avatar.png"), - MaterialButtonUserModel( - "superhero3", "SUPERHERO3", "assets/spiderman_avatar.png"), - MaterialButtonUserModel( - "superhero4", "SUPERHERO4", "assets/cyclops_avatar.png"), - ]; - - @override - void initState() { - super.initState(); - - //CometChat SDk should be initialized at the start of application. No need to initialize it again - // AppSettings appSettings = (AppSettingsBuilder() - // ..subscriptionType = CometChatSubscriptionType.allUsers - // ..region = CometChatConstants.region - // ..autoEstablishSocketConnection = true) - // .build(); - // - // CometChat.init(CometChatConstants.appId, appSettings, - // onSuccess: (String successMessage) { - // debugPrint("Initialization completed successfully $successMessage"); - // }, onError: (CometChatException excep) { - // debugPrint("Initialization failed with exception: ${excep.message}"); - // }); - - //initialization end + Widget userSelectionButton( + MaterialButtonUserModel model, + BuildContext context, + ) { + return MaterialButton( + color: Colors.black, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)), + onPressed: () { + loginUser(model.userId, context); + }, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + CircleAvatar( + backgroundColor: Colors.white, + child: model.imageURL.startsWith('http') + ? Image.network( + model.imageURL, + height: 30, + width: 30, + ) + : Image.asset( + model.imageURL, + height: 30, + width: 30, + ), + ), + const SizedBox(width: 10.0), + Expanded( + child: Text( + model.username, + style: const TextStyle(color: Colors.white, fontSize: 14.0), + ), + ) + ], + ), + ), + ); } //Login User function must pass userid and authkey should be used only while developing - loginUser(String userId, BuildContext context) async { + loginUser(String userId, context) async { Alert.showLoadingIndicatorDialog(context); - User? _user = await CometChat.getLoggedInUser(); + User? user = await CometChat.getLoggedInUser(); try { - if (_user != null) { - if (_user.uid == userId) { + if (user != null) { + if (user.uid == userId) { Navigator.of(context).pop(); Navigator.push(context, @@ -72,127 +82,96 @@ class _LoginState extends State { await CometChatUIKit.login(userId, onSuccess: (User loggedInUser) { debugPrint("Login Successful from UI : $loggedInUser"); Navigator.of(context).pop(); - _user = loggedInUser; + user = loggedInUser; Navigator.push( context, MaterialPageRoute(builder: (context) => const Dashboard())); }, onError: (CometChatException e) { Navigator.of(context).pop(); debugPrint("Login failed with exception: ${e.message}"); }); - - // await CometChat.login(userId, CometChatConstants.authKey, - // onSuccess: (User loggedInUser) { - // debugPrint("Login Successful : $loggedInUser"); - // Navigator.of(context).pop(); - // _user = loggedInUser; - // Navigator.push( - // context, MaterialPageRoute(builder: (context) => const Dashboard())); - // }, onError: (CometChatException e) { - // Navigator.of(context).pop(); - // debugPrint("Login failed with exception: ${e.message}"); - // }); - } - - Widget userSelectionButton( - MaterialButtonUserModel model, BuildContext context) { - return MaterialButton( - color: Colors.black, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)), - onPressed: () { - loginUser(model.userId, context); - }, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - CircleAvatar( - backgroundColor: Colors.white, - child: Image.asset( - model.imageURL, - height: 30, - width: 30, - ), - ), - Text( - model.userId, - style: const TextStyle(color: Colors.white, fontSize: 14.0), - ) - ], - ), - ); } @override Widget build(BuildContext context) { return Scaffold( body: SafeArea( - child: SingleChildScrollView( - child: Padding( + child: SingleChildScrollView( padding: const EdgeInsets.all(10.0), - child: (Column( + child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Image.asset("assets/cometchat_logo.png", height: 100, width: 100), + Image.asset( + "assets/cometchat_logo.png", + height: 100, + width: 100, + ), const Text( "CometChat", style: TextStyle( - color: Colors.black54, - fontSize: 30, - fontWeight: FontWeight.bold), - ), - const SizedBox( - height: 20.0, - ), - const Wrap( - children: [ - Text( - "Login with one of our sample user", - style: TextStyle(color: Colors.black38), - ) - ], + color: Colors.black54, + fontSize: 30, + fontWeight: FontWeight.bold, + ), ), - const SizedBox( - height: 20.0, + const SizedBox(height: 20.0), + const Text( + "Login with one of our sample users", + style: TextStyle(color: Colors.black38), ), - - //All available user Ids in grid - GridView.count( - shrinkWrap: true, - crossAxisCount: 2, - crossAxisSpacing: 10.0, - mainAxisSpacing: 10.0, - childAspectRatio: 3.0, - children: List.generate( - userModelList.length, - (index) => - userSelectionButton(userModelList[index], context)), + const SizedBox(height: 20.0), + // Use FutureBuilder to handle async operation and show loader + FutureBuilder>( + future: ApiServices.fetchUsers(), + builder: (BuildContext context, + AsyncSnapshot> snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + // Show loader while fetching data + return Center( + child: Image.asset( + AssetConstants.spinner, + package: UIConstants.packageName, + ), + ); + } else if (snapshot.hasError) { + // Handle error + return Center(child: Text('Error: ${snapshot.error}')); + } else { + // Show user selection buttons + return GridView.count( + shrinkWrap: true, + crossAxisCount: 2, + crossAxisSpacing: 10.0, + mainAxisSpacing: 10.0, + childAspectRatio: 3.0, + children: (snapshot.data ?? []).take(4).map((user) { + return userSelectionButton(user, context); + }).toList(), + ); + } + }, ), const SizedBox(height: 20), - - const Wrap( - children: [ - Text( - "or else continue login with", - style: TextStyle(color: Colors.black38), - ) - ], - ), - - const SizedBox( - height: 5, + const Text( + "or continue login with", + style: TextStyle(color: Colors.black38), ), + const SizedBox(height: 5), Center( child: MaterialButton( color: Colors.blue, height: 45, minWidth: 200, shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10.0)), + borderRadius: BorderRadius.circular(10.0), + ), onPressed: () { Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const LoginWithUID())); + context, + MaterialPageRoute( + builder: (context) => const LoginWithUID(), + ), + ); }, child: const Text( "Login using UID", @@ -200,41 +179,35 @@ class _LoginState extends State { ), ), ), - const SizedBox(height: 100), - Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text("New to cometchat? "), + const Text("New to CometChat? "), GestureDetector( - onTap: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => const SignUp())); - }, - child: const Text("CREATE NEW", - style: TextStyle( - //decoration: TextDecoration.underline, - fontWeight: FontWeight.bold, - fontSize: 15, - color: Colors.blue))) + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const SignUp(), + ), + ); + }, + child: const Text( + "CREATE NEW", + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 15, + color: Colors.blue, + ), + ), + ), ], ), - ], - )), + ), ), - )), + ), ); } } - -class MaterialButtonUserModel { - String username; - String userId; - String imageURL; - - MaterialButtonUserModel(this.username, this.userId, this.imageURL); -} diff --git a/lib/models/material_button_user_model.dart b/lib/models/material_button_user_model.dart new file mode 100644 index 0000000..bc6122d --- /dev/null +++ b/lib/models/material_button_user_model.dart @@ -0,0 +1,11 @@ +class MaterialButtonUserModel { + final String username; + final String userId; + final String imageURL; + + MaterialButtonUserModel( + this.username, + this.userId, + this.imageURL, + ); +} diff --git a/lib/services/api_services.dart b/lib/services/api_services.dart new file mode 100644 index 0000000..509c068 --- /dev/null +++ b/lib/services/api_services.dart @@ -0,0 +1,58 @@ +import 'package:cometchat_flutter_sample_app/models/material_button_user_model.dart'; +import 'package:http/http.dart' as http; +import 'dart:convert'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +class ApiServices { + + // Fetch users from the API + + static Future> fetchUsers() async { + try { + final response = await http.get( + Uri.parse('https://assets.cometchat.io/sampleapp/sampledata.json'), + ); + + if (response.statusCode == 200) { + final List data = json.decode(response.body)['users'] ?? []; + final List userList = data + .map((user) => MaterialButtonUserModel( + user['name'] ?? "", + user['uid'] ?? "", + user['avatar'] ?? "", + )) + .toList(); + return userList; + } else { + throw Exception('Failed to load users'); + } + } catch (e) { + debugPrint('Exception while fetching users: $e'); + // Handle exception here, load users from local asset + return getDefaultUsers(); + } + } + + // Load default users from local asset + static Future> getDefaultUsers() async { + Map jsonData = + await loadJsonFromAssets('assets/sample_app/sample_data.json'); + final List data = jsonData['users'] ?? []; + final List userList = data + .map((user) => MaterialButtonUserModel( + user['name'] ?? "", + user['uid'] ?? "", + user['avatar'] ?? "", + )) + .toList(); + return userList; + } + + // Load JSON from local asset + static Future> loadJsonFromAssets( + String filePath) async { + String jsonString = await rootBundle.loadString(filePath); + return jsonDecode(jsonString); + } +} diff --git a/lib/utils/demo_meta_info_constants.dart b/lib/utils/demo_meta_info_constants.dart index 8cf1d24..ea5f159 100644 --- a/lib/utils/demo_meta_info_constants.dart +++ b/lib/utils/demo_meta_info_constants.dart @@ -3,7 +3,7 @@ import 'dart:io'; class DemoMetaInfoConstants { static String name = "cometchat_flutter_sample_app"; static String type = "sample-app"; - static String version = "1.0.11"; + static String version = "1.0.13"; static String bundle = Platform.isAndroid ? "com.cometchat.cometchat_flutter_sample_app" : "com.cometchat.cometchatFlutterSampleApp"; static String platform = "Flutter"; } \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index f13b273..58744b2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.11 +version: 1.0.14 environment: sdk: ">=2.16.2 <3.0.0" @@ -34,8 +34,9 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 - cometchat_chat_uikit: ^4.5.0 - cometchat_calls_uikit: ^4.3.0 + cometchat_chat_uikit: ^4.5.2 + cometchat_calls_uikit: ^4.3.2 + http: ^1.1.0 flutter_localizations: sdk: flutter toast: ^0.3.0 @@ -75,6 +76,7 @@ flutter: assets: - assets/ - assets/icons/ + - assets/sample_app/ # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware.