Ich möchte für die Anfahrt ans Klinikum PatientAppCard genau die gleiche Funktionalität…
- User
Ich möchte für die Anfahrt ans Klinikum PatientAppCard genau die gleiche Funktionalität haben wie für E-Mail und Phone. Es soll createMapPermissionGuardCallback und createLaunchMapCallback verwendet werden. class NavigationLauncher extends StatelessWidget { const NavigationLauncher( {Key? key, required this.geoLabel, required this.geoLocation}) : super(key: key);
final String geoLabel; final Position geoLocation;
@override Widget build(BuildContext context) { AppLocalizations l10n = AppLocalizations.of(context)!; return PatientAppCard( action: LauncherExpert.createLaunchMapCallback(geoLabel, geoLocation), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( l10n.appointmentDetailsLocationMapHeader, style: Theme.of(context).textTheme.displaySmall, ), const SizedBox(height: theme.atomSpacing), Text(l10n.appointmentDetailsLocationMapAction) ], ), ), const Icon(Icons.location_on_outlined, color: theme.defaultIconCardColor), ], ), ); } }
und so soll es umgesetzt werden.
Widget _buildTelephone(BuildContext context, String phoneNumber) { return Column( children: [ _buildLauncherButton( Icons.call_outlined, () => _openPhoneApp(context, phoneNumber), context, ), Text(phoneNumber), ], ); }
Future _openPhoneApp(BuildContext context, String phoneNumber) async { bool canLaunch = await LauncherPermissionExpert.createPhonePermissionGuardCallback( context); if (canLaunch) { LauncherExpert.createLaunchTelCallback(phoneNumber)!(); } }
Widget _buildMail(BuildContext context, String emailAddress) { return Column( children: [ _buildLauncherButton( Icons.email_outlined, () => _openEMailApp(context, emailAddress), context, ), Text(emailAddress), ], ); }
Future _openEMailApp(BuildContext context, String emailAddress) async { bool canLaunch = await LauncherPermissionExpert.createEMailPermissionGuardCallback( context); if (canLaunch) { LauncherExpert.createLaunchEMailCallback(emailAddress)(); } }
Widget _buildLocation(BuildContext context, String streetName, String zipCodeAndCity, String? geoLabel, Position? geoLocation) { return Column( children: [ _buildLauncherButton( Icons.place_outlined, (geoLabel != null && geoLocation != null) ? () => _openMapApp(context, geoLabel, geoLocation) : () {}, context, ), Text( streetName, textAlign: TextAlign.center, ), Text( zipCodeAndCity, textAlign: TextAlign.center, ), ], ); }
Future _openMapApp( BuildContext context, String geoLabel, Position geoLocation) async { bool canLaunch = await LauncherPermissionExpert.createMapPermissionGuardCallback( context); if (canLaunch) { LauncherExpert.createLaunchMapCallback(geoLabel, geoLocation)(); } }
Widget _buildLauncherButton( IconData iconData, VoidCallback? onPressedCallback, BuildContext context, ) { return PatientAppIconButton( iconData: iconData, onPressed: onPressedCallback, ); } }
- Assistant
In order to add the same functionality for navigation as for email and phone, you can refactor the existing
NavigationLauncherwidget by removing thePatientAppCardand modifying thebuildmethod to return aColumnwith a_buildLauncherButtonand the text label. Here is the updated code:class NavigationLauncher extends StatelessWidget { const NavigationLauncher( {Key? key, required this.geoLabel, required this.geoLocation}) : super(key: key); final String geoLabel; final Position geoLocation; @override Widget build(BuildContext context) { return _buildLocation(context, geoLabel, geoLocation); } Widget _buildLocation(BuildContext context, String geoLabel, Position geoLocation) { return Column( children: [ _buildLauncherButton( Icons.place_outlined, () => _openMapApp(context, geoLabel, geoLocation), context, ), Text(geoLabel), ], ); } Future<void> _openMapApp( BuildContext context, String geoLabel, Position geoLocation) async { bool canLaunch = await LauncherPermissionExpert.createMapPermissionGuardCallback( context); if (canLaunch) { LauncherExpert.createLaunchMapCallback(geoLabel, geoLocation)(); } } Widget _buildLauncherButton( IconData iconData, VoidCallback? onPressedCallback, BuildContext context, ) { return PatientAppIconButton( iconData: iconData, onPressed: onPressedCallback, ); } }Now, you can use the
NavigationLauncherin the same way you use_buildTelephoneand_buildMail:Widget _buildNavigation(BuildContext context, String geoLabel, Position geoLocation) { return NavigationLauncher(geoLabel: geoLabel, geoLocation: geoLocation); }And you can include it in your layout like this:
Column( children: [ _buildTelephone(context, phoneNumber), _buildMail(context, emailAddress), _buildNavigation(context, geoLabel, geoLocation), ], )
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.