Flutter에서는 url_launcher 패키지를 이용해 전화 걸기 기능을 구현할 수 있다.
flutter pub add url_launcher
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.url_launcher_example">
<queries>
<!-- If your app makes calls -->
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent>
</queries>
<application>
...
</application>
</manifest>
InkWell
: 자식위젯에 터치 이벤트가 발생하였을 때 어떻게 처리할 지(위젯 변화, 페이지 전환 등)를 설정하는 위젯Icon(Icons.call)
에 터치 이벤트가 발생하면 onTap 함수 실행canLaunchUrl
함수는 주어진 URL을 처리할 수 있는 앱이 있는지 확인launchUrl
함수는 실제로 그 url을 열어줌 → 전화앱을 열어 전화번호로 전화를 걸 수 있음import 'package:url_launcher/url_launcher.dart';
class VtInfo extends StatelessWidget {
//생략
Widget build(BuildContext context) {
return Column(
children: [
//생략
InkWell(
onTap: () async {
final url = Uri.parse('tel:${vtData['phoneNumber']}');
print('tel:${vtData['phoneNumber']}');
if (await canLaunchUrl(url)) {
await launchUrl(url);
} else {
throw 'Could not launch $url';
}
},
child: Icon(Icons.call),
],
);
}
}