Flutter 当用户在flatter中滚动时如何拉伸图像

Flutter 当用户在flatter中滚动时如何拉伸图像,flutter,flutter-animation,Flutter,Flutter Animation,我想在用户滚动时拉伸图像 Container( child: Image.asset( 'assets/appHeader.png', fit: BoxFit.cover, width: size.width, height: 170, ), ) 此图像位于页面顶部,当用户向上滚动时,我想拉伸图像。 这就像在SliverAppBar中拉伸一样。我对颤振非常陌生,所以我对动画了解不多。试试这个,我正在使用FlexibleSpaceBar创建这个 @override

我想在用户滚动时拉伸图像

Container(
 child: Image.asset(
  'assets/appHeader.png',
   fit: BoxFit.cover,
   width: size.width,
   height: 170,
 ),
)
此图像位于页面顶部,当用户向上滚动时,我想拉伸图像。
这就像在SliverAppBar中拉伸一样。我对颤振非常陌生,所以我对动画了解不多。

试试这个,我正在使用FlexibleSpaceBar创建这个

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[
            SliverAppBar(
              expandedHeight: 200.0,
              floating: false,
              //pinned: true, if you need to show appBar.
              pinned: false,

              flexibleSpace: FlexibleSpaceBar(
                  centerTitle: true,
                  title: Text("Image Text(optional)",
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 16.0,
                      )),
                  background: Image.network(
                    "https://miro.medium.com/max/700/1*_nCC_uFDVYas8uYa9m6fQQ.jpeg",
                    fit: BoxFit.cover,
                  )
                  /*-------Your Image here--------*/
                  /* Image.asset(
          'assets/appHeader.png',
          fit: BoxFit.cover,
          width: size.width,
          height: 170,
          ),*/
                  ),
            ),
          ];
        },
        body: Center(
          child: Text("Your screen data"),
        ),
      ),
    );
  }
@覆盖
小部件构建(构建上下文){
返回脚手架(
正文:嵌套滚动视图(
headerSliverBuilder:(BuildContext上下文,boolInnerBoxIsCrolled){
返回[
滑杆(
扩展高度:200.0,
浮动:假,
//pinted:如果需要显示appBar,则为true。
错,,
flexibleSpace:FlexibleSpaceBar(
标题:对,
标题:文本(“图像文本(可选)”,
样式:TextStyle(
颜色:颜色,白色,
字体大小:16.0,
)),
背景:Image.net(
"https://miro.medium.com/max/700/1*_nCC_uFDVYas8uYa9m6fQQ.jpeg“,
适合:BoxFit.cover,
)
/*-------你在这里的形象--------*/
/*影像资产(
“assets/appHeader.png”,
适合:BoxFit.cover,
宽度:size.width,
身高:170,
),*/
),
),
];
},
正文:中(
子:文本(“您的屏幕数据”),
),
),
);
}

试试这个,我正在使用FlexibleSpaceBar创建它

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[
            SliverAppBar(
              expandedHeight: 200.0,
              floating: false,
              //pinned: true, if you need to show appBar.
              pinned: false,

              flexibleSpace: FlexibleSpaceBar(
                  centerTitle: true,
                  title: Text("Image Text(optional)",
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 16.0,
                      )),
                  background: Image.network(
                    "https://miro.medium.com/max/700/1*_nCC_uFDVYas8uYa9m6fQQ.jpeg",
                    fit: BoxFit.cover,
                  )
                  /*-------Your Image here--------*/
                  /* Image.asset(
          'assets/appHeader.png',
          fit: BoxFit.cover,
          width: size.width,
          height: 170,
          ),*/
                  ),
            ),
          ];
        },
        body: Center(
          child: Text("Your screen data"),
        ),
      ),
    );
  }
@覆盖
小部件构建(构建上下文){
返回脚手架(
正文:嵌套滚动视图(
headerSliverBuilder:(BuildContext上下文,boolInnerBoxIsCrolled){
返回[
滑杆(
扩展高度:200.0,
浮动:假,
//pinted:如果需要显示appBar,则为true。
错,,
flexibleSpace:FlexibleSpaceBar(
标题:对,
标题:文本(“图像文本(可选)”,
样式:TextStyle(
颜色:颜色,白色,
字体大小:16.0,
)),
背景:Image.net(
"https://miro.medium.com/max/700/1*_nCC_uFDVYas8uYa9m6fQQ.jpeg“,
适合:BoxFit.cover,
)
/*-------你在这里的形象--------*/
/*影像资产(
“assets/appHeader.png”,
适合:BoxFit.cover,
宽度:size.width,
身高:170,
),*/
),
),
];
},
正文:中(
子:文本(“您的屏幕数据”),
),
),
);
}

关于(您在评论中询问的)此答案更新(仅适用于我们讨论的这种情况)


关于(您在评论中询问的)更新的回答(仅适用于我们讨论的这种情况)


当我滚动到底部时,我不希望标题出现。好的,我将根据您的要求更新答案。非常感谢!!:)另一个问题。我怎样才能把另一个容器放在上面??就像我们在stackmeans做的那样。。您需要在主体或任何其他位置添加容器。我不明白,“我怎样才能在上面放置另一个容器?就像我们在堆栈中一样”'我不想在滚动到底部时显示标题。好的,我将根据您的要求通过回答进行更新。非常感谢!!:)另一个问题。我怎样才能把另一个容器放在上面??就像我们在stackmeans做的那样。。您需要在主体或任何其他位置添加容器。我不明白,“我怎样才能把另一个容器放在上面?就像我们在堆栈中做的那样”'我可以添加一个堆栈吗?我可以添加一个堆栈吗??