-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work lista: animationAnimation APIsAnimation APIscustomer: money (g3)found in release: 3.19Found to occur in 3.19Found to occur in 3.19found in release: 3.21Found to occur in 3.21Found to occur in 3.21frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
I found SchedulerBinding.instance.scheduleTask can be stucked in a specific scene.
Here is my example code
const tag = "ScheduleTest";
class ScheduleTestPage1 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Container(
width: 50,
height: 50,
child: CircularProgressIndicator(),
),
),
FlatButton(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(builder: (context) {
return ScheduleTestPage2();
})).then((value) {
SchedulerBinding.instance.scheduleTask(() {
print("$tag>>>>>>scheduleTask1");
}, Priority.touch);
Future.delayed(Duration(seconds: 1), () {
SchedulerBinding.instance.scheduleTask(() {
print("$tag>>>>>>scheduleTask2");
}, Priority.touch);
});
});
},
child: Text("click me "))
],
),
);
}
}
class ScheduleTestPage2 extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _ScheduleTest2State();
}
}
class _ScheduleTest2State extends State<ScheduleTestPage2> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
width: 100,
height: 50,
child: FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text("Back"),
),
),
),
);
}
@override
void dispose() {
super.dispose();
SchedulerBinding.instance.scheduleTask(() {
print("$tag>>>>>> call ScheduleTestPage2 dispose");
// do something such as Exception . throw Exception("Exception Test");
}, Priority.idle);
}
}
After debug the SchedulerBinding, I found the task was not been executed because of these code.
flutter/packages/flutter/lib/src/scheduler/binding.dart
Lines 1173 to 1177 in 80f15dc
| bool defaultSchedulingStrategy({ required int priority, required SchedulerBinding scheduler }) { | |
| if (scheduler.transientCallbackCount > 0) | |
| return priority >= Priority.animation.value; | |
| return true; | |
| } |
The transientCallbackCount will be increased by Ticker in SingleTickerProviderStateMixin.didChangeDependencies
flutter/packages/flutter/lib/src/scheduler/ticker.dart
Lines 90 to 99 in 80f15dc
| set muted(bool value) { | |
| if (value == muted) | |
| return; | |
| _muted = value; | |
| if (value) { | |
| unscheduleTick(); | |
| } else if (shouldScheduleTick) { | |
| scheduleTick(); | |
| } | |
| } |
I draw a timeline might explain the issue.

Because of _taskQueue.isEmpty is not true, so the remain task will not have chance to be executed :(
jeiea, SixSheeppp, shashikantleher, noinskit, Matthiee and 1 more
Metadata
Metadata
Assignees
Labels
P1High-priority issues at the top of the work listHigh-priority issues at the top of the work lista: animationAnimation APIsAnimation APIscustomer: money (g3)found in release: 3.19Found to occur in 3.19Found to occur in 3.19found in release: 3.21Found to occur in 3.21Found to occur in 3.21frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
