From 712500c846c9ddbb2f057b2d428ec7e24226aaed Mon Sep 17 00:00:00 2001 From: johanneskhage Date: Sun, 20 Oct 2024 14:01:32 +0200 Subject: [PATCH 1/2] wroks for android --- lib/pages/menu/menu_page.dart | 93 +++++++++++-------- linux/flutter/generated_plugin_registrant.cc | 4 + linux/flutter/generated_plugins.cmake | 1 + macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 8 ++ pubspec.yaml | 1 + .../flutter/generated_plugin_registrant.cc | 3 + windows/flutter/generated_plugins.cmake | 1 + 8 files changed, 72 insertions(+), 41 deletions(-) diff --git a/lib/pages/menu/menu_page.dart b/lib/pages/menu/menu_page.dart index 83826726..030502d6 100644 --- a/lib/pages/menu/menu_page.dart +++ b/lib/pages/menu/menu_page.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:native_ios_dialog/native_ios_dialog.dart'; import 'package:url_launcher/url_launcher.dart'; +import 'package:flutter_platform_alert/flutter_platform_alert.dart'; import '/components/animated_button.dart'; import '/components/online_scaffold.dart'; @@ -110,53 +111,63 @@ class MenuPageState extends State { database = Databases(client); } - void initiateDeletion(BuildContext context) { + Future initiateDeletion(BuildContext context) async { final bool isIOS = Theme.of(context).platform == TargetPlatform.iOS; - if (isIOS) { - cupertionDeleteDialog(); - } else { - showDialog(context: context, builder: (context) => materialDeleteDialog()); + final result = await FlutterPlatformAlert.showCustomAlert( + windowTitle: 'Bekreft sletting', + text: 'Er du sikker på at du vil slette brukerdataene dine?', + iconStyle: IconStyle.warning, + negativeButtonTitle: 'Slett', + neutralButtonTitle: 'Avbryt', + options: PlatformAlertOptions( + windows: WindowsAlertOptions(preferMessageBox: true), + ), + ); + + if (result == CustomButton.negativeButton) { + deleteUserData(); } - } - void cupertionDeleteDialog() { - NativeIosDialog( - title: 'Bekreft sletting', - message: 'Er du sikker på at du vil slette brukerdataene dine?', - actions: [ - NativeIosDialogAction( - text: 'Avbryt', - style: NativeIosDialogActionStyle.cancel, - onPressed: () {}, - ), - NativeIosDialogAction( - text: 'Slett', - style: NativeIosDialogActionStyle.destructive, - onPressed: deleteUserData, - ), - ], - ).show(); + // if (isIOS) { + // cupertionDeleteDialog(); + // } else { + // showDialog(context: context, builder: (context) => materialDeleteDialog()); + // } } - Widget materialDeleteDialog() { - return AlertDialog( - title: const Text('Bekreft sletting'), - content: const Text('Er du sikker på at du vil slette brukerdataene dine?'), - actions: [ - TextButton( - onPressed: () { - AppNavigator.pop(); - }, - child: const Text('Avbryt'), - ), - TextButton( - onPressed: deleteUserData, - child: const Text('Slett'), - ), - ], - ); - } + // void cupertionDeleteDialog() { + // NativeIosDialog( + // title: 'Bekreft sletting', + // message: 'Er du sikker på at du vil slette brukerdataene dine?', + // actions: [ + // NativeIosDialogAction( + // text: 'Avbryt', + // style: NativeIosDialogActionStyle.cancel, + // onPressed: () {}, + // ), + // NativeIosDialogAction( + // text: 'Slett', + // style: NativeIosDialogActionStyle.destructive, + // onPressed: deleteUserData, + // ), + // ], + // ).show(); + // } + + // materialDeleteDialog() async { + // final result = await FlutterPlatformAlert.showCustomAlert( + // windowTitle: 'Bekreft sletting', + // text: 'Er du sikker på at du vil slette brukerdataene dine?', + // iconStyle: IconStyle.warning, + // negativeButtonTitle: 'Slett', + // neutralButtonTitle: 'Avbryt', + // options: PlatformAlertOptions( + // windows: WindowsAlertOptions(preferMessageBox: true), + // ), + // ); + // return result; + // } void deleteUserData() { final userInfo = io.Client.userCache.value; diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 64a665d2..85fe2e7a 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -7,6 +7,7 @@ #include "generated_plugin_registrant.h" #include +#include #include #include #include @@ -15,6 +16,9 @@ void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) file_selector_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin"); file_selector_plugin_register_with_registrar(file_selector_linux_registrar); + g_autoptr(FlPluginRegistrar) flutter_platform_alert_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterPlatformAlertPlugin"); + flutter_platform_alert_plugin_register_with_registrar(flutter_platform_alert_registrar); g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin"); flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 0e508b6c..5c1ebbf3 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -4,6 +4,7 @@ list(APPEND FLUTTER_PLUGIN_LIST file_selector_linux + flutter_platform_alert flutter_secure_storage_linux url_launcher_linux window_to_front diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 6466ad24..e0da1e7d 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -12,6 +12,7 @@ import firebase_core import firebase_messaging import flutter_inappwebview_macos import flutter_local_notifications +import flutter_platform_alert import flutter_secure_storage_macos import flutter_web_auth_2 import native_ios_dialog @@ -32,6 +33,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FLTFirebaseMessagingPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseMessagingPlugin")) InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin")) FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin")) + FlutterPlatformAlertPlugin.register(with: registry.registrar(forPlugin: "FlutterPlatformAlertPlugin")) FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin")) FlutterWebAuth2Plugin.register(with: registry.registrar(forPlugin: "FlutterWebAuth2Plugin")) NativeIosDialogPlugin.register(with: registry.registrar(forPlugin: "NativeIosDialogPlugin")) diff --git a/pubspec.lock b/pubspec.lock index 36414fe4..53f24c01 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -454,6 +454,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.3+2" + flutter_platform_alert: + dependency: "direct main" + description: + name: flutter_platform_alert + sha256: "29a27c81660468bfb7746bc78205f79e07f18ca785e0aeaf70eac28d7a011edb" + url: "https://pub.dev" + source: hosted + version: "0.6.1" flutter_plugin_android_lifecycle: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index c8e33d98..a411b9b1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,6 +42,7 @@ dependencies: swipeable_page_route: ^0.4.2 native_ios_dialog: ^0.2.1 go_router: ^14.3.0 + flutter_platform_alert: ^0.6.1 dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 43f44bc0..c46e548f 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +21,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { registry->GetRegistrarForPlugin("FirebaseCorePluginCApi")); FlutterInappwebviewWindowsPluginCApiRegisterWithRegistrar( registry->GetRegistrarForPlugin("FlutterInappwebviewWindowsPluginCApi")); + FlutterPlatformAlertPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("FlutterPlatformAlertPlugin")); FlutterSecureStorageWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin")); UrlLauncherWindowsRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 93a4a651..ce4f267f 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST file_selector_windows firebase_core flutter_inappwebview_windows + flutter_platform_alert flutter_secure_storage_windows url_launcher_windows window_to_front From aa48d8239ed07ff9df26c77c3b8bee0da62d69ea Mon Sep 17 00:00:00 2001 From: johanneskhage Date: Sun, 20 Oct 2024 14:28:57 +0200 Subject: [PATCH 2/2] added native for avmelding --- lib/pages/event/cards/event_card_buttons.dart | 57 +++++-------------- lib/pages/menu/menu_page.dart | 39 ------------- 2 files changed, 15 insertions(+), 81 deletions(-) diff --git a/lib/pages/event/cards/event_card_buttons.dart b/lib/pages/event/cards/event_card_buttons.dart index 2caa8844..b4bb5e49 100644 --- a/lib/pages/event/cards/event_card_buttons.dart +++ b/lib/pages/event/cards/event_card_buttons.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; +import 'package:flutter_platform_alert/flutter_platform_alert.dart'; import 'package:go_router/go_router.dart'; import 'package:http/http.dart' as http; import 'package:native_ios_dialog/native_ios_dialog.dart'; @@ -158,48 +159,20 @@ class _EventCardButtonsState extends State { ); } - void showUnregisterDialog() { - final bool isIOS = Platform.isIOS; - - if (isIOS) { - NativeIosDialog(title: 'Bekreft avmelding', actions: [ - NativeIosDialogAction( - text: 'Avbryt', - style: NativeIosDialogActionStyle.cancel, - onPressed: () {}, - ), - NativeIosDialogAction( - text: 'Bekreft', - style: NativeIosDialogActionStyle.destructive, - onPressed: () { - unregisterForEvent(widget.model.id, context); - }, - ), - ]).show(); - } else { - // TODO: Implement Android dialog - showDialog( - context: context, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('Bekreft avemelding'), - content: const Text('Er du sikker på at du vil melde av?'), - actions: [ - TextButton( - onPressed: () => rootNavigator.currentState!.pop(), - child: Text('Avbryt'), - ), - TextButton( - child: const Text('Meld av'), - onPressed: () { - rootNavigator.currentState!.pop(); - unregisterForEvent(widget.model.id, context); - }, - ), - ], - ); - }, - ); + Future showUnregisterDialog() async { + final result = await FlutterPlatformAlert.showCustomAlert( + windowTitle: 'Bekreft avmelding', + text: 'Er du sikker på at du vil melde deg av?', + iconStyle: IconStyle.warning, + negativeButtonTitle: 'Meld av', + neutralButtonTitle: 'Avbryt', + options: PlatformAlertOptions( + windows: WindowsAlertOptions(preferMessageBox: true), + ), + ); + + if (result == CustomButton.negativeButton) { + unregisterForEvent(widget.model.id, context); } } diff --git a/lib/pages/menu/menu_page.dart b/lib/pages/menu/menu_page.dart index 030502d6..3096e7f6 100644 --- a/lib/pages/menu/menu_page.dart +++ b/lib/pages/menu/menu_page.dart @@ -128,47 +128,8 @@ class MenuPageState extends State { if (result == CustomButton.negativeButton) { deleteUserData(); } - - // if (isIOS) { - // cupertionDeleteDialog(); - // } else { - // showDialog(context: context, builder: (context) => materialDeleteDialog()); - // } } - // void cupertionDeleteDialog() { - // NativeIosDialog( - // title: 'Bekreft sletting', - // message: 'Er du sikker på at du vil slette brukerdataene dine?', - // actions: [ - // NativeIosDialogAction( - // text: 'Avbryt', - // style: NativeIosDialogActionStyle.cancel, - // onPressed: () {}, - // ), - // NativeIosDialogAction( - // text: 'Slett', - // style: NativeIosDialogActionStyle.destructive, - // onPressed: deleteUserData, - // ), - // ], - // ).show(); - // } - - // materialDeleteDialog() async { - // final result = await FlutterPlatformAlert.showCustomAlert( - // windowTitle: 'Bekreft sletting', - // text: 'Er du sikker på at du vil slette brukerdataene dine?', - // iconStyle: IconStyle.warning, - // negativeButtonTitle: 'Slett', - // neutralButtonTitle: 'Avbryt', - // options: PlatformAlertOptions( - // windows: WindowsAlertOptions(preferMessageBox: true), - // ), - // ); - // return result; - // } - void deleteUserData() { final userInfo = io.Client.userCache.value;