Skip to content

Commit

Permalink
Fix : Resolved the Messaging and Calling Issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Divyakumar21202 committed Sep 27, 2024
1 parent 9e517ac commit b1e977e
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 29 deletions.
13 changes: 13 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:label="Coupon Aggregator"
android:name="${applicationName}"
Expand Down Expand Up @@ -42,5 +44,16 @@
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
</intent>
<!-- If your app checks for SMS support -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="sms" />
</intent>
<!-- If your app checks for call support -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="tel" />
</intent>
</queries>

</manifest>
45 changes: 27 additions & 18 deletions lib/Global/Functions/contact_helper_class.dart
Original file line number Diff line number Diff line change
@@ -1,44 +1,53 @@
import 'package:mess_mgmt/Global/store/app_state_store.dart';
import 'package:mess_mgmt/features/auth/error%20handling/auth_error.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:url_launcher/url_launcher.dart';

class ContactHelper {
// Function to send a WhatsApp message
static Future<void> sendWhatsAppMessage(
String phoneNumber, String message) async {
// final whatsappUrl =
// "whatsapp://send?phone=$phoneNumber&text=Your Message here";
String whatsappUrl =
"whatsapp://send?phone=${phoneNumber.trim()}&text=${Uri.encodeComponent(message)}";

// "whatsapp://send?phone=$phoneNumber&text=${Uri.encodeComponent(message)}";
if (await canLaunchUrl(Uri.parse(whatsappUrl))) {
await launchUrl(
Uri.parse(whatsappUrl),
mode: LaunchMode.externalApplication,
);
} else {
appState.authError = const AuthErrorUnknownIssue();
appState.authError = const MessageIssue();
}
}

// Function to send an SMS message
static Future<void> sendSms(String phoneNumber, String message) async {
final smsUrl = "sms:$phoneNumber?body=${Uri.encodeComponent(message)}";
if (await canLaunchUrl(Uri.parse(smsUrl))) {
await launchUrl(Uri.parse(smsUrl));
} else {
appState.authError = const AuthErrorUnknownIssue();
PermissionStatus status = await Permission.sms.request();

if (status.isGranted) {
final smsUrl = "sms:$phoneNumber?body=${Uri.encodeComponent(message)}";
if (await canLaunchUrl(Uri.parse(smsUrl))) {
await launchUrl(Uri.parse(smsUrl));
} else {
appState.authError = const MessageIssue();
}
} else if (status.isDenied) {
} else if (status.isPermanentlyDenied) {
await openAppSettings();
}
}

// Function to make a call
static Future<void> makePhoneCall(String phoneNumber) async {
final telUrl = "tel:$phoneNumber";
if (await canLaunchUrl(Uri.parse(telUrl))) {
await launchUrl(Uri.parse(telUrl));
} else {
appState.authError = const AuthErrorUnknownIssue();
PermissionStatus status = await Permission.phone.request();

if (status.isGranted) {
final telUrl = "tel:$phoneNumber";
if (await canLaunchUrl(Uri.parse(telUrl))) {
await launchUrl(Uri.parse(telUrl));
} else {
appState.authError = const CallIssue();

}
} else if (status.isDenied) {
} else if (status.isPermanentlyDenied) {
openAppSettings();
}
}
}
16 changes: 7 additions & 9 deletions lib/Global/dialogs/edit_coupon_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:mess_mgmt/Global/store/app_state_store.dart';
import 'package:mess_mgmt/features/User%20Profile/store/user_profile_store.dart';
import 'package:mobx/mobx.dart';

import '../enums/enums.dart';
import '../models/coupon_data_model.dart';
import '../widgets/loader.dart';
Expand Down Expand Up @@ -62,15 +64,14 @@ class _DialogWidgetState extends State<DialogWidget> {
return Dialog(
backgroundColor: Colors.transparent,
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Colors.white
.withOpacity(0.3),
color: Colors.white.withOpacity(0.3),
width: 1.5,
),
),
Expand All @@ -94,16 +95,14 @@ class _DialogWidgetState extends State<DialogWidget> {
labelText: "Floor",
labelStyle: TextStyle(
color: Colors.white,
),
),
),
items: Floor.values.map((Floor value) {
return DropdownMenuItem<Floor>(
value: value,
child: Text(
value.intoString(),
style: const TextStyle(
color: Colors
.white),
style: const TextStyle(color: Colors.white),
),
);
}).toList(),
Expand Down Expand Up @@ -205,8 +204,7 @@ class _DialogWidgetState extends State<DialogWidget> {
),
builder: (context) {
return autorun((_) {
final canDialogPop =
appState.canDialogPop;
final canDialogPop = appState.canDialogPop;
if (canDialogPop) {
Navigator.pop(context);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/Global/widgets/my_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ class MyListTile extends StatelessWidget {
InkWell(
onTap: () {
ContactHelper.sendSms(
coupon.createdBy!.mobileNumber,
"Hey I want to buy your coupon");
coupon.createdBy!.mobileNumber,
"Hey I want to buy your coupon",
);
},
child: const Icon(
Icons.chat,
Expand Down
20 changes: 20 additions & 0 deletions lib/features/auth/error handling/auth_error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,23 @@ class AuthErrorUnknownIssue implements AuthError {
@override
String get errorString => "Something Went wrong !";
}

class MessageIssue implements AuthError {
const MessageIssue();

@override
String get errorDescription => "Please try again .";

@override
String get errorString => "We couldn't find the Message App";
}

class CallIssue implements AuthError {
const CallIssue();

@override
String get errorDescription => "Please try again .";

@override
String get errorString => "We couldn't find the Caller App";
}
48 changes: 48 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,54 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.3.0"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
sha256: "18bf33f7fefbd812f37e72091a15575e72d5318854877e0e4035a24ac1113ecb"
url: "https://pub.dev"
source: hosted
version: "11.3.1"
permission_handler_android:
dependency: transitive
description:
name: permission_handler_android
sha256: "76e4ab092c1b240d31177bb64d2b0bea43f43d0e23541ec866151b9f7b2490fa"
url: "https://pub.dev"
source: hosted
version: "12.0.12"
permission_handler_apple:
dependency: transitive
description:
name: permission_handler_apple
sha256: e6f6d73b12438ef13e648c4ae56bd106ec60d17e90a59c4545db6781229082a0
url: "https://pub.dev"
source: hosted
version: "9.4.5"
permission_handler_html:
dependency: transitive
description:
name: permission_handler_html
sha256: af26edbbb1f2674af65a8f4b56e1a6f526156bc273d0e65dd8075fab51c78851
url: "https://pub.dev"
source: hosted
version: "0.1.3+2"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
sha256: e9c8eadee926c4532d0305dff94b85bf961f16759c3af791486613152af4b4f9
url: "https://pub.dev"
source: hosted
version: "4.2.3"
permission_handler_windows:
dependency: transitive
description:
name: permission_handler_windows
sha256: "1a790728016f79a41216d88672dbc5df30e686e811ad4e698bfc51f76ad91f1e"
url: "https://pub.dev"
source: hosted
version: "0.2.1"
petitparser:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies:
flutter_svg:
font_awesome_flutter: ^10.7.0
flutter_secure_storage: ^9.2.2
permission_handler: ^11.3.1


dev_dependencies:
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
#include "generated_plugin_registrant.h"

#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_windows
permission_handler_windows
url_launcher_windows
)

Expand Down

0 comments on commit b1e977e

Please sign in to comment.