Я пытаюсь воспроизвести эффект сжатия текста, который естественно возникает с SliverAppBar с изображением, таким образом, что фоновое изображение ползунка сжимается до ведущего значка на панели приложений sloverAppBar.
Я пробовал использовать виджет flutter AnimatedPostioned вместе с контроллером прокрутки, который переключает состояние логического isSkrink
при прокрутке страницы.
Ниже представлен виджет AnimatedPosition:
AnimatedPositioned(
width: isShrink ? 10.0 : 200.0,
height: isShrink ? 10.0 : 200.0,
duration: Duration(seconds: 2),
curve: Curves.linear,
child: Stack(
children: [
Container(
child: Image.asset(
'assets/images/user-avatar.png'),
),
],
),
),
Ниже представлен SliverAppBar с AnimatedPosition, размещенным в стеке, и значок пользователя в ведущем параметре SliverAppBar.
SliverAppBar(
leading: isShrink
? Padding(
padding: EdgeInsets.all(10),
child: CircleAvatar(
backgroundImage:
AssetImage('assets/images/user-avatar.png'),
backgroundColor: Colors.white,
radius: 3,
),
)
: Container(),
floating: true,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
title: Row(
children: <Widget>[
Text(
"Username",
style: bodyText1Style(
context,
color: isShrink ? Colors.black : Colors.white,
fontSize: isShrink ? 18 : 15,
fontWeight: FontWeight.w600,
),
),
],
),
background: Stack(
children: <Widget>[
AnimatedPositioned(
width: isShrink ? 10.0 : 200.0,
height: isShrink ? 10.0 : 200.0,
duration: Duration(seconds: 2),
curve: Curves.linear,
child: Stack(
children: [
Container(
child: Image.asset(
'assets/images/user-avatar.png'),
),
],
),
),
],
),
),
expandedHeight: size.height * 0.35,
);
Это результат приведенного выше кода: