@@ -38,7 +38,7 @@ class _DemoPageState extends State<DemoPage> {
3838 Task .simultaneousA: Status .stopped,
3939 Task .simultaneousB: Status .stopped,
4040 Task .simultaneousC: Status .stopped,
41- Task .compute : Status .stopped,
41+ Task .isolate : Status .stopped,
4242 };
4343 CancellationToken ? _cancellationToken;
4444
@@ -75,15 +75,14 @@ class _DemoPageState extends State<DemoPage> {
7575 setState (() => _tasks[Task .simultaneousC] = Status .complete)),
7676 ]);
7777
78- // To run a function in a cancellable isolate, use cancellableCompute in
79- // place of the Flutter's compute function
80- setState (() => _tasks[Task .compute] = Status .running);
81- await cancellableCompute (
82- delayedIsolateFunction,
83- const Duration (seconds: 2 ),
78+ // To run a function in a cancellable isolate, use CancellableIsolate.run
79+ // or cancellableCompute
80+ setState (() => _tasks[Task .isolate] = Status .running);
81+ await CancellableIsolate .run (
82+ () => delayedIsolateFunction (const Duration (seconds: 2 )),
8483 _cancellationToken,
8584 );
86- setState (() => _tasks[Task .compute ] = Status .complete);
85+ setState (() => _tasks[Task .isolate ] = Status .complete);
8786 } on CancelledException {
8887 // In some cases, like when cancelling tasks because in a widget's
8988 // dispose method, you'll want to catch the CancellationException but
@@ -140,8 +139,8 @@ class _DemoPageState extends State<DemoPage> {
140139 status: _tasks[Task .simultaneousC]! ,
141140 ),
142141 TaskStatusDisplay (
143- label: 'Compute status' ,
144- status: _tasks[Task .compute ]! ,
142+ label: 'Isolate status' ,
143+ status: _tasks[Task .isolate ]! ,
145144 ),
146145 const SizedBox (height: 16.0 ),
147146 ElevatedButton (
@@ -170,8 +169,7 @@ Future<void> delayedFuture() async {
170169/// A simple function for testing isolates.
171170///
172171/// If you cancel running tasks whilst this isolate is sleeping, the isolate
173- /// will be killed and you'll only see the 'Isolate started' message in the
174- /// console.
172+ /// will be killed and you'll only see the 'Isolate started' message in the log.
175173void delayedIsolateFunction (Duration delay) {
176174 if (kDebugMode) print ('Isolate started - Waiting ${delay .inSeconds } seconds' );
177175 sleep (delay);
0 commit comments