为什么我无法更改 Flutter 中 AppBar 中 CircleAvatar 或其他圆形小部件的高度?

问题描述 投票:0回答:2

我试图将

CircleAvatar
放入操作列表中的
AppBar
内,但 CircleAvatar 会将其高度固定到 AppBar 的高度,从而无法调整其大小并保持其圆形。我已经尝试将其包装在 Container 或 SizedBox 内,但没有成功。

示例:

import 'package:flutter/material.dart';

class HoursScreenEmployee extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white10,
        brightness: Brightness.light,
        elevation: 0,
        centerTitle: false,
        actions: [
          CircleAvatar(
            backgroundImage: NetworkImage("https://picsum.photos/500/300"),
            maxRadius: 15,
            minRadius: 15,
          ),
        ],
        title: Text(
          "La Chance 🍻",
          style: TextStyle(
            fontFamily: "Masiva",
            fontSize: 27,
            fontWeight: FontWeight.w800,
            color: Colors.black,
          ),
        ),
      ),
    );
  }
}

flutter flutter-layout flutter-appbar
2个回答
2
投票

您可以将

CircleAvatar
包裹在
Row
中:

actions: [
          Row(
            children: <Widget>[
              Container(
                height: 60,
                width: 60,
                child: CircleAvatar(
                  backgroundImage:
                      NetworkImage("https://picsum.photos/500/300"),
                  maxRadius: 15,
                  minRadius: 15,
                ),
              ),
            ],
          ),
        ],

结果:


0
投票

要更改圆形头像内图像的高度和宽度,请执行以下操作:

                   CircleAvatar(
                      radius: 20,
                      child: CircleAvatar(
                        radius: 15,
                        backgroundImage: AssetImage(
                          ImageAssets.micIcon,
                        ),
                      ),
                    ),
© www.soinside.com 2019 - 2024. All rights reserved.