Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up API #283

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b172f60
clean up api
MarcelGarus Mar 3, 2020
a623ed1
fully implement new api
MarcelGarus Mar 7, 2020
0837dbb
add wait method to DownloadTask
MarcelGarus Mar 11, 2020
6d6d924
fix download
MarcelGarus Mar 11, 2020
4d4e356
cast objects explicitly
MarcelGarus Apr 24, 2020
2dda9e0
minor fixes
MarcelGarus Apr 24, 2020
87dfd6f
add quotes for more solid sql lookup
MarcelGarus Apr 24, 2020
4a2f00e
add doc comment to progress
MarcelGarus Apr 24, 2020
584efe0
make destination changeable
MarcelGarus Apr 24, 2020
cf0fe8c
fix update method call
MarcelGarus Apr 24, 2020
e7fbdad
make resume still update the existing DownloadTask
MarcelGarus Apr 24, 2020
167eb68
make retry still update the existing DownloadTask
MarcelGarus Apr 24, 2020
0deb3a5
fix calls to resume and retry
MarcelGarus Apr 24, 2020
792fd7f
flesh out example
MarcelGarus Apr 24, 2020
26853ed
update readme
MarcelGarus Apr 25, 2020
68f5a3e
bump packge version
MarcelGarus Apr 25, 2020
85e0e87
update changelog
MarcelGarus Apr 25, 2020
e9c5f13
Merge remote-tracking branch 'upstream/master'
MarcelGarus Apr 25, 2020
1a0adf4
add timeCreated field to DownloadTask
MarcelGarus Apr 25, 2020
20f5a96
revise changelog
MarcelGarus Apr 25, 2020
765ae86
remove deprecated authors section from pubspec
MarcelGarus Apr 25, 2020
56e062d
show previous tasks when re-launching the app
MarcelGarus May 6, 2020
5253e85
choose random URL
MarcelGarus May 6, 2020
fc75c4c
make timeCreated into DateTime and rename it to created
MarcelGarus May 11, 2020
307bcfc
update example
MarcelGarus May 11, 2020
a9b4cbd
Override dartx version
MarcelGarus Jun 11, 2020
af121e3
Update black_hole_flutter package
MarcelGarus Jul 30, 2020
def7f37
Restructure example
MarcelGarus Aug 28, 2020
62651ed
Merge remote-tracking branch 'upstream/master'
MarcelGarus Aug 28, 2020
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
2 changes: 1 addition & 1 deletion example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"flutter_downloader","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"permission_handler","dependencies":[]}]}
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"flutter_downloader","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"permission_handler","dependencies":[]}]}
11 changes: 5 additions & 6 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/hunghd/Documents/Workspace/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/hunghd/Documents/Workspace/flutter_packages/flutter_downloader/example"
export "FLUTTER_TARGET=/Users/hunghd/Documents/Workspace/flutter_packages/flutter_downloader/example/lib/main.dart"
export "FLUTTER_ROOT=C:\src\flutter"
export "FLUTTER_APPLICATION_PATH=C:\projects\flutter_downloader\example"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_FRAMEWORK_DIR=/Users/hunghd/Documents/Workspace/flutter/bin/cache/artifacts/engine/ios"
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "FLUTTER_FRAMEWORK_DIR=C:\src\flutter\bin\cache\artifacts\engine\ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "TRACK_WIDGET_CREATION=true"
23 changes: 9 additions & 14 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import 'package:permission_handler/permission_handler.dart';
import 'dart:io';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await FlutterDownloader.initialize();

runApp(new MyApp());
runApp(MyApp());
}

class MyApp extends StatelessWidget {
Expand All @@ -22,9 +20,7 @@ class MyApp extends StatelessWidget {

return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
theme: new ThemeData(primarySwatch: Colors.blue),
home: new MyHomePage(
title: 'Downloader',
platform: platform,
Expand Down Expand Up @@ -400,30 +396,29 @@ class _MyHomePageState extends State<MyHomePage> {
}

void _cancelDownload(_TaskInfo task) async {
await FlutterDownloader.cancel(taskId: task.taskId);
await FlutterDownloader.cancel(id: task.taskId);
}

void _pauseDownload(_TaskInfo task) async {
await FlutterDownloader.pause(taskId: task.taskId);
await FlutterDownloader.pause(id: task.taskId);
}

void _resumeDownload(_TaskInfo task) async {
String newTaskId = await FlutterDownloader.resume(taskId: task.taskId);
String newTaskId = await FlutterDownloader.resume(id: task.taskId);
task.taskId = newTaskId;
}

void _retryDownload(_TaskInfo task) async {
String newTaskId = await FlutterDownloader.retry(taskId: task.taskId);
String newTaskId = await FlutterDownloader.retry(id: task.taskId);
task.taskId = newTaskId;
}

Future<bool> _openDownloadedFile(_TaskInfo task) {
return FlutterDownloader.open(taskId: task.taskId);
return FlutterDownloader.open(id: task.taskId);
}

void _delete(_TaskInfo task) async {
await FlutterDownloader.remove(
taskId: task.taskId, shouldDeleteContent: true);
await FlutterDownloader.remove(id: task.taskId, shouldDeleteContent: true);
await _prepare();
setState(() {});
}
Expand Down Expand Up @@ -485,7 +480,7 @@ class _MyHomePageState extends State<MyHomePage> {
tasks?.forEach((task) {
for (_TaskInfo info in _tasks) {
if (info.link == task.url) {
info.taskId = task.taskId;
info.taskId = task.id;
info.status = task.status;
info.progress = task.progress;
}
Expand Down
2 changes: 0 additions & 2 deletions lib/flutter_downloader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
/// All task information is saved in a Sqlite database, it gives a Flutter
/// application benefit of either getting rid of managing task information
/// manually or querying task data with SQL statements easily.
///

library flutter_downloader;

export 'src/downloader.dart';
export 'src/models.dart';
38 changes: 28 additions & 10 deletions lib/src/callback_dispatcher.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import 'dart:ui';
part of 'downloader.dart';

import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';

import 'models.dart';

void callbackDispatcher() {
const MethodChannel backgroundChannel =
MethodChannel('vn.hunghd/downloader_background');
void dispatchCallback() {
const backgroundChannel = MethodChannel('vn.hunghd/downloader_background');

WidgetsFlutterBinding.ensureInitialized();

Expand All @@ -21,8 +15,32 @@ void callbackDispatcher() {
final int status = args[2];
final int progress = args[3];

callback(id, DownloadTaskStatus(status), progress);
// TODO: handle callback
// callback(id, DownloadTaskStatus(status), progress);
});

backgroundChannel.invokeMethod('didInitializeDispatcher');
}

// ReceivePort _port = ReceivePort();
///
/// @override
/// void initState() {
/// super.initState();
///
/// IsolateNameServer.registerPortWithName(_port.sendPort, 'downloader_send_port');
/// _port.listen((dynamic data) {
/// String id = data[0];
/// DownloadTaskStatus status = data[1];
/// int progress = data[2];
/// setState((){ });
/// });
///
/// FlutterDownloader.registerCallback(downloadCallback);
///
/// }
///
/// static void downloadCallback(String id, DownloadTaskStatus status, int progress) {
/// final SendPort send = IsolateNameServer.lookupPortByName('downloader_send_port');
/// send.send([id, status, progress]);
/// }
Loading