From 9fffe1533192c5a2f744ef253583030824c8dd4c Mon Sep 17 00:00:00 2001 From: uumair327 Date: Mon, 13 May 2024 18:23:25 +0530 Subject: [PATCH] Emergency ui improve --- lib/src/screens/emergencyContactPage.dart | 51 ++++++++++++++++------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/lib/src/screens/emergencyContactPage.dart b/lib/src/screens/emergencyContactPage.dart index 0ed59e4..2fee8a1 100644 --- a/lib/src/screens/emergencyContactPage.dart +++ b/lib/src/screens/emergencyContactPage.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:url_launcher/url_launcher.dart'; class EmergencyContactPage extends StatelessWidget { @override @@ -19,9 +20,9 @@ class EmergencyContactPage extends StatelessWidget { icon: Icons.local_hospital, title: 'Emergency Services', contacts: [ - 'Police: 911', - 'Fire Department: 911', - 'Medical Emergency: 911', + {'name': 'Police', 'number': '911'}, + {'name': 'Fire Department', 'number': '911'}, + {'name': 'Medical Emergency', 'number': '911'}, ], ), const SizedBox(height: 20), @@ -30,9 +31,9 @@ class EmergencyContactPage extends StatelessWidget { icon: Icons.child_care, title: 'Child Safety', contacts: [ - 'National Center for Missing & Exploited Children: 1-800-843-5678', - 'Childhelp National Child Abuse Hotline: 1-800-422-4453', - 'Poison Control Center: 1-800-222-1222', + {'name': 'National Center for Missing & Exploited Children', 'number': '1-800-843-5678'}, + {'name': 'Childhelp National Child Abuse Hotline', 'number': '1-800-422-4453'}, + {'name': 'Poison Control Center', 'number': '1-800-222-1222'}, ], ), ], @@ -46,7 +47,7 @@ class EmergencyContactPage extends StatelessWidget { Widget _buildCard({ required IconData icon, required String title, - required List contacts, + required List> contacts, }) { return Card( elevation: 4, @@ -77,14 +78,25 @@ class EmergencyContactPage extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: contacts .map((contact) => Padding( - padding: const EdgeInsets.symmetric(vertical: 4.0), - child: Text( - contact, - style: const TextStyle( - fontSize: 16, - ), - ), - )) + padding: const EdgeInsets.symmetric(vertical: 4.0), + child: ElevatedButton.icon( + onPressed: () { + _launchPhone(contact['number']!); + }, + icon: Icon( + Icons.phone, + size: 20, + ), + label: Text( + '${contact['name']}: ${contact['number']}', + style: const TextStyle(fontSize: 16), + ), + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all(Colors.green), // Use MaterialStateProperty.all to set background color + padding: MaterialStateProperty.all(EdgeInsets.symmetric(vertical: 10, horizontal: 15)), + ), + ), + )) .toList(), ), ], @@ -92,4 +104,13 @@ class EmergencyContactPage extends StatelessWidget { ), ); } + + void _launchPhone(String phoneNumber) async { + final Uri phoneLaunchUri = Uri(scheme: 'tel', path: phoneNumber); + if (await canLaunch(phoneLaunchUri.toString())) { + await launch(phoneLaunchUri.toString()); + } else { + throw 'Could not launch $phoneLaunchUri'; + } + } }