gpt4 book ai didi

flutter - 在 Sliver Appbar 上圈出头像

转载 作者:IT王子 更新时间:2023-10-29 06:53:35 25 4
gpt4 key购买 nike

我试图在我的 sliver 应用栏上包含一个圆形个人资料图像按钮,但 sliver 应用栏并没有完全正确地呈现它。这就是我得到的,如何在条形应用栏上获得圆形个人资料图片?

enter image description here

我的代码:

    @override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: Text('Home'),
leading: Container(),
actions: <Widget>[
IconButton(
icon: Icon(Icons.notifications),
onPressed: () {}),
Padding(
padding: const EdgeInsets.all(8.0),
child: InkWell(
child: Container(
height: 30,
width: 30,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(25.0),
image: DecorationImage(image: AssetImage('assets/images/blank_profile.png'))
),
),
onTap: () => Navigator.push(context, new MaterialPageRoute(builder: (BuildContext context) => ProfilePage())),
),
),
],

),

使用 CircleAvatar :

 @override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: Text('Home'),
backgroundColor: Colors.deepOrange,
leading: Container(),
actions: <Widget>[
IconButton(
icon: Icon(Icons.notifications),
onPressed: () {}),
CircleAvatar(
backgroundImage: AssetImage('assets/images/blank_profile.png'),
minRadius: 28,
),
],

),

enter image description here

最佳答案

为此你必须使用 CircleAvatar为此。

这是您可以使用的代码:

SliverAppBar(
title: Text('Home'),
leading: Container(),
actions: <Widget>[
IconButton(
icon: Icon(Icons.notifications),
onPressed: () {}),
CircleAvatar(
child: ClipOval(
child: Image.asset('assets/images/blank_profile.png'),
),
),
],
)

关于flutter - 在 Sliver Appbar 上圈出头像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55292379/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com