From ec29c1a335f61aa94f4a0a7c18b0da8ce6bc5e8e Mon Sep 17 00:00:00 2001 From: Chip Weinberger Date: Thu, 18 Jan 2024 14:58:22 -0600 Subject: [PATCH] Revert "[Example] remove flutter_downloader due to out of date gradle kotlin plugin breaking build" This reverts commit 8b19773e1c34a032da6a6e66aaa0abe310eaeae0. --- example/lib/main.dart | 131 +++++++++++++++++++++--------------------- example/pubspec.yaml | 1 + 2 files changed, 66 insertions(+), 66 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index f40e599..b8326a0 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,25 +1,22 @@ import 'dart:async'; -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_isolate/flutter_isolate.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:flutter_downloader/flutter_downloader.dart'; @pragma('vm:entry-point') void isolate2(String arg) { - HttpClient? httpClient; - HttpClientRequest? request; - var url = Uri.parse('https://raw.githubusercontent.com/rmawatson/flutter_isolate/master/README.md'); - getTemporaryDirectory().then((dir) async { - print("isolate2 downloading $url"); - httpClient?.close(); - request?.close(); - httpClient = HttpClient(); - request = await httpClient!.getUrl(url); - print("downloaded the file."); - }).catchError((e) { - print(e); + print("isolate2 temporary directory: $dir"); + + await FlutterDownloader.initialize(debug: true); + FlutterDownloader.registerCallback(AppWidget.downloaderCallback); + + var url = 'https://raw.githubusercontent.com/rmawatson/flutter_isolate/master/README.md'; + + // ignore: unused_local_variable + final taskId = await FlutterDownloader.enqueue(url: url, savedDir: dir.path); }); Timer.periodic(Duration(seconds: 1), (timer) => print("Timer Running From Isolate 2")); } @@ -87,59 +84,61 @@ class AppWidget extends StatelessWidget { @override Widget build(BuildContext context) { return Center( - child: Column(crossAxisAlignment: CrossAxisAlignment.center, children: [ - Padding( - padding: const EdgeInsets.only(top: 30), - child: ElevatedButton( - child: Text('Spawn isolates'), - onPressed: _run, - ), - ), - Padding( - padding: const EdgeInsets.only(top: 30), - child: ElevatedButton( - child: Text('Check running isolates'), - onPressed: () async { - final isolates = await FlutterIsolate.runningIsolates; - await showDialog( - builder: (ctx) { - return Center( - child: Container( - color: Colors.white, - padding: EdgeInsets.all(5), - child: Column( - children: isolates.map((i) => Text(i)).cast().toList() + - [ - ElevatedButton( - child: Text("Close"), - onPressed: () { - Navigator.of(ctx).pop(); - }) - ]))); - }, - context: context); - }, - ), - ), - Padding( - padding: const EdgeInsets.only(top: 30), - child: ElevatedButton( - child: Text('Kill all running isolates'), - onPressed: () async { - await FlutterIsolate.killAll(); - }, - ), - ), - Padding( - padding: const EdgeInsets.only(top: 30), - child: ElevatedButton( - child: Text('Run in compute function'), - onPressed: () async { - await flutterCompute(computeFunction, "foo"); - }, - ), - ), - ]), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.only(top: 30), + child: ElevatedButton( + child: Text('Spawn isolates'), + onPressed: _run, + ), + ), + Padding( + padding: const EdgeInsets.only(top: 30), + child: ElevatedButton( + child: Text('Check running isolates'), + onPressed: () async { + final isolates = await FlutterIsolate.runningIsolates; + await showDialog( + builder: (ctx) { + return Center( + child: Container( + color: Colors.white, + padding: EdgeInsets.all(5), + child: Column( + children: isolates.map((i) => Text(i)).cast().toList() + + [ + ElevatedButton( + child: Text("Close"), + onPressed: () { + Navigator.of(ctx).pop(); + }) + ]))); + }, + context: context); + }, + ), + ), + Padding( + padding: const EdgeInsets.only(top: 30), + child: ElevatedButton( + child: Text('Kill all running isolates'), + onPressed: () async { + await FlutterIsolate.killAll(); + }, + ), + ), + Padding( + padding: const EdgeInsets.only(top: 30), + child: ElevatedButton( + child: Text('Run in compute function'), + onPressed: () async { + await flutterCompute(computeFunction, "foo"); + }, + ), + ), + ]), ); } } diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 2eaeda3..ee8ae1b 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: flutter_isolate: path: ../ path_provider: ^2.1.2 + flutter_downloader: ^1.11.6 dev_dependencies: flutter_test: