def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8')
{ reader
->
localProperties.load(reader)
}
}
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) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
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
{
lintOptions
{
abortOnError false
}
flavorDimensions "Doctor-type"
productFlavors
{
doctor_dev
{
dimension "Doctor-type"
applicationId "com.medicall.doctor"
resValue "string", "app_name", "Doctor_Dev"
}
doctor_prod
{
dimension "Doctor-type"
applicationId "com.medicall.doctor"
resValue "string", "app_name", "Doctor_Prod"
}
patient_dev
{
dimension "Doctor-type"
applicationId "com.medicall.patient"
resValue "string", "app_name", "Patient_Dev"
}
patient_prod
{
dimension "Doctor-type"
applicationId "com.medicall.patient"
resValue "string", "app_name", "Patient_Prod"
}
}
compileSdkVersion 30
buildToolsVersion '29.0.0'
sourceSets
{
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions
{
// disable 'InvalidPackage'
// abortOnError false
// checkReleaseBuilds false
}
defaultConfig
{
//
TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "
com.medicall.app"
minSdkVersion 23
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
buildTypes
{
release
{
//
TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter
{
source '../..'
}
dependencies
{
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-messaging:23.0.0'
implementation 'com.android.support:multidex:1.0.3'
}
apply plugin: 'com.google.gms.google-services'
And here's my android build gradle
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:quickblox_sdk/chat/constants.dart';
import 'package:quickblox_sdk/quickblox_sdk.dart';
import 'package:rxdart/rxdart.dart';
import 'AppController/App.dart';
import 'AppController/flavors.dart';
import 'Repos/SharedPrefRepo.dart';
import 'Services/NotificationService.dart';
import 'SharedPrefRepoImpl.dart';
import 'Utils/Constants.dart';
import 'Utils/VideoCallHelper.dart';
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
/// Streams are created so that app can respond to notification-related events
/// since the plugin is initialised in the `main` function
final BehaviorSubject<ReceivedNotification> didReceiveLocalNotificationSubject = BehaviorSubject<ReceivedNotification>();
final BehaviorSubject<String> selectNotificationSubject = BehaviorSubject<String>();
final BehaviorSubject<String> chatConnectionListener = BehaviorSubject<String>();
dynamic fcmMessage;
bool appLaunchedFromNotification = false;
bool callScreenOn =false;
const MethodChannel platform = MethodChannel('
dexterx.dev/flutter_local_notifications');
Future<void> _messageHandler(RemoteMessage message) async {
print('background message ${message.notification.body}');
}
Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) async {
print('Message from fcm : $message');
dynamic data,notification;
if (message.containsKey('data')) {
// Handle data message
print('fcm >>>>> message:'+message.toString());
data = message['data'];
print('fcm >>>>> data:'+data.toString());
if(data.containsKey('sessionId')) {
String sessionId = data['sessionId'];
print('fcm >>>>> sessionId:' + sessionId);
String name = data['name'];
print('fcm >>>>> name:' +name);
String userId = data['userId'];
print('fcm >>>>> userId:' +userId);
String clId = data['clId'];
print('fcm >>>>> clid:' +clId);
int callTime = int.
tryParse(data['time']);
print('call time: $callTime');
int currTime = DateTime.now().millisecondsSinceEpoch;
int diff = currTime - callTime;
print('call time diff'+diff.toString());
if(currTime-callTime<=45000) {
appLaunchedFromNotification = true;
NotificationService().showCallNotification(data, name);
}else{
String title = 'Missed call from $name';
if(title!=null) {
NotificationService().showNotification(title, '');
}
}
}
}
if (message.containsKey('notification')) {
// Handle notification message
print('fcm >>>>> message:'+message.toString());
notification = message['notification'];
print('fcm >>>>> notif:'+notification.toString());
}
}
_listenForChatConnections() async{
try {
var _connectedSubscription = await QB.
chat.subscribeChatEvent(QBChatEvents.
CONNECTED,(data) {
print('chat CONNECTED status: $data');
//QB.webrtc.init();
});
await QB.
chat.subscribeChatEvent(QBChatEvents.
CONNECTION_CLOSED,(data) {
print('chat CONNECTION_CLOSED status: $data');
});
await QB.
chat.subscribeChatEvent(QBChatEvents.
RECONNECTION_SUCCESSFUL,(data) {
print('chat RECONNECTION_SUCCESSFUL status: $data');
//QB.webrtc.init();
});
} on PlatformException catch (e) {
// Some error occured, look at the exception message for more details
}
}
void main() async{
F.
appFlavor = Flavor.DOCTOR_DEV;
WidgetsFlutterBinding.
ensureInitialized();
WidgetsFlutterBinding.
ensureInitialized();
await Firebase.
initializeApp();
FirebaseMessaging.
onBackgroundMessage(_messageHandler);
_initFCM();
_initNotifications();
_initQuickblox();
_listenForChatConnections();
SystemChrome.
setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]).then((value) => runApp(App()));
}
_initQuickblox() async {
try {
SharedPrefRepo sharedPrefRepo = SharedPrefRepoImpl();
await QB.
settings.init(
Constants.
APP_ID,
Constants.
AUTH_KEY,
Constants.
AUTH_SECRET,
Constants.
ACCOUNT_KEY,
apiEndpoint: Constants.
API_ENDPOINT,
chatEndpoint: Constants.
CHAT_ENDPOINT);
print('sdk initialized,will login to QB');
String _username = await sharedPrefRepo.getString(Constants.
PHONE_NUMBER);
if(_username!=null) {
print('logging in to QB with $_username');
await VideoCallHelper.
loginToQuickblox(_username);
}else{
print('username is null');
return -1;
}
} on PlatformException catch (e) {
// Some error occured, look at the exception message for more details
print('error while initializing quickblox sdk'+e.toString());
}
}
_initFCM() async{
await Firebase.
initializeApp();
}
_initNotifications() async{
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('ic_launcher');
/// Note: permissions aren't requested here just to demonstrate that can be
/// done later
final IOSInitializationSettings initializationSettingsIOS =
IOSInitializationSettings(
requestAlertPermission: false,
requestBadgePermission: false,
requestSoundPermission: false,
onDidReceiveLocalNotification:
(int id, String title, String body, String payload) async {
didReceiveLocalNotificationSubject.add(ReceivedNotification(
id: id, title: title, body: body, payload: payload));
});
final InitializationSettings initializationSettings = InitializationSettings(
android: initializationSettingsAndroid,
iOS: initializationSettingsIOS,);
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: (String payload) async {
if (payload != null) {
debugPrint('notification payload: $payload');
}
final NotificationAppLaunchDetails details =
await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();
print("test me !-> ${details.payload}");
selectNotificationSubject.add(details.payload);
});
}
Please help me through this process