簡體   English   中英

Flutter:如何為圓形頭像設置背景圖像

[英]Flutter: How can I set a background image for Circle Avatar

我的資產文件夾中有一張圖片,想設置為圓形頭像的背景,我該怎么做?

CircleAvatar(
  backgroundImage: AssetImage('assets/image.png'),
);

這對你有用。

確保您已在 pubspec.yaml 文件內的資產文件夾和路徑中添加圖像

喜歡

assets:
    - assets/image.png

由於您的Assets文件夾中已經有圖像。

1) 將其添加到您的pubspec.yaml文件中:

assets:
    - assets/yourimage.png

2)將圖像指定為您的CircleAvatarbackgroundImage

CircleAvatar(
  // the circle avatar has the background image property for specifying images
  backgroundImage: AssetImage('assets/yourimage.png'),
);

像這樣的東西?

CircleAvatar(
              child: Image.network(
        "https://miro.medium.com/proxy/1*ilC2Aqp5sZd1wi0CopD1Hw.png",
        fit: BoxFit.scaleDown,
      ))

像這樣的東西會給你一個帶有背景的頭像,在加載網絡圖像時會顯示

CircleAvatar(
   backgroundColor: Colors.pink,
   backgroundImage: AssetImage('/path/to/asset.png'),
   child: Image.network('https://www.example.com/with/online.png')
);

不要忘記將資產文件夾的路徑放在 pubspec.yml 中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM