Skip to content

Commit 0eb1e1a

Browse files
committed
new PlatformAlertOptions, removed FlutterPlatformAlertOption
1 parent e617b26 commit 0eb1e1a

35 files changed

+348
-620
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.dart_tool/
3+
**/**/*.lock
34

45
.packages
56
.pub/

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.5.0
2+
3+
- Breaking refactor by replacing FlutterPlatformAlertOption with PlatformAlertOptions.
4+
- New customizations with IosAlertStyle and IosButtonStyle.
5+
- Updates documentation and examples.
6+
17
## 0.4.0
28

39
- Support Flutter 3.10.x.

README.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,19 @@ To show an alert dialog with custom button titles:
7171
import 'package:flutter_platform_alert/flutter_platform_alert.dart';
7272
await FlutterPlatformAlert.playAlertSound();
7373
74-
final clickedButton = await FlutterPlatformAlert.showCustomAlert(
75-
windowTitle: 'This ia title',
76-
text: 'This is body',
77-
positiveButtonTitle: "Positive",
78-
negativeButtonTitle: "Negative",
79-
neutralButtonTitle: "Neutral",
80-
additionalWindowTitleOnWindows: 'Window title',
81-
showAsLinksOnWindows: true);
74+
final result = await FlutterPlatformAlert.showCustomAlert(
75+
windowTitle: 'This is title',
76+
text: 'This is body',
77+
positiveButtonTitle: "Positive",
78+
negativeButtonTitle: "Negative",
79+
neutralButtonTitle: "Neutral",
80+
options: PlatformAlertOptions(
81+
windows: WindowsAlertOptions(
82+
additionalWindowTitle: 'Window title',
83+
showAsLinks: true,
84+
),
85+
),
86+
);
8287
```
8388

8489
## Platform Alert Dialogs
@@ -158,30 +163,34 @@ The package in released under MIT License.
158163

159164
## Screenshots
160165

161-
iOS 15 in Simulator
166+
Android 13 on Pixel 6 emulator
167+
168+
![Android](./screenshot_android.png)
169+
170+
iOS 16 in Simulator
162171

163-
![iOS](https://raw.githubusercontent.com/zonble/flutter_platform_alert/main/screenshot_ios.png)
172+
![iOS](./screenshot_ios.png)
164173

165-
Android 11 on Samsung phone
174+
iOS 15 in Simulator (IosAlertOptions: alertStyle = IosAlertStyle.actionSheet)
166175

167-
![Android](https://raw.githubusercontent.com/zonble/flutter_platform_alert/main/screenshot_android.jpg)
176+
![iOS](./screenshot_ios_sheet.png)
168177

169178
macOS 12 Monterey
170179

171-
![macOS](https://raw.githubusercontent.com/zonble/flutter_platform_alert/main/screenshot_macos.png)
180+
![macOS](./screenshot_macos.png)
172181

173182
Windows 10 with MessageBox API
174183

175-
![Windows](https://raw.githubusercontent.com/zonble/flutter_platform_alert/main/screenshot_windows.png)
184+
![Windows](./screenshot_windows.png)
176185

177186
Windows 11 with TaskDialogIndirect API
178187

179-
![Windows](https://raw.githubusercontent.com/zonble/flutter_platform_alert/main/screenshot_windows_11.png)
188+
![Windows](./screenshot_windows_11.png)
180189

181190
Windows 11 with TaskDialogIndirect API that shows buttons as links
182191

183-
![Windows](https://raw.githubusercontent.com/zonble/flutter_platform_alert/main/screenshot_windows_11_links.png)
192+
![Windows](./screenshot_windows_11_links.png)
184193

185194
Ubuntu 21.10
186195

187-
![linux](https://raw.githubusercontent.com/zonble/flutter_platform_alert/main/screenshot_linux.png)
196+
![linux](./screenshot_linux.png)

android/src/main/kotlin/net/zonble/flutter_platform_alert/FlutterPlatformAlertPlugin.kt

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package net.zonble.flutter_platform_alert
33
import android.app.Activity
44
import android.app.AlertDialog
55
import android.content.Context
6+
import android.content.res.Configuration
67
import android.graphics.Bitmap
78
import android.graphics.BitmapFactory
89
import android.graphics.drawable.BitmapDrawable
910
import android.graphics.drawable.Drawable
1011
import android.media.RingtoneManager
1112
import android.os.Build
1213
import android.util.Base64
13-
import androidx.annotation.NonNull
1414
import androidx.annotation.RequiresApi
1515
import io.flutter.embedding.engine.plugins.FlutterPlugin
1616
import io.flutter.embedding.engine.plugins.activity.ActivityAware
@@ -27,7 +27,7 @@ class FlutterPlatformAlertPlugin : FlutterPlugin, MethodCallHandler, ActivityAwa
2727

2828
@Suppress("UNCHECKED_CAST")
2929
@RequiresApi(Build.VERSION_CODES.N)
30-
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result): Unit =
30+
override fun onMethodCall(call: MethodCall, result: Result): Unit =
3131
when (call.method) {
3232
"playAlertSound" -> {
3333
val notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
@@ -41,13 +41,13 @@ class FlutterPlatformAlertPlugin : FlutterPlugin, MethodCallHandler, ActivityAwa
4141
if (args == null) {
4242
result.error("No args", "Args is a null object.", "")
4343
} else {
44-
val windowTitle = args["windowTitle"] ?: ""
45-
val text = args["text"] ?: ""
46-
val alertStyle = args["alertStyle"] ?: "ok"
44+
val windowTitle = args.getOrDefault("windowTitle", "")
45+
val text = args.getOrDefault("text", "")
46+
val alertStyle = args.getOrDefault("alertStyle", "ok")
4747

4848
AlertDialog.Builder(
4949
this.activity,
50-
R.style.AlertDialogCustom
50+
getDialogStyle()
5151
).setTitle(windowTitle).setMessage(text).apply {
5252
when (alertStyle) {
5353
"abortRetryIgnore" ->
@@ -56,7 +56,7 @@ class FlutterPlatformAlertPlugin : FlutterPlugin, MethodCallHandler, ActivityAwa
5656
.setNegativeButton(R.string.abort) { _, _ -> result.success("abort") }
5757
"cancelTryContinue" ->
5858
setPositiveButton(R.string.try_again) { _, _ -> result.success("try_again") }
59-
.setNeutralButton(R.string.continue_button) { _, _ -> result.success("continue") }
59+
.setNeutralButton(R.string.continue_button) { _, _ -> result.success("continue" ) }
6060
.setNegativeButton(R.string.cancel) { _, _ -> result.success("cancel") }
6161
"okCancel" ->
6262
setPositiveButton(R.string.ok) { _, _ -> result.success("ok") }
@@ -81,16 +81,16 @@ class FlutterPlatformAlertPlugin : FlutterPlugin, MethodCallHandler, ActivityAwa
8181
if (args == null) {
8282
result.error("No args", "Args is a null object.", "")
8383
} else {
84-
val windowTitle = args["windowTitle"] ?: ""
85-
val text = args["text"] ?: ""
86-
val positiveButtonTitle = args["positiveButtonTitle"] ?: ""
87-
val negativeButtonTitle = args["negativeButtonTitle"] ?: ""
88-
val neutralButtonTitle = args["neutralButtonTitle"] ?: ""
89-
val base64Icon = args["base64Icon"] ?: ""
84+
val windowTitle = args.getOrDefault("windowTitle", "")
85+
val text = args.getOrDefault("text", "")
86+
val positiveButtonTitle = args.getOrDefault("positiveButtonTitle", "")
87+
val negativeButtonTitle = args.getOrDefault("negativeButtonTitle", "")
88+
val neutralButtonTitle = args.getOrDefault("neutralButtonTitle", "")
89+
val base64Icon = args.getOrDefault("base64Icon", "")
9090

9191
val builder = AlertDialog.Builder(
9292
this.activity,
93-
R.style.AlertDialogCustom
93+
getDialogStyle()
9494
).setTitle(windowTitle).setMessage(text)
9595
var buttonCount = 0
9696
if (positiveButtonTitle.isNotEmpty()) {
@@ -105,7 +105,7 @@ class FlutterPlatformAlertPlugin : FlutterPlugin, MethodCallHandler, ActivityAwa
105105
builder.setNeutralButton(neutralButtonTitle) { _, _ -> result.success("neutral_button") }
106106
buttonCount += 1
107107
}
108-
if (buttonCount==0) {
108+
if (buttonCount == 0) {
109109
builder.setPositiveButton("OK") { _, _ -> result.success("other") }
110110
buttonCount += 1
111111
}
@@ -123,14 +123,25 @@ class FlutterPlatformAlertPlugin : FlutterPlugin, MethodCallHandler, ActivityAwa
123123
else -> result.notImplemented()
124124
}
125125

126-
override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
126+
@RequiresApi(Build.VERSION_CODES.LOLLIPOP_MR1)
127+
private fun getDialogStyle(): Int {
128+
if (this.context != null) {
129+
val nightModeFlags: Int = this.context!!.resources.configuration.uiMode and
130+
Configuration.UI_MODE_NIGHT_MASK
131+
when (nightModeFlags) {
132+
Configuration.UI_MODE_NIGHT_NO -> return android.R.style.Theme_DeviceDefault_Light_Dialog_Alert
133+
}
134+
}
135+
return android.R.style.Theme_DeviceDefault_Dialog_Alert
136+
}
137+
138+
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
127139
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "flutter_platform_alert")
128140
channel.setMethodCallHandler(this)
129141
context = flutterPluginBinding.applicationContext
130142
}
131143

132-
133-
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
144+
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
134145
channel.setMethodCallHandler(null)
135146
context = null
136147
}

example/ios/Flutter/AppFrameworkInfo.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<key>CFBundleVersion</key>
2222
<string>1.0</string>
2323
<key>MinimumOSVersion</key>
24-
<string>9.0</string>
24+
<string>11.0</string>
2525
</dict>
2626
</plist>

example/ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Uncomment this line to define a global platform for your project
2-
# platform :ios, '9.0'
2+
# platform :ios, '11.0'
33

44
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
55
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

example/ios/Podfile.lock

Lines changed: 0 additions & 22 deletions
This file was deleted.

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 51;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -155,7 +155,7 @@
155155
97C146E61CF9000F007C117D /* Project object */ = {
156156
isa = PBXProject;
157157
attributes = {
158-
LastUpgradeCheck = 1300;
158+
LastUpgradeCheck = 1430;
159159
ORGANIZATIONNAME = "";
160160
TargetAttributes = {
161161
97C146ED1CF9000F007C117D = {
@@ -199,10 +199,12 @@
199199
/* Begin PBXShellScriptBuildPhase section */
200200
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
201201
isa = PBXShellScriptBuildPhase;
202+
alwaysOutOfDate = 1;
202203
buildActionMask = 2147483647;
203204
files = (
204205
);
205206
inputPaths = (
207+
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
206208
);
207209
name = "Thin Binary";
208210
outputPaths = (
@@ -230,6 +232,7 @@
230232
};
231233
9740EEB61CF901F6004384FC /* Run Script */ = {
232234
isa = PBXShellScriptBuildPhase;
235+
alwaysOutOfDate = 1;
233236
buildActionMask = 2147483647;
234237
files = (
235238
);
@@ -339,7 +342,7 @@
339342
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
340343
GCC_WARN_UNUSED_FUNCTION = YES;
341344
GCC_WARN_UNUSED_VARIABLE = YES;
342-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
345+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
343346
MTL_ENABLE_DEBUG_INFO = NO;
344347
SDKROOT = iphoneos;
345348
SUPPORTED_PLATFORMS = iphoneos;
@@ -417,7 +420,7 @@
417420
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
418421
GCC_WARN_UNUSED_FUNCTION = YES;
419422
GCC_WARN_UNUSED_VARIABLE = YES;
420-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
423+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
421424
MTL_ENABLE_DEBUG_INFO = YES;
422425
ONLY_ACTIVE_ARCH = YES;
423426
SDKROOT = iphoneos;
@@ -466,7 +469,7 @@
466469
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
467470
GCC_WARN_UNUSED_FUNCTION = YES;
468471
GCC_WARN_UNUSED_VARIABLE = YES;
469-
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
472+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
470473
MTL_ENABLE_DEBUG_INFO = NO;
471474
SDKROOT = iphoneos;
472475
SUPPORTED_PLATFORMS = iphoneos;

example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1300"
3+
LastUpgradeVersion = "1430"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

example/ios/Runner/Info.plist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,9 @@
4141
</array>
4242
<key>UIViewControllerBasedStatusBarAppearance</key>
4343
<false/>
44+
<key>CADisableMinimumFrameDurationOnPhone</key>
45+
<true/>
46+
<key>UIApplicationSupportsIndirectInputEvents</key>
47+
<true/>
4448
</dict>
4549
</plist>

0 commit comments

Comments
 (0)