Skip to content

Commit

Permalink
Initialize() should not be called more than once
Browse files Browse the repository at this point in the history
Add an assert checking that `FlutterDownloader.initialize()` is not called more than once, because that may end up registering plugins multiple times and crashing the app.

Related to fluttercommunity#154.
  • Loading branch information
JonasVautherin authored Oct 30, 2019
1 parent bc425a0 commit da774e3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/src/downloader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class FlutterDownloader {
static bool _initialized = false;

static Future<Null> initialize() async {
assert(!_initialized, 'FlutterDownloader.initialize() must be called only once!');

final callback = PluginUtilities.getCallbackHandle(callbackDispatcher);
await _channel
.invokeMethod('initialize', <dynamic>[callback.toRawHandle()]);
Expand Down Expand Up @@ -385,4 +387,4 @@ class FlutterDownloader {
_channel.invokeMethod('registerCallback', <dynamic>[callbackHandle.toRawHandle()]);
}

}
}

0 comments on commit da774e3

Please sign in to comment.