Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 颤振:AppBar背景图像_Dart_Flutter_Appbar - Fatal编程技术网

Dart 颤振:AppBar背景图像

Dart 颤振:AppBar背景图像,dart,flutter,appbar,Dart,Flutter,Appbar,是否可以将背景图像添加到脚手架的AppBar?我知道sliver,但当你向下滚动时,图像会被隐藏,应用程序栏会改变颜色,对吗?因此,我想知道这是否可行,如果不可行,是否存在任何现有的解决办法?谢谢 小部件构建(构建上下文){ Widget build(BuildContext context) { return new Container( child: new Stack(children: <Widget>[ new Container( child:

是否可以将背景图像添加到脚手架的AppBar?我知道sliver,但当你向下滚动时,图像会被隐藏,应用程序栏会改变颜色,对吗?因此,我想知道这是否可行,如果不可行,是否存在任何现有的解决办法?谢谢

小部件构建(构建上下文){
Widget build(BuildContext context) {

return new Container(
  child: new Stack(children: <Widget>[
    new Container(
      child: new Image.asset('assets/appimage.jpg'),
      color: Colors.lightGreen,
    ),
    new Scaffold(
      appBar: new AppBar(title: new Text('Hello'),
      backgroundColor: Colors.transparent,
        elevation: 0.0,
      ),
      backgroundColor: Colors.transparent,
      body: new Container(
        color: Colors.white,
        child: new Center(
        child: new Text('Hello how are you?'),),)
    )
  ],),
);
}
退回新货柜( 子级:新堆栈(子级:[ 新容器( 子级:new Image.asset('assets/appimage.jpg'), 颜色:颜色。浅绿色, ), 新脚手架( appBar:newappbar(标题:newtext('Hello'), 背景颜色:颜色。透明, 标高:0.0, ), 背景颜色:颜色。透明, 主体:新容器( 颜色:颜色,白色, 孩子:新中心( 孩子:新课文(‘你好吗?’),),) ) ],), ); }
不要像使用
堆栈
小部件那样,而是在
AppBar
小部件的
flexibleSpace
参数中传递背景图像:

 @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('App Bar!'),
        flexibleSpace: Image(
          image: AssetImage('assets/image.png'),
          fit: BoxFit.cover,
        ),
        backgroundColor: Colors.transparent,
      ),
      body: Container(),
    );
  }

我在使用iOS和Hafiz Nordin的答案时遇到了一些问题。在iOS上,图像没有覆盖整个appbar,只留下一个小的透明空间

我的解决方案是使用带有
DecorationImage
的容器

AppBar(
  flexibleSpace: Container(
    decoration: 
      BoxDecoration(
        image: DecorationImage(
          image: AssetImage(),
          fit: BoxFit.cover,
        ),
      ),
  ),
  backgroundColor: Colors.transparent,
  title: Text("App Bar"),
);

嗨,祖尔菲卡。有没有一个更像主题的解决方案?我想更改所有appBar的背景图像。因为我有很多屏幕,所以我不想对所有屏幕应用更改。非常感谢。你不能只创建一个容器小部件并在所有屏幕中使用它吗?这不会使
AppBar
与图像一样大,它会剪辑图像。