我有一个Timer,它有一个围绕它的小动画。从另一个路由调用Timer以启动(ExamTimer(size: 40.0),
(。当我导航到另一条路线时,我会收到以下错误:
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown while finalizing the widget tree:
ExamTimerState#c1b45(tickers: tracking 1 ticker) was disposed with an active Ticker.
ExamTimerState created a Ticker via its TickerProviderStateMixin, but at the time dispose() was called on the mixin, that Ticker was still active. All Tickers must be disposed before calling super.dispose().
Tickers used by AnimationControllers should be disposed by calling dispose() on the AnimationController itself. Otherwise, the ticker will leak.
The offending ticker was: _WidgetTicker(created by ExamTimerState#c1b45(lifecycle state: created, tickers: tracking 0 tickers))
The stack trace when the _WidgetTicker was actually created was:
#0 new Ticker.<anonymous closure> (package:flutter/src/scheduler/ticker.dart:66:40)
#1 new Ticker (package:flutter/src/scheduler/ticker.dart:68:6)
#2 new _WidgetTicker (package:flutter/src/widgets/ticker_provider.dart:237:80)
#3 TickerProviderStateMixin.createTicker (package:flutter/src/widgets/ticker_provider.dart:168:34)
#4 new AnimationController (package:flutter/src/animation/animation_controller.dart:245:21)
#5 ExamTimerState.initState (package:azmoonasli/models/ExamTimer.dart:27:18)
#6 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4355:58)
#7 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#9 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5551:32)
#10 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#11 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#12 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#13 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#14 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#15 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#16 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#17 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#18 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#19 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#20 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#21 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#22 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#23 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#24 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#25 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#26 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#27 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#28 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#29 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#30 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#31 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#32 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#33 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#34 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#35 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#36 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#37 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#38 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#39 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#40 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#41 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#42 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5551:32)
#43 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#44 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#45 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#46 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#47 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#48 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#49 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#50 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5551:32)
#51 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#52 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#53 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#54 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#55 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#56 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#57 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#58 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#59 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#60 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#61 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#62 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#63 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#64 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#65 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#66 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#67 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#68 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#69 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#70 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#71 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#72 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#73 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#74 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#75 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#76 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#77 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#78 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#79 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#80 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#81 ParentDataElement.mount (package:flutter/src/widgets/framework.dart:4617:11)
#82 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#83 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5551:32)
#84 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#85 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#86 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#87 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#88 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#89 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#90 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#91 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#92 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#93 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#94 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#95 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#96 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#97 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#98 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#99 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#100 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#101 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#102 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#103 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#104 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#105 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#106 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#108 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#109 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#110 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#111 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#112 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#113 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#114 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#115 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#116 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#117 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#118 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#119 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#120 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#121 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#122 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#123 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#124 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#125 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#126 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#127 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#128 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#129 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#130 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#131 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#132 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#133 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#134 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#135 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#136 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#137 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#138 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#139 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#140 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#141 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#142 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#143 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#144 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#145 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#146 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#147 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#148 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#149 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#150 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#151 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#152 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#153 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#154 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#155 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#156 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#157 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#158 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#159 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#160 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#161 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#162 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#163 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#164 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#165 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#166 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#167 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#168 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#169 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#170 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#171 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#172 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#173 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#174 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#175 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#176 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#177 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#178 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#179 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#180 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#181 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#182 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#183 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#184 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#185 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#186 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#187 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#188 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#189 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#190 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#191 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#192 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#193 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#194 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#195 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#196 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#197 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#198 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#199 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#200 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#201 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#202 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#203 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
#204 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#205 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#206 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#207 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#208 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#209 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#210 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#211 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#212 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#213 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#217 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#224 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#225 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#226 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#227 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#228 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#229 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#230 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#231 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#232 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#233 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#234 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#235 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#236 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#237 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
#238 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
#239 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
#240 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
#241 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
#242 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5219:32)
#243 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5561:17)
#244 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#245 _TheatreElement.update (package:flutter/src/widgets/overlay.dart:605:16)
#246 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#247 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#249 StatefulElement.update (package:flutter/src/widgets/framework.dart:4413:5)
#250 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#251 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#252 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#253 ProxyElement.update (package:flutter/src/widgets/framework.dart:4557:5)
#254 _InheritedNotifierElement.update (package:flutter/src/widgets/inherited_notifier.dart:94:11)
#255 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#256 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)
#257 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#258 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#259 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#260 StatefulElement.update (package:flutter/src/widgets/framework.dart:4413:5)
#261 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#262 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)
#263 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#264 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)
#265 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#266 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#267 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
#268 StatelessElement.update (package:flutter/src/widgets/framework.dart:4298:5)
#269 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
#270 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
#272 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2432:33)
#273 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:773:20)
#274 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)
#275 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)
#276 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1041:9)
#277 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:957:5)
#281 _invoke (dart:ui/hooks.dart:259:10)
#282 _drawFrame (dart:ui/hooks.dart:217:3)
(elided 3 frames from package dart:async)
When the exception was thrown, this was the stack:
#0 TickerProviderStateMixin.dispose.<anonymous closure> (package:flutter/src/widgets/ticker_provider.dart:185:13)
#1 TickerProviderStateMixin.dispose (package:flutter/src/widgets/ticker_provider.dart:203:6)
#2 StatefulElement.unmount (package:flutter/src/widgets/framework.dart:4435:12)
#3 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1748:13)
#4 _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1746:7)
...
════════════════════════════════════════════════════════════════════════════════════════════════════
这是我的代码:
import 'package:flutter/material.dart';
import 'dart:math' as math;
class ExamTimer extends StatefulWidget {
final double size;
ExamTimer({@required this.size, });
@override
ExamTimerState createState() => ExamTimerState();
}
class ExamTimerState extends State<ExamTimer> with TickerProviderStateMixin {
AnimationController controller;
String get timerString {
Duration duration = controller.duration * controller.value;
return '${duration.inMinutes}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}';
}
@override
void initState() {
super.initState();
controller = AnimationController(
vsync: this,
duration: Duration(minutes: 20),
);
}
@override
Widget build(BuildContext context) {
ThemeData themeData = Theme.of(context);
controller.reverse(from: controller.value == 0.0 ? 1.0 : controller.value);
return Stack(
alignment: Alignment.center,
children: <Widget>[ AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child) {
return CustomPaint(
size: Size(widget.size, widget.size),
painter: TimerPainter(
animation: controller,
backgroundColor: Colors.white,
color: themeData.indicatorColor,
));
},
),
AnimatedBuilder(
animation: controller,
builder: (BuildContext context, Widget child) {
return Text(
timerString,
style: TextStyle(fontSize: 12.0),
);
}),
],
);
}
}
class TimerPainter extends CustomPainter {
TimerPainter({
this.animation,
this.backgroundColor,
this.color,
}) : super(repaint: animation);
final Animation<double> animation;
final Color backgroundColor, color;
@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint()
..color = backgroundColor
..strokeWidth = 5.0
..strokeCap = StrokeCap.round
..style = PaintingStyle.stroke;
canvas.drawCircle(size.center(Offset.zero), size.width / 2.0, paint);
paint.color = color;
double progress = (1.0 - animation.value) * 2 * math.pi;
canvas.drawArc(Offset.zero & size, math.pi * 1.5, progress, false, paint);
}
@override
bool shouldRepaint(TimerPainter old) {
return animation.value != old.animation.value ||
color != old.color ||
backgroundColor != old.backgroundColor;
}
}
所以我有3个问题:
当用户手动导航到另一条路线时,如何
dispose()
计时器?我需要知道从用户启动
ExamTimer()
到导航到另一条路线的时间(总时间(。如何在计时器结束其持续时间后自动导航到另一条路线。
如果能提供一个示例代码或任何方法,我们将不胜感激。
首先,您需要通过这种方式处理您的AnimationController
controller?.dispose();
关于您的问题:1.这就是处理Timer
的方法
yourTimer.cancel();
2、利用StopWatch
或Timer
可以计算出经过的时间
StopWatch
//start a stopwatch final watch = StopWatch()..start(); //Eleapsed time watch.eleapsed //returns a Duration //Stop it watch.stop() //You can also reset when you return to your page watch.reset();
计时器
//Start final timer = Timer.periodic(Duration(seconds:1), (Timer ticker){ if(ticker.tick == 2){//Wait for 1*2 seconds //Navigate here } //Total eleapsed time timer.tick*yourDurationUnit // used when creating this timer )
- 自动导航
计时器=计时器(持续时间(秒:2(,(({//导航到此处});
注意:您应该在dispose
方法中处理Timer
和StopWatch
,否则会导致内存泄漏