Skip to content

Commit a662186

Browse files
committed
fix warning
1 parent 8879746 commit a662186

File tree

2 files changed

+15
-103
lines changed

2 files changed

+15
-103
lines changed

lib/utils/call_icon.dart

+15-102
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ library;
2929

3030
import 'package:flutter/material.dart';
3131

32-
import 'package:permission_handler/permission_handler.dart';
3332
import 'package:universal_io/io.dart' show Platform;
3433
import 'package:ussd_phone_call_sms/ussd_phone_call_sms.dart';
3534

3635
import 'package:healthpod/utils/show_alert.dart';
3736

3837
/// A widget that displays a phone icon. On iOS, Android, and Linux the icon is interactive.
39-
/// On Linux, we bypass permission checks because permission_handler does not support Linux.
38+
/// (Permission checks have been removed for Linux since permission_handler does not work there.).
4039
4140
class CallIcon extends StatefulWidget {
4241
final String contactNumber;
42+
4343
const CallIcon({
4444
super.key,
4545
required this.contactNumber,
@@ -54,7 +54,7 @@ class _CallIconState extends State<CallIcon> {
5454

5555
@override
5656
Widget build(BuildContext context) {
57-
// Enable interactive behavior on mobile and Linux.
57+
// Enable interactive behavior on iOS, Android, and Linux.
5858

5959
if (Platform.isIOS || Platform.isAndroid || Platform.isLinux) {
6060
return GestureDetector(
@@ -68,72 +68,10 @@ class _CallIconState extends State<CallIcon> {
6868
}
6969
}
7070

71-
Future<void> _showPermissionDialog(BuildContext context) async {
72-
if (!mounted) return;
73-
final result = await showDialog<bool>(
74-
context: context,
75-
builder: (dialogContext) => AlertDialog(
76-
title: const Text("Permission Required"),
77-
content: const Text(
78-
"This app requires phone call permissions to make a call. Please enable it."),
79-
actions: <Widget>[
80-
ElevatedButton(
81-
child: const Text("Cancel"),
82-
onPressed: () => Navigator.of(dialogContext).pop(false),
83-
),
84-
ElevatedButton(
85-
child: const Text("Ok"),
86-
onPressed: () => Navigator.of(dialogContext).pop(true),
87-
),
88-
],
89-
),
90-
);
91-
if (!mounted) return;
92-
if (result == true) {
93-
await Permission.phone.request();
94-
}
95-
}
96-
97-
Future<void> _showManualPermissionSettingDialog() async {
98-
if (!mounted) return;
99-
final result = await showDialog<bool>(
100-
context: context,
101-
builder: (dialogContext) {
102-
return AlertDialog(
103-
title: const Text('Permission Needed'),
104-
content: const SingleChildScrollView(
105-
child: ListBody(
106-
children: <Widget>[
107-
Text('This app needs phone permission to make calls.'),
108-
Text('Please enable it in the app settings.'),
109-
],
110-
),
111-
),
112-
actions: <Widget>[
113-
TextButton(
114-
child: const Text('Cancel'),
115-
onPressed: () {
116-
Navigator.of(dialogContext).pop(false);
117-
},
118-
),
119-
TextButton(
120-
child: const Text('Settings'),
121-
onPressed: () {
122-
Navigator.of(dialogContext).pop(true);
123-
},
124-
),
125-
],
126-
);
127-
},
128-
);
129-
if (!mounted) return;
130-
if (result == true) {
131-
await openAppSettings();
132-
}
133-
}
134-
71+
/// Displays a confirmation dialog before initiating the phone call.
72+
13573
Future<void> _showConfirmationDialog(BuildContext context) async {
136-
// Capture the context synchronously.
74+
// Capture the current BuildContext synchronously.
13775

13876
final localContext = context;
13977
showDialog(
@@ -149,7 +87,7 @@ class _CallIconState extends State<CallIcon> {
14987
ElevatedButton(
15088
child: const Text("Yes"),
15189
onPressed: () async {
152-
Navigator.of(dialogContext).pop(); // Close the dialog first.
90+
Navigator.of(dialogContext).pop();
15391
await _initiatePhoneCall(localContext);
15492
},
15593
),
@@ -158,6 +96,8 @@ class _CallIconState extends State<CallIcon> {
15896
);
15997
}
16098

99+
/// Initiates the phone call process.
100+
161101
Future<void> _initiatePhoneCall(BuildContext context) async {
162102
// Capture the BuildContext synchronously.
163103

@@ -168,45 +108,18 @@ class _CallIconState extends State<CallIcon> {
168108
_iconColor = Colors.red;
169109
});
170110

171-
// If running on Linux, skip permission checks.
111+
// For iOS/Android/Linux, simply attempt the phone call.
172112

173-
if (Platform.isLinux) {
174-
try {
175-
await UssdPhoneCallSms().phoneCall(phoneNumber: widget.contactNumber);
176-
} catch (e) {
177-
if (!mounted) return;
178-
showAlert(localContext,
179-
'Fail to call ${widget.contactNumber}! Phone call may not be supported on Linux.');
180-
}
113+
try {
114+
await UssdPhoneCallSms().phoneCall(phoneNumber: widget.contactNumber);
115+
} catch (e) {
181116
if (!mounted) return;
182-
setState(() {
183-
_iconColor = Colors.deepPurple;
184-
});
185-
return;
186-
}
187-
188-
// For iOS/Android, use permission_handler.
189117

190-
final callStatus = await Permission.phone.status;
191-
if (!mounted) return;
192-
if (callStatus.isPermanentlyDenied) {
193-
await _showManualPermissionSettingDialog();
194-
if (!mounted) return;
195-
} else if (callStatus.isDenied) {
196-
await _showPermissionDialog(localContext);
197-
if (!mounted) return;
198-
} else {
199-
try {
200-
await UssdPhoneCallSms().phoneCall(phoneNumber: widget.contactNumber);
201-
} catch (e) {
202-
if (!mounted) return;
203-
showAlert(localContext,
204-
'Fail to call ${widget.contactNumber}! Please check app permission!');
205-
}
118+
showAlert(localContext,
119+
'Fail to call ${widget.contactNumber}! Please check app permission or platform support!');
206120
}
207121

208122
if (!mounted) return;
209-
210123
setState(() {
211124
_iconColor = Colors.deepPurple;
212125
});

pubspec.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ dependencies:
5050
flutter_riverpod: ^2.4.9
5151
riverpod: ^2.6.1
5252
badges: ^3.1.2
53-
permission_handler: ^11.4.0
5453
ussd_phone_call_sms: ^0.0.3
5554

5655
dev_dependencies:

0 commit comments

Comments
 (0)