Skip to content

Commit

Permalink
getPlatformVersion changed to reuse 3rd party plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelsetragni committed Dec 6, 2021
1 parent db5bb9d commit 818263e
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 27 deletions.
21 changes: 6 additions & 15 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,6 @@ public void onMethodCall(@NonNull final MethodCall call, @NonNull final Result r
channelMethodGetDrawableData(call, result);
return;

case Definitions.CHANNEL_METHOD_GET_PLATFORM_VERSION:
channelMethodGetPlatformVersion(call, result);
return;

case Definitions.CHANNEL_METHOD_ENABLE_WAKELOCK:
channelMethodGetPlatformVersion(call, result);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public interface Definitions {

String CHANNEL_METHOD_INITIALIZE = "initialize";
String CHANNEL_METHOD_GET_DRAWABLE_DATA = "getDrawableData";
String CHANNEL_METHOD_GET_PLATFORM_VERSION = "getPlatformVersion";
String CHANNEL_METHOD_ENABLE_WAKELOCK = "enableWakelock";
String CHANNEL_METHOD_CREATE_NOTIFICATION = "createNewNotification";

Expand Down
18 changes: 18 additions & 0 deletions example/lib/utils/common_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;

import 'package:flutter/material.dart';
import 'package:device_info/device_info.dart';
import 'package:path_provider/path_provider.dart';

Future<String> saveAssetOnDisk(ImageProvider image, String fileName) async {
Expand Down Expand Up @@ -38,6 +39,23 @@ void unlockScreenPortrait(){
]);
}

Future<String> getPlatformVersion() async {
if (Platform.isAndroid) {
var androidInfo = await DeviceInfoPlugin().androidInfo;
var sdkInt = androidInfo.version.sdkInt;
return 'Android-$sdkInt';
}

if (Platform.isIOS) {
var iosInfo = await DeviceInfoPlugin().iosInfo;
var systemName = iosInfo.systemName;
var version = iosInfo.systemVersion;
return '$systemName-$version';
}

return 'unknow';
}

String printDuration(Duration? duration) {
if (duration == null) return '00:00';
String twoDigits(int n) => n.toString().padLeft(2, "0");
Expand Down
4 changes: 3 additions & 1 deletion example/lib/utils/notification_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ class NotificationUtils {
************************************************ */

static Future<void> showCallNotification(int id) async {
String platformVersion = await getPlatformVersion();
AndroidForegroundService.startForeground(
//await AwesomeNotifications().createNotification(
content: NotificationContent(
Expand All @@ -505,7 +506,8 @@ class NotificationUtils {
wakeUpScreen: true,
fullScreenIntent: true,
autoDismissible: false,
backgroundColor: (AwesomeNotifications.platformVersion == 'Android-31') ? Color(0x00796a) : Colors.white,
backgroundColor: (platformVersion == 'Android-31') ?
Color(0x00796a) : Colors.white,
payload: {
'username': 'Little Mary'
}
Expand Down
14 changes: 14 additions & 0 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
device_info:
dependency: "direct main"
description:
name: device_info
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.3"
device_info_platform_interface:
dependency: transitive
description:
name: device_info_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
fake_async:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ dependencies:
giffy_dialog: ^1.8.0
vibration: ^1.7.4-nullsafety.0

device_info: ^2.0.3

url_launcher: ^6.0.3

intl: ^0.17.0
Expand Down
7 changes: 1 addition & 6 deletions lib/src/awesome_notifications_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ class AwesomeNotifications {

static String
_utcTimeZoneIdentifier = 'UTC',
_localTimeZoneIdentifier = 'UTC',
_platformVersion = 'unknow';
_localTimeZoneIdentifier = 'UTC';

static String get utcTimeZoneIdentifier => _utcTimeZoneIdentifier;
static String get localTimeZoneIdentifier => _localTimeZoneIdentifier;
static String get platformVersion => _platformVersion;

/// WEB SUPPORT METHODS *********************************************
/*
Expand Down Expand Up @@ -187,9 +185,6 @@ class AwesomeNotifications {
_utcTimeZoneIdentifier =
await _channel.invokeMethod(CHANNEL_METHOD_GET_UTC_TIMEZONE_IDENTIFIER);

_platformVersion = await _channel
.invokeMethod(CHANNEL_METHOD_GET_PLATFORM_VERSION);

return result;
}

Expand Down

0 comments on commit 818263e

Please sign in to comment.