Flutter 在颤振中处理@build方法中的变量是否正确?

Flutter 在颤振中处理@build方法中的变量是否正确?,flutter,dart,flutter-layout,flutter-dependencies,lifecycle,Flutter,Dart,Flutter Layout,Flutter Dependencies,Lifecycle,我认为有时需要在@override构建方法中处理变量 @override Widget build(BuildContext context) { Animation animationTitle1 = Tween<double>(begin: 0.0, end: 1.0).animate( CurvedAnimation( parent: widget.animationController, curve:

我认为有时需要在@override构建方法中处理变量

@override
  Widget build(BuildContext context) {
    Animation animationTitle1 = Tween<double>(begin: 0.0, end: 1.0).animate(
        CurvedAnimation(
            parent: widget.animationController,
            curve: Interval(0, 1.0, curve: Curves.fastOutSlowIn)));
    Animation animationTitle2 = Tween<double>(begin: 0.0, end: 1.0).animate(
        CurvedAnimation(
            parent: widget.animationController,
            curve: Interval(0.2, 1.0, curve: Curves.fastOutSlowIn)));
.
.
.
@覆盖
小部件构建(构建上下文){
动画标题1=Tween(开始:0.0,结束:1.0)。设置动画(
曲线化(
父项:widget.animationController,
曲线:区间(0,1.0,曲线:Curves.fastoutswowin));
动画标题2=Tween(开始:0.0,结束:1.0)。设置动画(
曲线化(
父项:widget.animationController,
曲线:区间(0.2,1.0,曲线:Curves.fastoutswowin));
.
.
.
我不知道它在逻辑上是否有效? 但不知何故,我需要这种逻辑来声明和管理@build方法中的多个变量。 一些要求如

  • 动画对象
  • 在某些情况下,手动调用stream builder小部件以刷新数据
榜样

@override
  Widget build(BuildContext context) {
    var streamBuilder = StreamBuilder(
          stream: myStreamObj,
          builder: (BuildContext context, AsyncSnapshot<dynamic> snapshotVacchan) {
           // my code
          },
        );
    
    return Column(
            children: [
              streamBuilder,
              FlatButton(
                  child: Text('Reload'),
                  onPressed: () {
                    setState(() {
                      myStreamObj = newScreen;
                    });
                  }),
            ],
          );
 }
@覆盖
小部件构建(构建上下文){
var streamBuilder=streamBuilder(
流:myStreamObj,
生成器:(构建上下文上下文,异步快照快照){
//我的代码
},
);
返回列(
儿童:[
streamBuilder,
扁平按钮(
子项:文本('Reload'),
已按下:(){
设置状态(){
myStreamObj=新闻屏幕;
});
}),
],
);
}

据我所知,在构建方法中声明或管理变量不是正确的编码方式

@override
  Widget build(BuildContext context) {
    Animation animationTitle1 = Tween<double>(begin: 0.0, end: 1.0).animate(
        CurvedAnimation(
            parent: widget.animationController,
            curve: Interval(0, 1.0, curve: Curves.fastOutSlowIn)));
    Animation animationTitle2 = Tween<double>(begin: 0.0, end: 1.0).animate(
        CurvedAnimation(
            parent: widget.animationController,
            curve: Interval(0.2, 1.0, curve: Curves.fastOutSlowIn)));
.
.
.