Это желаемое поведение background:
свойства FlexibleSpaceBar
- его Предположим, что он заполняет всю фоновую область Appbar
, теперь title
здесь не отдельный элемент для рендеринга ниже фона, а виджет переднего плана из FlexibleSpaceBar
для отображения поверх background:
Если вам действительно нужно разделить заголовок и изображение, вы не можете использовать свойство background
& title
, но вместо этого вам нужно использовать Column
или ListView
вместо FlexibleSpaceBar
.
Вы можете попробовать следующий код с возможными вариантами:
Рекомендуемое решение:
SliverAppBar(
backgroundColor: Colors.blue,
expandedHeight: 200.0,
floating: true,
// pinned: true,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Text("Collapsing Toolbar",
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
)),
background: Row(
children: <Widget>[
Spacer(),
CircleAvatar(
radius: 54.0,
backgroundImage: NetworkImage(
"https://placeimg.com/640/480/animals",
),
),
Spacer(),
],
)),
),
Это изображение с radius: 68.0,
.
![enter image description here](https://i.stack.imgur.com/F0Qrq.png)
Ниже приводятся фиксированные поля, может вызвать проблемы в адаптивном дизайне, но все еще работает.
С ClipOval
:
SliverAppBar(
backgroundColor: Colors.blue,
expandedHeight: 200.0,
floating: true,
// pinned: true,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Text("Collapsing Toolbar",
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
)),
background: Container(
margin:
EdgeInsets.symmetric(horizontal: 125.0, vertical: 50.0),
child: ClipOval(
child: Image.network(
"https://placeimg.com/640/480/animals",
),
),
)),
),
![enter image description here](https://i.stack.imgur.com/6MXan.png)
с CircleAvatar
SliverAppBar(
backgroundColor: Colors.blue,
expandedHeight: 200.0,
floating: true,
// pinned: true,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Text("Collapsing Toolbar",
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
)),
background: Container(
margin:
EdgeInsets.symmetric(horizontal: 125.0, vertical: 50.0),
child: CircleAvatar(
radius: 30.0,
backgroundImage: NetworkImage(
"https://placeimg.com/640/480/animals",
),
),
)),
),
![enter image description here](https://i.stack.imgur.com/3sc71.png)
Обновление:
с ListView
Опция.
Примечание: AppBar
высота определяется свойством expandedHeight:
и не будет увеличиваться в случае увеличения радиуса изображения.
SliverAppBar(
backgroundColor: Colors.blue,
expandedHeight: 200.0,
floating: true,
// pinned: true,
flexibleSpace: Center(
child: ListView(
shrinkWrap: true,
children: <Widget>[
Row(
children: <Widget>[
Spacer(),
CircleAvatar(
radius: 68.0,
backgroundImage: NetworkImage(
"https://placeimg.com/640/480/animals",
),
),
Spacer(),
],
),
Center(
child: Text("Collapsing Toolbar",
style: TextStyle(
color: Colors.white,
fontSize: 22.0,
)),
),
],
),
),
),