Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/android_alarm_manager/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.0-null-safety

* Migrate to null safety.

## 0.4.5+20

* Update the example app: remove the deprecated `RaisedButton` and `FlatButton` widgets.
Expand Down
20 changes: 10 additions & 10 deletions packages/android_alarm_manager/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const String isolateName = 'isolate';
final ReceivePort port = ReceivePort();

/// Global [SharedPreferences] object.
SharedPreferences prefs;
SharedPreferences? prefs;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this isn't late?


Future<void> main() async {
// TODO(bkonyi): uncomment
Expand All @@ -35,8 +35,8 @@ Future<void> main() async {
isolateName,
);
prefs = await SharedPreferences.getInstance();
if (!prefs.containsKey(countKey)) {
await prefs.setInt(countKey, 0);
if (!prefs!.containsKey(countKey)) {
await prefs!.setInt(countKey, 0);
}
runApp(AlarmManagerExampleApp());
}
Expand All @@ -54,8 +54,8 @@ class AlarmManagerExampleApp extends StatelessWidget {
}

class _AlarmHomePage extends StatefulWidget {
_AlarmHomePage({Key key, this.title}) : super(key: key);
final String title;
_AlarmHomePage({Key? key, this.title}) : super(key: key);
final String? title;

@override
_AlarmHomePageState createState() => _AlarmHomePageState();
Expand All @@ -78,15 +78,15 @@ class _AlarmHomePageState extends State<_AlarmHomePage> {
print('Increment counter!');

// Ensure we've loaded the updated count from the background isolate.
await prefs.reload();
await prefs!.reload();

setState(() {
_counter++;
});
}

// The background
static SendPort uiSendPort;
static SendPort? uiSendPort;

// The callback for our alarm
static Future<void> callback() async {
Expand All @@ -107,7 +107,7 @@ class _AlarmHomePageState extends State<_AlarmHomePage> {
final textStyle = Theme.of(context).textTheme.headline4;
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
title: Text(widget.title!),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unsafe; you can't assert the existence of field that was declared as nullable.

),
body: Center(
child: Column(
Expand All @@ -125,7 +125,7 @@ class _AlarmHomePageState extends State<_AlarmHomePage> {
style: textStyle,
),
Text(
prefs.getInt(countKey).toString(),
prefs!.getInt(countKey).toString(),
key: ValueKey('BackgroundCountText'),
style: textStyle,
),
Expand All @@ -140,7 +140,7 @@ class _AlarmHomePageState extends State<_AlarmHomePage> {
await AndroidAlarmManager.oneShot(
const Duration(seconds: 5),
// Ensure we have a unique alarm ID.
Random().nextInt(pow(2, 31)),
Random().nextInt(pow(2, 31).toInt()),
callback,
exact: true,
wakeup: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/android_alarm_manager/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ flutter:
uses-material-design: true

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: '>=2.12.0-0 <3.0.0'
flutter: ">=1.12.13+hotfix.5 <2.0.0"
16 changes: 8 additions & 8 deletions packages/android_alarm_manager/lib/android_alarm_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void _alarmManagerCallbackDispatcher() {

// PluginUtilities.getCallbackFromHandle performs a lookup based on the
// callback handle and returns a tear-off of the original callback.
final Function closure = PluginUtilities.getCallbackFromHandle(handle);
final Function? closure = PluginUtilities.getCallbackFromHandle(handle);

if (closure == null) {
print('Fatal: could not find callback');
Expand Down Expand Up @@ -71,13 +71,13 @@ class AndroidAlarmManager {
// Callback used to get the handle for a callback. It's
// [PluginUtilities.getCallbackHandle] by default.
static _GetCallbackHandle _getCallbackHandle =
(Function callback) => PluginUtilities.getCallbackHandle(callback);
(Function callback) => PluginUtilities.getCallbackHandle(callback)!;

/// This is exposed for the unit tests. It should not be accessed by users of
/// the plugin.
@visibleForTesting
static void setTestOverides(
{_Now now, _GetCallbackHandle getCallbackHandle}) {
{_Now? now, _GetCallbackHandle? getCallbackHandle}) {
_now = (now ?? _now);
_getCallbackHandle = (getCallbackHandle ?? _getCallbackHandle);
}
Expand All @@ -93,7 +93,7 @@ class AndroidAlarmManager {
if (handle == null) {
return false;
}
final bool r = await _channel.invokeMethod<bool>(
final bool? r = await _channel.invokeMethod<bool>(
'AlarmService.start', <dynamic>[handle.toRawHandle()]);
return r ?? false;
}
Expand Down Expand Up @@ -211,7 +211,7 @@ class AndroidAlarmManager {
if (handle == null) {
return false;
}
final bool r =
final bool? r =
await _channel.invokeMethod<bool>('Alarm.oneShotAt', <dynamic>[
id,
alarmClock,
Expand Down Expand Up @@ -262,7 +262,7 @@ class AndroidAlarmManager {
Duration duration,
int id,
Function callback, {
DateTime startAt,
DateTime? startAt,
bool exact = false,
bool wakeup = false,
bool rescheduleOnReboot = false,
Expand All @@ -278,7 +278,7 @@ class AndroidAlarmManager {
if (handle == null) {
return false;
}
final bool r = await _channel.invokeMethod<bool>(
final bool? r = await _channel.invokeMethod<bool>(
'Alarm.periodic', <dynamic>[
id,
exact,
Expand All @@ -299,7 +299,7 @@ class AndroidAlarmManager {
/// Returns a [Future] that resolves to `true` on success and `false` on
/// failure.
static Future<bool> cancel(int id) async {
final bool r =
final bool? r =
await _channel.invokeMethod<bool>('Alarm.cancel', <dynamic>[id]);
return (r == null) ? false : r;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/android_alarm_manager/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Flutter plugin for accessing the Android AlarmManager service, and
# 0.4.y+z is compatible with 1.0.0, if you land a breaking change bump
# the version to 2.0.0.
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
version: 0.4.5+20
version: 0.5.0-null-safety
homepage: https://github.com/flutter/plugins/tree/master/packages/android_alarm_manager

dependencies:
Expand All @@ -24,5 +24,5 @@ flutter:
pluginClass: AndroidAlarmManagerPlugin

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: '>=2.12.0-0 <3.0.0'
flutter: ">=1.12.13+hotfix.5"