Skip to content

Commit ec29c1a

Browse files
Revert "[Example] remove flutter_downloader due to out of date gradle kotlin plugin breaking build"
This reverts commit 8b19773.
1 parent 4fa6870 commit ec29c1a

File tree

2 files changed

+66
-66
lines changed

2 files changed

+66
-66
lines changed

example/lib/main.dart

+65-66
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
import 'dart:async';
2-
import 'dart:io';
32

43
import 'package:flutter/material.dart';
54
import 'package:flutter_isolate/flutter_isolate.dart';
65
import 'package:path_provider/path_provider.dart';
6+
import 'package:flutter_downloader/flutter_downloader.dart';
77

88
@pragma('vm:entry-point')
99
void isolate2(String arg) {
10-
HttpClient? httpClient;
11-
HttpClientRequest? request;
12-
var url = Uri.parse('https://raw.githubusercontent.com/rmawatson/flutter_isolate/master/README.md');
13-
1410
getTemporaryDirectory().then((dir) async {
15-
print("isolate2 downloading $url");
16-
httpClient?.close();
17-
request?.close();
18-
httpClient = HttpClient();
19-
request = await httpClient!.getUrl(url);
20-
print("downloaded the file.");
21-
}).catchError((e) {
22-
print(e);
11+
print("isolate2 temporary directory: $dir");
12+
13+
await FlutterDownloader.initialize(debug: true);
14+
FlutterDownloader.registerCallback(AppWidget.downloaderCallback);
15+
16+
var url = 'https://raw.githubusercontent.com/rmawatson/flutter_isolate/master/README.md';
17+
18+
// ignore: unused_local_variable
19+
final taskId = await FlutterDownloader.enqueue(url: url, savedDir: dir.path);
2320
});
2421
Timer.periodic(Duration(seconds: 1), (timer) => print("Timer Running From Isolate 2"));
2522
}
@@ -87,59 +84,61 @@ class AppWidget extends StatelessWidget {
8784
@override
8885
Widget build(BuildContext context) {
8986
return Center(
90-
child: Column(crossAxisAlignment: CrossAxisAlignment.center, children: [
91-
Padding(
92-
padding: const EdgeInsets.only(top: 30),
93-
child: ElevatedButton(
94-
child: Text('Spawn isolates'),
95-
onPressed: _run,
96-
),
97-
),
98-
Padding(
99-
padding: const EdgeInsets.only(top: 30),
100-
child: ElevatedButton(
101-
child: Text('Check running isolates'),
102-
onPressed: () async {
103-
final isolates = await FlutterIsolate.runningIsolates;
104-
await showDialog(
105-
builder: (ctx) {
106-
return Center(
107-
child: Container(
108-
color: Colors.white,
109-
padding: EdgeInsets.all(5),
110-
child: Column(
111-
children: isolates.map((i) => Text(i)).cast<Widget>().toList() +
112-
[
113-
ElevatedButton(
114-
child: Text("Close"),
115-
onPressed: () {
116-
Navigator.of(ctx).pop();
117-
})
118-
])));
119-
},
120-
context: context);
121-
},
122-
),
123-
),
124-
Padding(
125-
padding: const EdgeInsets.only(top: 30),
126-
child: ElevatedButton(
127-
child: Text('Kill all running isolates'),
128-
onPressed: () async {
129-
await FlutterIsolate.killAll();
130-
},
131-
),
132-
),
133-
Padding(
134-
padding: const EdgeInsets.only(top: 30),
135-
child: ElevatedButton(
136-
child: Text('Run in compute function'),
137-
onPressed: () async {
138-
await flutterCompute(computeFunction, "foo");
139-
},
140-
),
141-
),
142-
]),
87+
child: Column(
88+
crossAxisAlignment: CrossAxisAlignment.center,
89+
children: [
90+
Padding(
91+
padding: const EdgeInsets.only(top: 30),
92+
child: ElevatedButton(
93+
child: Text('Spawn isolates'),
94+
onPressed: _run,
95+
),
96+
),
97+
Padding(
98+
padding: const EdgeInsets.only(top: 30),
99+
child: ElevatedButton(
100+
child: Text('Check running isolates'),
101+
onPressed: () async {
102+
final isolates = await FlutterIsolate.runningIsolates;
103+
await showDialog(
104+
builder: (ctx) {
105+
return Center(
106+
child: Container(
107+
color: Colors.white,
108+
padding: EdgeInsets.all(5),
109+
child: Column(
110+
children: isolates.map((i) => Text(i)).cast<Widget>().toList() +
111+
[
112+
ElevatedButton(
113+
child: Text("Close"),
114+
onPressed: () {
115+
Navigator.of(ctx).pop();
116+
})
117+
])));
118+
},
119+
context: context);
120+
},
121+
),
122+
),
123+
Padding(
124+
padding: const EdgeInsets.only(top: 30),
125+
child: ElevatedButton(
126+
child: Text('Kill all running isolates'),
127+
onPressed: () async {
128+
await FlutterIsolate.killAll();
129+
},
130+
),
131+
),
132+
Padding(
133+
padding: const EdgeInsets.only(top: 30),
134+
child: ElevatedButton(
135+
child: Text('Run in compute function'),
136+
onPressed: () async {
137+
await flutterCompute(computeFunction, "foo");
138+
},
139+
),
140+
),
141+
]),
143142
);
144143
}
145144
}

example/pubspec.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies:
1111
flutter_isolate:
1212
path: ../
1313
path_provider: ^2.1.2
14+
flutter_downloader: ^1.11.6
1415

1516
dev_dependencies:
1617
flutter_test:

0 commit comments

Comments
 (0)