Skip to content

Commit

Permalink
format codes
Browse files Browse the repository at this point in the history
  • Loading branch information
hnvn committed Jan 12, 2020
1 parent 2af60a8 commit 7f8b72e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class _MyHomePageState extends State<MyHomePage> {
}

@override
void dispose(){
void dispose() {
_unbindBackgroundIsolate();
super.dispose();
}
Expand Down
1 change: 0 additions & 1 deletion lib/flutter_downloader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ library flutter_downloader;

export 'src/downloader.dart';
export 'src/models.dart';

49 changes: 26 additions & 23 deletions lib/src/downloader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import 'models.dart';
/// * `progress`: current progress value of a download task, the value is in
/// range of 0 and 100
///
typedef void DownloadCallback(String id, DownloadTaskStatus status, int progress);
typedef void DownloadCallback(
String id, DownloadTaskStatus status, int progress);

///
/// A convenient class wraps all api functions of **FlutterDownloader** plugin
Expand All @@ -26,7 +27,8 @@ class FlutterDownloader {
static bool _initialized = false;

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

WidgetsFlutterBinding.ensureInitialized();

Expand Down Expand Up @@ -62,12 +64,12 @@ class FlutterDownloader {
///
static Future<String> enqueue(
{@required String url,
@required String savedDir,
String fileName,
Map<String, String> headers,
bool showNotification = true,
bool openFileFromNotification = true,
bool requiresStorageNotLow = true}) async {
@required String savedDir,
String fileName,
Map<String, String> headers,
bool showNotification = true,
bool openFileFromNotification = true,
bool requiresStorageNotLow = true}) async {
assert(_initialized, 'FlutterDownloader.initialize() must be called first');
assert(Directory(savedDir).existsSync());

Expand Down Expand Up @@ -112,12 +114,12 @@ class FlutterDownloader {
List<dynamic> result = await _channel.invokeMethod('loadTasks');
return result
.map((item) => new DownloadTask(
taskId: item['task_id'],
status: DownloadTaskStatus(item['status']),
progress: item['progress'],
url: item['url'],
filename: item['file_name'],
savedDir: item['saved_dir']))
taskId: item['task_id'],
status: DownloadTaskStatus(item['status']),
progress: item['progress'],
url: item['url'],
filename: item['file_name'],
savedDir: item['saved_dir']))
.toList();
} on PlatformException catch (e) {
print(e.message);
Expand Down Expand Up @@ -155,12 +157,12 @@ class FlutterDownloader {
print('Loaded tasks: $result');
return result
.map((item) => new DownloadTask(
taskId: item['task_id'],
status: DownloadTaskStatus(item['status']),
progress: item['progress'],
url: item['url'],
filename: item['file_name'],
savedDir: item['saved_dir']))
taskId: item['task_id'],
status: DownloadTaskStatus(item['status']),
progress: item['progress'],
url: item['url'],
filename: item['file_name'],
savedDir: item['saved_dir']))
.toList();
} on PlatformException catch (e) {
print(e.message);
Expand Down Expand Up @@ -385,8 +387,9 @@ class FlutterDownloader {
assert(_initialized, 'FlutterDownloader.initialize() must be called first');

final callbackHandle = PluginUtilities.getCallbackHandle(callback);
assert(callbackHandle != null, 'callback must be a top-level or a static function');
_channel.invokeMethod('registerCallback', <dynamic>[callbackHandle.toRawHandle()]);
assert(callbackHandle != null,
'callback must be a top-level or a static function');
_channel.invokeMethod(
'registerCallback', <dynamic>[callbackHandle.toRawHandle()]);
}

}
18 changes: 8 additions & 10 deletions lib/src/models.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

///
/// A class defines a set of possible statuses of a download task
///
class DownloadTaskStatus {
final int _value;

const DownloadTaskStatus(int value): _value = value;
const DownloadTaskStatus(int value) : _value = value;

int get value => _value;

Expand All @@ -15,8 +14,7 @@ class DownloadTaskStatus {

toString() => 'DownloadTaskStatus($_value)';

static DownloadTaskStatus from(int value) =>
DownloadTaskStatus(value);
static DownloadTaskStatus from(int value) => DownloadTaskStatus(value);

static const undefined = const DownloadTaskStatus(0);
static const enqueued = const DownloadTaskStatus(1);
Expand Down Expand Up @@ -48,13 +46,13 @@ class DownloadTask {

DownloadTask(
{this.taskId,
this.status,
this.progress,
this.url,
this.filename,
this.savedDir});
this.status,
this.progress,
this.url,
this.filename,
this.savedDir});

@override
String toString() =>
"DownloadTask(taskId: $taskId, status: $status, progress: $progress, url: $url, filename: $filename, savedDir: $savedDir)";
}
}

0 comments on commit 7f8b72e

Please sign in to comment.