【发布时间】:2021-11-14 04:59:08
【问题描述】:
你好吗?我正在学习颤振,我被颤动的兴奋所困扰,我不知道如何解决它。我想为测验 gma 制作一个进度条。我想制作一个 60 秒的进度条,但是当我执行我的代码时,我收到了这个错误:
FlutterError (Cannot lerp between "0" and "1".
The type int returned a double after multiplication with a double value. See "Types with
special considerations" at https://api.flutter.dev/flutter/animation/Tween-class.html for more
information.
To lerp int values, consider IntTween or StepTween instead.)
谁能帮帮我??我的 ProgressBar 代码
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:quizz_app/constants.dart';
import 'package:quizz_app/controllers/question_controllers.dart';
class ProgressBar extends StatelessWidget {
const ProgressBar({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
height: 35,
decoration: BoxDecoration(
border: Border.all(color: Colors.white.withOpacity(0.2), width: 3),
borderRadius: BorderRadius.circular(50)),
child: GetBuilder<QuestionController>(
init: QuestionController(),
builder: (controller) {
print(controller.animation.value);
return Stack(
children: [
LayoutBuilder(
//layout provide us the available space for the container
builder: (context, constraints) => Container(
width: constraints.maxWidth * 0.5,
decoration: BoxDecoration(
gradient: kPrimaryGradient,
borderRadius: BorderRadius.circular(50)),
)),
Positioned.fill(
child: Padding(
padding:
const EdgeInsets.symmetric(horizontal: kDefaultPadding),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
// ignore: prefer_const_literals_to_create_immutables
children: [
const Text("Time left:", style: TextStyle(fontSize: 20)),
const Text(
"10",
style: TextStyle(fontSize: 20),
),
],
),
))
],
);
},
),
);
}
}
这是我的问题控制器代码,用于控制我的进度条
import 'package:flutter/animation.dart';
import 'package:get/get.dart';
//we use get pckage for our state management
class QuestionController extends GetxController
with SingleGetTickerProviderMixin {
late AnimationController _animationController;
late Animation _animation;
Animation get animation => this._animation;
@override
void onInit() {
_animationController =
AnimationController(duration: const Duration(seconds: 60), vsync: this);
_animation = Tween(begin: 0, end: 1).animate(_animationController)
..addListener(() {
//update like setstate
update();
});
_animationController.forward();
super.onInit();
}
}
【问题讨论】:
标签: flutter