import ‘dart:convert’; import ‘packa… · The Chat Archive
Explore import ‘dart:convert’; import ‘package:flutter/material.dart’; import… Save Share Download ▾ Reportimport ‘dart:convert’;
import ‘package:flutter/material.dart’;
import ‘package:intl/locale.dart’ as intl;
import ‘package:patient_app/models/api_configuration.dart’;
import ‘package:patient_app/repositories/secure_store.dart’;
class SettingsRepository {
static final SettingsRepository _instance = SettingsRepository._internal();
factory SettingsRepository() => _instance;
SettingsRepository._internal();
static const _applicationIdStorageKey = ‘pbeApplicationId’;
static const _localeStorageKey = ‘pbeLocale’;
static const _apiConfigurationStorageKey = ‘pbeApiConfiguration’;
static const phoneAppLaunchPermission = ‘phoneAppLaunchPermission’;
static const mailAppLaunchPermission = ‘mailAppLaunchPermission’;
static const mapAppLaunchPermission = ‘mapAppLaunchPermission’;
String? _applicationId;
Locale? _locale;
ApiConfiguration? _apiConfiguration;
Future store(String key, bool value) async {
SecureStore().write(key, value.toString());
}
Future<bool?> read(String key) async {
String? storedValue = await SecureStore().read(key);
if (storedValue != null) {
return storedValue.toLowerCase() == ‘true’;
}
return null;
}
Future clear(String key) async {
await SecureStore().delete(key);
}
Future storeApplicationId(String applicationId) async {
SecureStore().write(_applicationIdStorageKey, applicationId);
_applicationId = applicationId;
}
Future<String?> readApplicationId() async {
return _applicationId ??=
await SecureStore().read(_applicationIdStorageKey);
}
Future clearApplicationId() async {
await SecureStore().delete(_applicationIdStorageKey);
_applicationId = null;
}
Future storeLocale(Locale locale) async {
SecureStore().write(_localeStorageKey, locale.toLanguageTag());
_locale = locale;
}
Future<Locale?> readLocale() async {
if (_locale != null) {
return _locale;
}
String? localeIdentifier = await SecureStore().read(_localeStorageKey);
if (localeIdentifier != null) {
// Flutter/Flutter Locale class does not have a parser method,
// the intl package’s LocaleParser is used instead
// also see https://github.com/flutter/flutter/issues/55720
intl.Locale? parsedLocale = intl.Locale.tryParse(localeIdentifier);
if (parsedLocale != null) {
return Locale.fromSubtags(
languageCode: parsedLocale.languageCode,
countryCode: parsedLocale.countryCode,
scriptCode: parsedLocale.scriptCode,
);
}
}
return null;
}
Future clearLocale() async {
await SecureStore().delete(_localeStorageKey);
_locale = null;
}
Future storeApiConfiguration(ApiConfiguration apiConfiguration) async {
await SecureStore().write(
_apiConfigurationStorageKey, json.encode(apiConfiguration.toJson()));
_apiConfiguration = apiConfiguration;
}
Future<ApiConfiguration?> readApiConfiguration() async {
ApiConfiguration? apiConfiguration;
Show full message · 406 lines Assistant2023-05-04 14:53 UTC Copy response
Ich habe mir aber keinen Context und benutze l10n mit parametern:
late AppLocalizations _l10n;
launchPermissionTitle: _l10n.general_launchPermissionTitle;
"general_launchPermissionTitle": "{placeholder} App öffnen?",
Widget _buildLauncherButton(
IconData iconData, VoidCallback? onPressedCallback, String key) {
return PatientAppIconButton(
iconData: iconData,
onPressed: () async {
final permission = await LaunchPermissionProvider().readMailAppLaunchPermission();
if(permission == null || permission == false)
{
showDialog(
context: context,
builder: (context) {
final loc = AppLocalizations.of(context);
String title = '';
String description = '';
switch (key) {
case SettingsRepository.phoneAppLaunchPermission:
title = loc!.general_launchPhonePermissionTitle;
description = loc.general_launchPermissionDescription;
break;
case SettingsRepository.mailAppLaunchPermission:
title = loc!.general_launchMailPermissionTitle;
description = loc.general_launchPermissionDescription;
break;
case SettingsRepository.mapAppLaunchPermission:
title = loc!.general_launchMapPermissionTitle;
description = loc.general_launchPermissionDescription;
break;
}
Show full message · 67 lines Assistant2023-05-04 15:25 UTC Copy response
Assistant2023-05-04 15:46 UTC Copy response
Apologies for the confusion. In order to pass the context to the _buildLauncherButton function, you can modify the function to accept BuildContext context as an additional parameter:
dart Copy code
Widget _buildLauncherButton(
BuildContext context, IconData iconData, VoidCallback? onPressedCallback, String key) {
// ...
}
Next, update the calls to _buildLauncherButton in the , , and methods to pass the :
Assistant2023-05-04 16:10 UTC Copy response
Copy first prompt
Details
Provider OpenAI
Model provenance As recorded by source dataset
Turns 4 (8 messages)
Language en
Conversation date May 4, 2023
Added to archive Nov 16, 2026
ID 01m7h4190w3pd05h88qfkvnhf5Source & license Imported from WildChat-4.8M (AI2) (source ). Imported records earn no Research Points.
Upstream record: d01f01662c16cfa64c276e80a08ad410
Zhao et al., WildChat: 1M ChatGPT Interaction Logs in the Wild (ICLR 2024). Contains information from WildChat-4.8M, made available under the ODC Attribution License.
License: ODC-BY-1.0
String? apiConfigurationString =
await SecureStore().read(_apiConfigurationStorageKey);
if (apiConfigurationString != null) {
try {
apiConfiguration =
ApiConfiguration.fromJson(json.decode(apiConfigurationString));
} catch (e) {
// do not prevent app start on failure, just delete old stored apiConfiguration
await clearApiConfiguration();
}
}
_apiConfiguration = apiConfiguration;
return _apiConfiguration;
}
Future clearApiConfiguration() async {
await SecureStore().delete(_apiConfigurationStorageKey);
_apiConfiguration = null;
}
}
/* Future store(String key, bool value) async {
SecureStore().write(key, value.toString());
}
Future<bool?> read(String key) async {
String? storedValue = await SecureStore().read(key);
if (storedValue != null) {
return storedValue.toLowerCase() == ‘true’;
}
return null;
}
Future clear(String key) async {
await SecureStore().delete(key);
}
// Launch permissions
Future storeLaunchPermission(String key, bool value) async {
await store(key, value);
}
Future<bool?> readLaunchPermission(String key) async {
return await read(key);
}
Future clearLaunchPermission(String key) async {
await clear(key);
}*/
import ‘package:patient_app/repositories/settings_repository.dart’;
class LaunchPermissionProvider {
static final LaunchPermissionProvider _instance =
LaunchPermissionProvider._internal();
factory LaunchPermissionProvider() => _instance;
LaunchPermissionProvider._internal();
SettingsRepository settingsRepository = SettingsRepository();
// Phone app launch permission
Future storePhoneAppLaunchPermission(bool permission) async {
await settingsRepository.store(
SettingsRepository.phoneAppLaunchPermission, permission);
}
Future<bool?> readPhoneAppLaunchPermission() async {
return await settingsRepository
.read(SettingsRepository.phoneAppLaunchPermission);
}
Future clearPhoneAppLaunchPermission() async {
await settingsRepository.clear(SettingsRepository.phoneAppLaunchPermission);
}
// Mail app launch permission
Future storeMailAppLaunchPermission(bool permission) async {
await settingsRepository.store(
SettingsRepository.mailAppLaunchPermission, permission);
}
Future<bool?> readMailAppLaunchPermission() async {
return await settingsRepository
.read(SettingsRepository.mailAppLaunchPermission);
}
Future clearMailAppLaunchPermission() async {
await settingsRepository.clear(SettingsRepository.mailAppLaunchPermission);
}
// Map app launch permission
Future storeMapAppLaunchPermission(bool permission) async {
await settingsRepository.store(
SettingsRepository.mapAppLaunchPermission, permission);
}
Future<bool?> readMapAppLaunchPermission() async {
return await settingsRepository
.read(SettingsRepository.mapAppLaunchPermission);
}
Future clearMapAppLaunchPermission() async {
await settingsRepository.clear(SettingsRepository.mapAppLaunchPermission);
}
}
Funktioniert jetzt alles korrekt? Was kann ich jetzt damit tun?
Es soll jetzt ein Alert Dialog angezeigt werden wenn man in dem ContactInfo Widget auf ein icon clickt.
Dialog ist AlertDialog class - material library - Dart API (flutter.dev)
general_launchPermissionTitle | general_launchPermissionDescription | general_cancelButtonLabel
general_confirmButtonLabel
E-Mail App öffnen? | Bitte bestätigen Sie, dass Ihre Standard E-Mail App geöffnet wird.
Telefon App öffnen? | Bitte bestätigen Sie, dass Ihre Standard Telefon App geöffnet wird.
Karten App öffnen? | Bitte bestätigen Sie, dass Ihre Standard Karten App geöffnet wird.
Auf die Reinfolge der Buttons achten (Entweder erst Cancel dann Confirm, oder so wie es in anderen Dialogen ist)
import ‘package:flutter/material.dart’;
import ‘package:flutter_gen/gen_l10n/patient_app_localizations.dart’;
import ‘package:patient_app/models/location.dart’;
import ‘package:patient_app/settings.dart’ show AppSettingsProvider;
import ‘package:patient_app/theme/patient_app_colors.dart’;
import ‘package:patient_app/theme/patient_app_theme.dart’ as theme;
import ‘package:patient_app/tools/launcher_expert.dart’;
import ‘package:patient_app/widgets/decorative_image.dart’;
import ‘package:patient_app/widgets/patient_app_icon_button.dart’;
import ‘package:responsive_framework/responsive_framework.dart’;
class ContactInfo extends StatelessWidget {
const ContactInfo({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final responsive = ResponsiveWrapper.of(context);
return ColoredBox(
color: responsive.isLargerThan(MOBILE)
? AppColors.grey
: AppColors.transparent,
child: ResponsiveRowColumn(
layout: responsive.isMobile
? ResponsiveRowColumnType.COLUMN
: ResponsiveRowColumnType.ROW,
children: [
const ResponsiveRowColumnItem(
rowFlex: 1,
child: _ResponsiveContactImage(),
),
ResponsiveRowColumnItem(
rowFlex: 1,
child: Center(
child: Padding(
padding: theme.commonEdgeInsetsFirstElement,
child: _buildContactActions(responsive, context),
),
),
),
],
),
);
}
Widget _buildContactActions(
ResponsiveWrapperData responsive, BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.homeHeadlineHospitalContact,
style: Theme.of(context).textTheme.headline2,
),
const SizedBox(height: theme.extraLargeSpacing),
ResponsiveRowColumn(
rowMainAxisAlignment: MainAxisAlignment.center,
rowCrossAxisAlignment: CrossAxisAlignment.start,
layout: responsive.isDesktop
? ResponsiveRowColumnType.ROW
: ResponsiveRowColumnType.COLUMN,
children: [
if (AppSettingsProvider().contact?.hasPhoneNumber == true)
ResponsiveRowColumnItem(
rowFlex: 1,
child: _buildTelephone(
AppSettingsProvider().contact!.phoneNumber!),
),
if (AppSettingsProvider().contact?.hasPhoneNumber == true)
const ResponsiveRowColumnItem(
child: SizedBox(
height: theme.mediumSpacing,
width: theme.mediumSpacing,
),
),
if (AppSettingsProvider().contact?.hasEmailAddress == true)
ResponsiveRowColumnItem(
rowFlex: 1,
child: _buildMail(AppSettingsProvider().contact!.eMailAddress!),
),
if (AppSettingsProvider().contact?.hasEmailAddress == true)
const ResponsiveRowColumnItem(
child: SizedBox(
height: theme.mediumSpacing,
width: theme.mediumSpacing,
),
),
if (AppSettingsProvider().contact?.hasAddress == true)
ResponsiveRowColumnItem(
rowFlex: 1,
child: _buildLocation(
AppSettingsProvider().contact!.streetName!,
AppSettingsProvider().contact!.zipCodeAndCity!,
AppSettingsProvider().contact?.geoLabel,
AppSettingsProvider().contact?.geoLocation),
),
],
),
],
);
}
Widget _buildTelephone(String phoneNumber) {
return Column(
children: [
_buildLauncherButton(
Icons.call_outlined,
LauncherExpert.createLaunchTelCallback(phoneNumber),
),
Text(phoneNumber),
],
);
}
Widget _buildMail(String emailAddress) {
return Column(
children: [
_buildLauncherButton(
Icons.email_outlined,
LauncherExpert.createLaunchEMailCallback(emailAddress),
),
Text(emailAddress),
],
);
}
Widget _buildLocation(String streetName, String zipCodeAndCity,
String? geoLabel, Position? geoLocation) {
return Column(
children: [
_buildLauncherButton(
Icons.place_outlined,
(geoLabel != null && geoLocation != null)
? LauncherExpert.createLaunchMapCallback(geoLabel, geoLocation)
: () {},
),
Text(
streetName,
textAlign: TextAlign.center,
),
Text(
zipCodeAndCity,
textAlign: TextAlign.center,
),
],
);
}
Widget _buildLauncherButton(
IconData iconData, VoidCallback? onPressedCallback) {
return PatientAppIconButton(
iconData: iconData,
onPressed: onPressedCallback,
);
}
}
class _ResponsiveContactImage extends StatelessWidget {
const _ResponsiveContactImage({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final responsive = ResponsiveWrapper.of(context);
if (responsive.isMobile) {
return AspectRatio(
aspectRatio: 19.0 / 9.0,
child: _buildImageContainer(),
);
} else {
return _buildImageContainer();
}
}
Widget _buildImageContainer() {
return DecorativeImage(
imagePath: AppSettingsProvider().assets.contactInfoImage,
maxHeight: theme.desktopLayoutImageMaxHeight);
}
}
○ Logged_in_user_service:
○ Zustimmung für E-Mail, Telefon, Map => Einzeln
○ Store-Methode: Konvertiert Boolean to String und speichert ihn
○ Ein Text mit Placeholder Variablen
○ Aktion statt Widget übergeben?
Kein Context in Launchexpert => In BuildTelefon machen und dann in Launch
○ Das Speichern immer in Provider? BuisnessSchicht für Repository Zwischenschalten
○ launcherExpert.createLaunchTelCallBakc(phoonenumber)
To display an alert dialog when clicking on an icon in the ContactInfo widget, you can modify the _buildLauncherButton method to include the alert dialog. Here's an example of how to do this:
First, you need to update the import statements inside contact_info.dart file:
dart Copy code
import 'package:patient_app/launch_permission_provider.dart';
import 'package:patient_app/repositories/settings_repository.dart';
Next, update the _buildLauncherButton method to show the AlertDialog:
dart Copy code
Widget _buildLauncherButton(
IconData iconData, VoidCallback? onPressedCallback, String key) {
return PatientAppIconButton(
iconData: iconData,
onPressed: () async {
final permission = await LaunchPermissionProvider().read(key);
if (permission == null || permission == false) {
// Show AlertDialog here
showDialog(
context: context,
builder: (context) {
final loc = AppLocalizations.of(context);
String title = '';
String description = '';
switch (key) {
case SettingsRepository.phoneAppLaunchPermission:
title = loc!.general_launchPhonePermissionTitle;
description = loc.general_launchPermissionDescription;
break;
case SettingsRepository.mailAppLaunchPermission:
title = loc!.general_launchMailPermissionTitle;
description = loc.general_launchPermissionDescription;
break;
case SettingsRepository.mapAppLaunchPermission:
title = loc!.general_launchMapPermissionTitle;
description = loc.general_launchPermissionDescription;
break;
}
return AlertDialog(
title: Text(title),
content: Text(description),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(loc.general_cancelButtonLabel),
),
TextButton(
onPressed: () async {
await LaunchPermissionProvider()
.store(key, true);
Navigator.of(context).pop();
if (onPressedCallback != null) {
onPressedCallback();
}
},
child: Text(
loc.general_confirmButtonLabel,
),
),
],
);
},
);
} else {
if (onPressedCallback != null) {
onPressedCallback();
}
}
},
);
}
Here, the showDialog method case for AlertDialog is added to display an alert depending on the provided key (phone, mail, or map).
Then modify the calls to _buildLauncherButton to include the permission keys:
dart Copy code
Widget _buildTelephone(String phoneNumber) {
return Column(
children: [
_buildLauncherButton(
Icons.call_outlined,
LauncherExpert.createLaunchTelCallback(phoneNumber),
SettingsRepository.phoneAppLaunchPermission,
),
Text(phoneNumber),
],
);
}
Widget _buildMail(String emailAddress) {
return Column(
children: [
_buildLauncherButton(
Icons.email_outlined,
LauncherExpert.createLaunchEMailCallback(emailAddress),
SettingsRepository.mailAppLaunchPermission,
),
Text(emailAddress),
],
);
}
Widget _buildLocation(String streetName, String zipCodeAndCity,
String? geoLabel, Position? geoLocation) {
return Column(
children: [
_buildLauncherButton(
Icons.place_outlined,
(geoLabel != null && geoLocation != null)
? LauncherExpert.createLaunchMapCallback(geoLabel, geoLocation)
: () {},
SettingsRepository.mapAppLaunchPermission,
),
Text(
streetName,
textAlign: TextAlign.center,
),
Text(
zipCodeAndCity,
textAlign: TextAlign.center,
),
],
);
}
Now, when you click on the contact icons in the ContactInfo widget, it should show an appropriate AlertDialog asking for confirmation. If the user confirms, the setting will be stored, and the action will be executed. If the user cancels, the AlertDialog will be closed without storing the setting or executing the action.
return AlertDialog(
title: Text(title),
content: Text(description),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(loc.general_cancelButtonLabel),
),
TextButton(
onPressed: () async {
await LaunchPermissionProvider()
.store(key, true);
Navigator.of(context).pop();
if (onPressedCallback != null) {
onPressedCallback();
}
},
child: Text(
loc.general_confirmButtonLabel,
),
),
],
);
},
);
} else {
if (onPressedCallback != null) {
onPressedCallback();
}
},
);
}
}
Here's an updated version of the provided _buildLauncherButton function that takes into account the l10n with parameters. We can use the general_launchPermissionTitle message inside the _buildLauncherButton function instead of having a separate case for each title:
dart Copy code
Widget _buildLauncherButton(
IconData iconData, VoidCallback? onPressedCallback, String key) {
return PatientAppIconButton(
iconData: iconData,
onPressed: () async {
final permission = await LaunchPermissionProvider()
.readMailAppLaunchPermission();
if (permission == null || permission == false) {
showDialog(
context: context,
builder: (context) {
final loc = AppLocalizations.of(context);
String description = '';
String placeholder = '';
switch (key) {
case SettingsRepository.phoneAppLaunchPermission:
description = loc!.general_launchPermissionDescription;
placeholder = loc.launchPermissionPlaceholderPhoneApp;
break;
case SettingsRepository.mailAppLaunchPermission:
description = loc!.general_launchPermissionDescription;
placeholder = loc.launchPermissionPlaceholderMailApp;
break;
case SettingsRepository.mapAppLaunchPermission:
description = loc!.general_launchPermissionDescription;
placeholder = loc.launchPermissionPlaceholderMapApp;
break;
}
return AlertDialog(
title: Text(
loc.general_launchPermissionTitle.replaceAll('{placeholder}', placeholder)),
content: Text(description),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(loc.general_cancelButtonLabel),
),
TextButton(
onPressed: () async {
await LaunchPermissionProvider().store(key, true);
Navigator.of(context).pop();
if (onPressedCallback != null) {
onPressedCallback();
}
},
child: Text(
loc.general_confirmButtonLabel,
),
),
],
);
},
);
} else {
if (onPressedCallback != null) {
onPressedCallback();
}
}
},
);
}
In your strings_*.arb files, add the placeholders:
json Copy code
{
"general_launchPermissionDescription": "Please confirm to open {placeholder} app.",
"launchPermissionPlaceholderPhoneApp": "Phone",
"launchPermissionPlaceholderMailApp": "E-mail",
"launchPermissionPlaceholderMapApp": "Maps",
...
}
This way, you can customize the placeholder texts for each app in the l10n .arb files accordingly.
Ich habe immer noch keinen Context in _buildLauncherButton.
code Copy code
- Kein Context in Launchexpert => In BuildTelefon durchführen und dann in Launch_Expert
○ Das Speichern immer in Provider? BuisnessSchicht für Repository Zwischenschalten
launcherExpert.createLaunchTelCallBack(phonenumber)
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:patient_app/models/location.dart';
import 'package:url_launcher/url_launcher.dart';
class LauncherExpert {
static VoidCallback? createLaunchTelCallback(String telephoneNumber) {
if (kIsWeb) {
// call not supported in web
return () {};
} else {
return () async {
Uri telUrl = Uri.parse('tel:telephoneNumber');
if (!await launchUrl(telUrl)) {
throw Exception('Could not launch telephone: telUrl');
}
};
}
}
static VoidCallback createLaunchEMailCallback(String emailAddress) {
return () async {
Uri mailUrl = Uri.parse('mailto:emailAddress');
if (!await launchUrl(mailUrl)) {
throw Exception('Could not launch mail to: mailUrl');
}
};
}
static VoidCallback createLaunchMapCallback(String label, Position location) {
return () async {
if (kIsWeb) {
await _launchForWeb(location, label);
} else {
await _launchOnPlatform(location, label);
}
};
}
static Future _launchOnPlatform(Position location, String label) async {
if (Platform.isAndroid) {
await _launchOnAndroid(location, label);
} else if (Platform.isIOS) {
await _launchOnIOS(label, location);
} else {
await _launchGoogleMapsWeb(location, label);
}
}
static Future _launchOnAndroid(Position location, String label) async {
Uri androidUrl = Uri.parse(
'geo:0,0?q=l o c a t i o n . l a t i t u d e , {location.latitude}, l oc a t i o n . l a t i t u d e , {location.longitude}(label)');
if (await canLaunchUrl(androidUrl)) {
if (!await launchUrl(androidUrl)) {
throw Exception('Could not launch maps on android: androidUrl');
}
} else {
await _launchGoogleMapsWeb(location, label);
}
}
static Future _launchOnIOS(String label, Position location) async {
Uri iosGoogleUrl = Uri.parse(
'comgooglemaps://?q=label¢er= {location.latitude},${location.longitude}');
code Copy code
Uri iosAppleMapsUrl = Uri.parse(
'http://maps.apple.com/?q=$label&ll=${location.latitude},${location.longitude}');
if (await canLaunchUrl(iosGoogleUrl)) {
if (!await launchUrl(iosGoogleUrl)) {
throw Exception('Could not launch maps on iOS: $iosGoogleUrl');
}
} else if (await canLaunchUrl(iosAppleMapsUrl)) {
if (!await launchUrl(iosAppleMapsUrl)) {
throw Exception('Could not launch http maps on iOS: $iosAppleMapsUrl');
}
} else {
await _launchGoogleMapsWeb(location, label);
}
}
static Future _launchForWeb(Position location, String label) async {
await _launchGoogleMapsWeb(location, label);
}
static Future _launchGoogleMapsWeb(
Position location, String label) async {
Uri webUrl =
Uri.parse('https://www.google.com/maps/search/?api=1&query=$label ');
if (!await launchUrl(webUrl)) {
throw Exception('Could not launch map on web: $webUrl');
}
}
}
Show full message · 101 lines _buildTelephone
_buildMail
_buildLocation
context
dart Copy code
Widget _buildTelephone(String phoneNumber) {
return Column(
children: [
_buildLauncherButton(
context,
Icons.call_outlined,
LauncherExpert.createLaunchTelCallback(phoneNumber),
SettingsRepository.phoneAppLaunchPermission,
),
Text(phoneNumber),
],
);
}
Widget _buildMail(String emailAddress) {
return Column(
children: [
_buildLauncherButton(
context,
Icons.email_outlined,
LauncherExpert.createLaunchEMailCallback(emailAddress),
SettingsRepository.mailAppLaunchPermission,
),
Text(emailAddress),
],
);
}
Widget _buildLocation(String streetName, String zipCodeAndCity,
String? geoLabel, Position? geoLocation) {
return Column(
children: [
_buildLauncherButton(
context,
Icons.place_outlined,
(geoLabel != null && geoLocation != null)
? LauncherExpert.createLaunchMapCallback(geoLabel, geoLocation)
: () {},
SettingsRepository.mapAppLaunchPermission,
),
Text(
streetName,
textAlign: TextAlign.center,
),
Text(
zipCodeAndCity,
textAlign: TextAlign.center,
),
],
);
}
Now you will have the context in your _buildLauncherButton function and can use it to show the AlertDialog as shown in the previous example.
Wie kann ich im _buildLauncherButton so ändern dass er funktioniert
Widget _buildLauncherButton(
IconData iconData,
VoidCallback? onPressedCallback,
String key,
BuildContext context,
) {
final l10n = AppLocalizations.of(context)!;
code Copy code
return PatientAppIconButton(
iconData: iconData,
onPressed: () async {
final permission =
await LaunchPermissionProvider().readMailAppLaunchPermission();
if (permission == null || permission == false) {
String description = '';
String placeholder = '';
switch (key) {
case SettingsRepository.phoneAppLaunchPermission:
description = l10n.general_launchPermissionTitle('phone');
placeholder = l10n.general_launchPermissionDescription('phone');
break;
case SettingsRepository.mailAppLaunchPermission:
description = l10n.general_launchPermissionTitle('mail');
placeholder = l10n.general_launchPermissionDescription('mail');
break;
case SettingsRepository.mapAppLaunchPermission:
description = l10n.general_launchPermissionTitle('map');
placeholder = l10n.general_launchPermissionDescription('map');
break;
}
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(description),
content: Text(placeholder),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(l10n.general_cancelButtonLabel),
),
TextButton(
onPressed: () async {
Navigator.pop(context);
//TODO: Was soll passieren
if (onPressedCallback != null) {
onPressedCallback();
}
},
child: Text(l10n.general_continueButtonLabel),
),
],
);
},
);
} else {
if (onPressedCallback != null) {
onPressedCallback();
}
}
},
);
Soll ungefähr so aussehen
Widget build(BuildContext context) {
return EntryPointCard(
title: AppLocalizations.of(context)!.userSession_endSession,
description:
AppLocalizations.of(context)!.userSession_endSessionDescription,
icon: const Icon(Icons.logout_outlined),
action: _showDialog(context),
);
}
VoidCallback _showDialog(BuildContext context) {
AppLocalizations l10n = AppLocalizations.of(context)!;
code Copy code
return () => showDialog<bool>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: Text(l10n.logoutConfirmationDialogTitle),
content: Text(l10n.logoutConfirmationDialogText),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context),
style: theme.dialogSecondaryTextButtonStyle,
child: Text(l10n.general_cancelButtonLabel),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
style: theme.dialogPrimaryPermanentlyActionTextButtonStyle,
child: Text(
l10n.general_logoutButtonLabel,
)),
],
),
).then(
(isLogoutConfirmed) {
if (isLogoutConfirmed == true) _handleLogout(context);
},
);
}
Show full message · 105 lines Here's an updated version of the _buildLauncherButton function that is consistent with the provided build function.
dart Copy code
Widget _buildLauncherButton(
IconData iconData,
VoidCallback? onPressedCallback,
String key,
BuildContext context,
) {
final loc = AppLocalizations.of(context)!;
return PatientAppIconButton(
iconData: iconData,
onPressed: () async {
final permission =
await LaunchPermissionProvider().readMailAppLaunchPermission();
if (permission == null || permission == false) {
String title = loc.general_launchPermissionTitle;
String description = '';
switch (key) {
case SettingsRepository.phoneAppLaunchPermission:
description =
loc.general_launchPermissionDescription('{placeholder}', 'phone');
break;
case SettingsRepository.mailAppLaunchPermission:
description =
loc.general_launchPermissionDescription('{placeholder}', 'mail');
break;
case SettingsRepository.mapAppLaunchPermission:
description =
loc.general_launchPermissionDescription('{placeholder}', 'map');
break;
}
showDialog<bool>(
context: context,
builder: (BuildContext context) => AlertDialog(
title: Text(title),
content: Text(description),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context),
child: Text(loc.general_cancelButtonLabel),
),
TextButton(
onPressed: () async {
await LaunchPermissionProvider().store(key, true);
Navigator.pop(context);
if (onPressedCallback != null) {
onPressedCallback();
}
},
child: Text(loc.general_continueButtonLabel),
),
],
),
);
} else {
if (onPressedCallback != null) {
onPressedCallback();
}
}
},
);
}
You can now call _buildLauncherButton in _buildTelephone, _buildMail, and _buildLocation methods, passing the context:
dart Copy code
Widget _buildTelephone(BuildContext context, String phoneNumber) {
// ...
_buildLauncherButton(
context,
Icons.call_outlined,
LauncherExpert.createLaunchTelCallback(phoneNumber),
SettingsRepository.phoneAppLaunchPermission,
),
// ...
}
// Same for _buildMail and _buildLocation
And, call these methods with '_buildContactActions':
dart Copy code
Widget _buildContactActions(
ResponsiveWrapperData responsive, BuildContext context) {
// ...
if (AppSettingsProvider().contact?.hasPhoneNumber == true)
ResponsiveRowColumnItem(
rowFlex: 1,
child: _buildTelephone(context, AppSettingsProvider().contact!.phoneNumber!),
),
// Same for _buildMail and _buildLocation
// ...
}
Next, update your strings_*.arb files:
json Copy code
{
"general_launchPermissionTitle": "{placeholder} App öffnen?",
"general_launchPermissionDescription": "Bitte bestätigen Sie, dass Ihre Standard {placeholder} App geöffnet wird.",
}
Now the AlertDialog should show up on clicking the icon, and the description should be properly formatted.
Copy first response
Not yet included in a published release.