Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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
Image 在颤振中添加到AppBar时,部分图像未显示_Image_Flutter_Flutter Appbar - Fatal编程技术网

Image 在颤振中添加到AppBar时,部分图像未显示

Image 在颤振中添加到AppBar时,部分图像未显示,image,flutter,flutter-appbar,Image,Flutter,Flutter Appbar,当我尝试在Flatter中将图像添加到Appbar时,如下所示: appBar: PreferredSize( preferredSize: Size.fromHeight(100.0), child: AppBar( centerTitle: true, title: Image.asset('images/Ataxx.jpg'), ), ) 我得到以下输出: 正如您所看到的,顶部缺少部分图

当我尝试在Flatter中将图像添加到Appbar时,如下所示:

appBar: PreferredSize(
        preferredSize: Size.fromHeight(100.0),
        child: AppBar(
          centerTitle: true,
          title: Image.asset('images/Ataxx.jpg'),
        ),
      )
我得到以下输出:


正如您所看到的,顶部缺少部分图像!如何纠正这一点?谢谢。

首先,我认为没有必要使用
PreferredSizeWidget
,因为
AppBar
本身已经实现了
PreferredSizeWidget


此外,我习惯于将图像放置在应用程序栏中-有关如何使用它,请参见示例代码。

正如@rgisi建议的那样,您确实不需要使用
PreferredSize()
您只需要在标题中传递图像即可

appBar: AppBar(
    titleSpacing: 0,
    elevation: 0,
    title: Image.network(
      'https://images-eu.ssl-images-amazon.com/images/I/71ZFcWRAX7L.png',
      fit: BoxFit.cover,
    ),
  ),
对于您的用例,如果您真的想使用
PreferredSize()
,您可以这样使用它

appBar: PreferredSize(
    preferredSize: Size.fromHeight(100),
    child: Container(
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Image.network(
          'https://images-eu.ssl-images-amazon.com/images/I/71ZFcWRAX7L.png',
          fit: BoxFit.cover,
        ),
      ),
    ),
  ),
你会得到这样的结果