import 'package:diplomaticquarterapp/core/model/contactus/get_hmg_locations.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:flutter/material.dart'; import 'package:maps_launcher/maps_launcher.dart'; import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; import 'avatar/large_avatar.dart'; import 'my_rich_text.dart'; import 'dart:io' show Platform; class HospitalLocation extends StatelessWidget { final GetHMGLocationsModel location; final bool showCity; final String waitingTime; HospitalLocation(this.location, {Key key, this.showCity = false, this.waitingTime}) : super(key: key); @override Widget build(BuildContext context) { ProjectViewModel projectViewModel = Provider.of(context); return Container( padding: const EdgeInsets.only(left: 12, right: 12, top: 12, bottom: 12), decoration: BoxDecoration( borderRadius: BorderRadius.all( Radius.circular(10.0), ), boxShadow: [ BoxShadow( color: Color(0xff000000).withOpacity(.05), //spreadRadius: 5, blurRadius: 27, offset: Offset(0, -3), ), ], color: Colors.white), child: Row( children: [ Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( location.locationName.trim(), style: TextStyle(fontSize: 16, letterSpacing: -0.64, fontWeight: FontWeight.w600, color: Color(0xff2E303A)), ), SizedBox(height: 10), Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ LargeAvatar( name: "", url: location?.projectImageURL?.toString() ?? 'https://hmgwebservices.com/Images/Hospitals/15.jpg', width: 48, height: 48, radius: 30, ), SizedBox(width: 10), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ if (showCity) MyRichText(TranslationBase.of(context).city + ":", location.cityName?.trim().toString(), projectViewModel.isArabic), MyRichText(TranslationBase.of(context).distance + ":", location.distanceInKilometers.toString() + " " + TranslationBase.of(context).km_ ?? "", projectViewModel.isArabic), if (waitingTime != null) MyRichText(TranslationBase.of(context).waitingTime, waitingTime, projectViewModel.isArabic), ], ), ) ], ), ], ), ), Column( children: [ contactButton(Icons.location_on, TranslationBase.of(context).locationa, () { // MapsLauncher.launchCoordinates(double.parse(location.latitude), double.parse(location.longitude), location.locationName); // launchMap( double.parse(location.latitude), double.parse(location.longitude)); navigateTo(double.parse(location.latitude), double.parse(location.longitude)); }), SizedBox(height: 10), contactButton(Icons.call, TranslationBase.of(context).callNow, () { launch("tel://" + location.phoneNumber); }), ], ), ], ), ); } Widget contactButton(IconData _iconData, String title, VoidCallback callback) { return SizedBox( height: 32, width: 100.0, child: FlatButton.icon( color: Color(0xffF5F5F5), shape: StadiumBorder(side: BorderSide(color: Color(0xffF0F0F0), width: 1)), onPressed: callback, icon: Icon( _iconData, size: 12, color: Color(0xff2E303A), ), label: Text( title, style: TextStyle(fontSize: 12, letterSpacing: -0.48, fontWeight: FontWeight.w600, color: Color(0xff2E303A)), ), ), ); } static void navigateTo(double latitude, double longitude) async { var uri = Uri.parse("google.navigation:q=$latitude,$longitude&mode=d"); if (await canLaunch(uri.toString())) { await launch(uri.toString()); } else { throw 'Could not launch ${uri.toString()}'; } } // launchMap(latitude, longitude) async { // var url = ''; // var urlAppleMaps = ''; // if (Platform.isAndroid) { // url = "https://www.google.com/maps/search/?api=1&query=${latitude},${longitude}"; // } else { // urlAppleMaps = 'https://maps.apple.com/?q=$latitude,$longitude'; // url = "comgooglemaps://?saddr=&daddr=$latitude,$longitude&directionsmode=driving"; // if (await canLaunch(url)) { // await launch(url); // } else { // throw 'Could not launch $url'; // } // } // // if (await canLaunch(url)) { // await launch(url); // } else if (await canLaunch(urlAppleMaps)) { // await launch(urlAppleMaps); // } else { // throw 'Could not launch $url'; // } // } }