Flutter 如何在Flatter中设置自定义画家颜色的动画?
我正在尝试在Flitter中设置进度条的动画。到目前为止,我能够使用CustomPainter类绘制progressbar:) 我的目标是创建第一个栏(custompainter),就像第二个栏一样: 我找到了很多制作Radical progressbar的例子,但这只是一个CustomPainter的例子。我(认为)我需要更多独立的客户画家来绘制孔线,如下所示: 但是现在我想从我被卡住的第一个点开始制作动画,我应该传递什么以及如何传递值来制作第一个圆的动画? 接下来,我必须为线条设置动画 以下是我迄今为止的代码(GitHub要点):Flutter 如何在Flatter中设置自定义画家颜色的动画?,flutter,flutter-animation,Flutter,Flutter Animation,我正在尝试在Flitter中设置进度条的动画。到目前为止,我能够使用CustomPainter类绘制progressbar:) 我的目标是创建第一个栏(custompainter),就像第二个栏一样: 我找到了很多制作Radical progressbar的例子,但这只是一个CustomPainter的例子。我(认为)我需要更多独立的客户画家来绘制孔线,如下所示: 但是现在我想从我被卡住的第一个点开始制作动画,我应该传递什么以及如何传递值来制作第一个圆的动画? 接下来,我必须为线条设置动画 以
非常感谢您的支持 您可以将行小部件与
容器
和线性进程指示器
由于我不知道应用程序的其余部分,我将提供一个小部件树示例,供您参考
小部件树:
Row(
children: <Widget>[
Container([...]),
LinearProgressIndicator([...]),
Container([...]),
LinearProgressIndicator([...]),
Container([...]),
]
)
示例逻辑:
Container1 - progressValue > 0
LinearProgressIndicator - (progressValue-10) to 110
Container2 - progressValue > 110
LinearProgressIndicator - (progressValue-120) to 220
Container2 - progressValue > 220
以上逻辑可根据您的方便进行修改
线性压路机指示器的工作示例
import 'dart:async';
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
debugShowCheckedModeBanner: false,
home: new MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
MyAppState createState() => new MyAppState();
}
class MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Slider Demo'),
),
body: new Container(
color: Colors.blueAccent,
padding: new EdgeInsets.all(32.0),
child: new ProgressIndicatorDemo(),
),
);
}
}
class ProgressIndicatorDemo extends StatefulWidget {
@override
_ProgressIndicatorDemoState createState() =>
new _ProgressIndicatorDemoState();
}
class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo>
with SingleTickerProviderStateMixin {
AnimationController controller;
Animation<double> animation;
@override
void initState() {
super.initState();
controller = AnimationController(
duration: const Duration(milliseconds: 2000), vsync: this);
animation = Tween(begin: 0.0, end: 1.0).animate(controller)
..addListener(() {
setState(() {
// the state that has changed here is the animation object’s value
});
});
controller.repeat();
}
@override
void dispose() {
controller.stop();
super.dispose();
}
@override
Widget build(BuildContext context) {
return new Center(
child: new Container(
child: LinearProgressIndicator( value: animation.value,),
)
);
}
}
导入'dart:async';
进口“包装:颤振/材料.省道”;
void main(){
runApp(新材料)PP(
debugShowCheckedModeBanner:false,
主页:新建MyApp(),
));
}
类MyApp扩展了StatefulWidget{
@凌驾
MyAppState createState()=>新建MyAppState();
}
类MyAppState扩展了状态{
@凌驾
小部件构建(构建上下文){
归还新脚手架(
appBar:新的appBar(
标题:新文本(“滑块演示”),
),
主体:新容器(
颜色:Colors.blueAccent,
填充:新边缘设置。全部(32.0),
子项:新的ProgressIndicatorDemo(),
),
);
}
}
类ProgressIndicatorDemo扩展StatefulWidget{
@凌驾
_ProgressIndicatorDemoState createState()=>
新的_ProgressIndicatorDemoState();
}
类_ProgressIndicatorDemoState扩展状态
使用SingleTickerProviderStateMixin{
动画控制器;
动画;
@凌驾
void initState(){
super.initState();
控制器=动画控制器(
持续时间:常量持续时间(毫秒:2000),vsync:this;
动画=Tween(开始:0.0,结束:1.0)。动画(控制器)
…addListener(){
设置状态(){
//此处更改的状态是动画对象的值
});
});
controller.repeat();
}
@凌驾
无效处置(){
controller.stop();
super.dispose();
}
@凌驾
小部件构建(构建上下文){
返回新中心(
子容器:新容器(
子级:LinearProgressIndicator(值:animation.value,),
)
);
}
}
Hi@Mohit,非常感谢。我现在有点理智了。你知道如何用动画实现progressValue吗?我添加了一个LinearProgressIndicator
的工作示例,供你从另一个线程中参考。谢谢你!你带我到正确的方向。现在,我让动画与交错动画一起工作。有关完整的工作进度条,请参见。
import 'dart:async';
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
debugShowCheckedModeBanner: false,
home: new MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
MyAppState createState() => new MyAppState();
}
class MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Slider Demo'),
),
body: new Container(
color: Colors.blueAccent,
padding: new EdgeInsets.all(32.0),
child: new ProgressIndicatorDemo(),
),
);
}
}
class ProgressIndicatorDemo extends StatefulWidget {
@override
_ProgressIndicatorDemoState createState() =>
new _ProgressIndicatorDemoState();
}
class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo>
with SingleTickerProviderStateMixin {
AnimationController controller;
Animation<double> animation;
@override
void initState() {
super.initState();
controller = AnimationController(
duration: const Duration(milliseconds: 2000), vsync: this);
animation = Tween(begin: 0.0, end: 1.0).animate(controller)
..addListener(() {
setState(() {
// the state that has changed here is the animation object’s value
});
});
controller.repeat();
}
@override
void dispose() {
controller.stop();
super.dispose();
}
@override
Widget build(BuildContext context) {
return new Center(
child: new Container(
child: LinearProgressIndicator( value: animation.value,),
)
);
}
}