Skip to content

Commit

Permalink
Reenable flutter_downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
dhzdhd committed Nov 12, 2023
1 parent 2551114 commit 42872e3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 42 deletions.
4 changes: 2 additions & 2 deletions lib/src/factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:io';
import 'package:dio/dio.dart';
import 'package:excode/src/settings/services/update_service.dart';
import 'package:flutter/foundation.dart';
// import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:fpdart/fpdart.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:package_info_plus/package_info_plus.dart';
Expand Down Expand Up @@ -40,7 +40,7 @@ Future<void> initPackageInfo() async {
}

Future<void> initDownloader() async {
// await FlutterDownloader.initialize(debug: true, ignoreSsl: true);
await FlutterDownloader.initialize(debug: true, ignoreSsl: true);
}

Future<void> initFileStorage() async {
Expand Down
77 changes: 38 additions & 39 deletions lib/src/settings/widgets/update_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'dart:isolate';
import 'dart:ui';

// import 'package:excode/src/settings/services/update_service.dart';
import 'package:excode/src/settings/services/update_service.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
// import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:flutter_downloader/flutter_downloader.dart';

class InfoDialogWidget extends StatefulWidget {
const InfoDialogWidget({Key? key, required this.isLatestVersion})
Expand All @@ -17,26 +17,26 @@ class InfoDialogWidget extends StatefulWidget {
}

class _InfoDialogWidgetState extends State<InfoDialogWidget> {
// final ReceivePort _port = ReceivePort();
// DownloadTaskStatus status = DownloadTaskStatus.undefined;
final ReceivePort _port = ReceivePort();
DownloadTaskStatus status = DownloadTaskStatus.undefined;
int progress = 0;
String id = '';

@override
void initState() {
super.initState();

// IsolateNameServer.registerPortWithName(
// _port.sendPort, 'downloader_send_port');
// _port.listen((dynamic data) {
// setState(() {
// id = data[0];
// status = data[1];
// progress = data[2];
// });
// });
IsolateNameServer.registerPortWithName(
_port.sendPort, 'downloader_send_port');
_port.listen((dynamic data) {
setState(() {
id = data[0];
status = data[1];
progress = data[2];
});
});

// FlutterDownloader.registerCallback(downloadCallback);
FlutterDownloader.registerCallback(downloadCallback);
}

@pragma('vm:entry-point')
Expand Down Expand Up @@ -67,31 +67,30 @@ class _InfoDialogWidgetState extends State<InfoDialogWidget> {
visible: !widget.isLatestVersion &&
(defaultTargetPlatform == TargetPlatform.android),
child: ElevatedButton(
onPressed: () async {
// await FlutterDownloader.enqueue(
// url: UpdateService.latestVersionUrl,
// headers: {},
// savedDir: '/storage/emulated/0/Download',
// showNotification: true,
// openFileFromNotification: true,
// saveInPublicStorage: true,
// );
},
child:
// (status == DownloadTaskStatus.running)
TweenAnimationBuilder<double>(
tween: Tween(begin: 0, end: progress.toDouble()),
duration: const Duration(milliseconds: 500),
builder: (context, value, child) {
return SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator.adaptive(value: value),
);
},
)
// : const Text('Update'),
),
onPressed: () async {
await FlutterDownloader.enqueue(
url: UpdateService.latestVersionUrl,
headers: {},
savedDir: '/storage/emulated/0/Download',
showNotification: true,
openFileFromNotification: true,
saveInPublicStorage: true,
);
},
child: (status == DownloadTaskStatus.running)
? TweenAnimationBuilder<double>(
tween: Tween(begin: 0, end: progress.toDouble()),
duration: const Duration(milliseconds: 500),
builder: (context, value, child) {
return SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator.adaptive(value: value),
);
},
)
: const Text('Update'),
),
),
],
);
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,14 @@ packages:
url: "https://github.com/dhzdhd/flutter-code-editor-package.git"
source: git
version: "0.2.23"
flutter_downloader:
dependency: "direct main"
description:
name: flutter_downloader
sha256: "4a03c705dc60b4f537796da937c80fd5bff63b175f4dd99e1539ab3ad5dbeda0"
url: "https://pub.dev"
source: hosted
version: "1.11.4"
flutter_highlight:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies:
fpdart: ^0.6.0
supabase_flutter: ^1.9.0
desktop_drop: ^0.4.1
# flutter_downloader: ^1.11.4
flutter_downloader: ^1.11.4
flutter_svg: ^2.0.5
leak_tracker: ^5.0.0
sentry_flutter: ^7.5.2
Expand Down

0 comments on commit 42872e3

Please sign in to comment.