在动画运行时,我想返回下一页或上一页......但此错误显示为“AnimationController.stop() 在 AnimationController.dispose() 之后调用 AnimationController 方法在调用 dispose 后不应使用。”
请帮我...
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:sanduk/utils/app_colors.dart';
import 'package:sanduk/utils/text_widget.dart';
import 'dart:math' as math;
class QuizSearchingPlayers extends StatefulWidget {
const QuizSearchingPlayers({Key? key}) : super(key: key);
@override
_QuizSearchingPlayersState createState() => _QuizSearchingPlayersState();
}
class _QuizSearchingPlayersState extends State<QuizSearchingPlayers>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 2),
vsync: this,
)..repeat();
_controller.addListener(() async {
await stoppingAnimation();
});
}
Future stoppingAnimation() async {
await Future.delayed(const Duration(seconds: 10));
_controller.reset();
_controller.stop();
return true;
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
backgroundColor: AppColors.darkThemeBackground,
body: Container(
height: Get.height,
width: Get.width,
padding: EdgeInsets.all(20.h),
child: Column(
children: [
TextWidget(
"BIOLOGY QUIZ",
styles: TextStyles.size18_500,
color: AppColors.white,
),
Container(
padding: EdgeInsets.symmetric(vertical: 5, horizontal: 10.w),
child: CircleAvatar(
radius: 150.r,
backgroundColor: AppColors.transparent,
child: AnimatedBuilder(
animation: _controller,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Stack(
children: [
Align(
alignment: Alignment.center,
child: CircleAvatar(
radius: 120.r,
backgroundColor: AppColors.blue,
child: CircleAvatar(
radius: 115.r,
backgroundColor: AppColors.darkThemeBackground,
),
),
),
Align(
alignment: Alignment.centerLeft,
child: CircleAvatar(
radius: 40.r,
backgroundColor: AppColors.red,
backgroundImage: const AssetImage(
"assets/images/sardar.png")),
),
Align(
alignment: Alignment.centerRight,
child: CircleAvatar(
radius: 40.r,
backgroundColor: AppColors.darkBlue,
backgroundImage: const AssetImage(
"assets/images/sardar.png"),
)),
],
),
),
builder: (context, child) {
return Transform.rotate(
angle: _controller.value * 2 * math.pi,
child: child,
);
},
),
),
),
TextWidget(
"Searching For Opponent..",
styles: TextStyles.size32_400,
color: AppColors.blue,
maxLines: 2,
),
],
),
),
),
);
}
}
一切正常,直到我导航回其他屏幕......当我在我的停止动画()方法中打印一些行时,它会一直打印我如何停止它?