我想將 CircleAvatar() 居中。我嘗試了 Center() 并將 Container(), Padding() 給它的父級來實作它。你有什么建議嗎?
endDrawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
UserAccountsDrawerHeader(
margin: EdgeInsets.only(bottom: 40.h),
decoration: BoxDecoration(color: Colors.blue[100]),
currentAccountPicture: CircleAvatar(
radius: 60.r,
backgroundColor: Colors.white,
child: Image.asset('assets/sermedhavuz.png')),
accountName:
SizedBox(child: Text(user.userName.toUpperCase())),
accountEmail: SizedBox(child: Text(user.email)),
),
],
),
)
這是抽屜的圖片:

uj5u.com熱心網友回復:
這樣做的唯一方法(不創建自定義抽屜)將 Size 設定為currentAccountPicturewithcurrentAccountPictureSize然后Center作業:
double widthDrawer = MediaQuery.of(context).size.width * 0.75;
return Container(
width: widthDrawer,
child: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
UserAccountsDrawerHeader(
margin: EdgeInsets.only(bottom: 40.h),
decoration: BoxDecoration(color: Colors.blue[100]),
currentAccountPictureSize: Size(widthDrawer, 80), //set custom height
currentAccountPicture: Center( //now Center works
child: CircleAvatar(
radius: 60.r,
backgroundColor: Colors.white,
child: Image.asset('assets/sermedhavuz.png')),
),
accountName:
SizedBox(child: Text(user.userName.toUpperCase())),
accountEmail: SizedBox(child: Text(user.email)),
),
],
),
),
);
要知道抽屜的寬度,請將 Container 設定為具有自定義寬度的父級。
uj5u.com熱心網友回復:
使用container與alignment: Alignment.center
endDrawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: [
UserAccountsDrawerHeader(
margin: EdgeInsets.only(bottom: 40.h),
decoration: BoxDecoration(color: Colors.blue[100]),
currentAccountPicture: Container(
alignment: Alignment.center
child: CircleAvatar(
radius: 60.r,
backgroundColor: Colors.white,
child: Image.asset('assets/sermedhavuz.png'))
),
accountName:
SizedBox(child: Text(user.userName.toUpperCase())),
accountEmail: SizedBox(child: Text(user.email)),
),
],
),
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/359634.html
上一篇:在顫振中實作多選交錯網格視圖
下一篇:我想添加到默認值
