首页 > 解决方案 > 为什么我不能在 Flutter 的 AppBar 中更改 CircleAvatar 或其他圆形小部件的高度?

问题描述

我试图在操作列表中放置一个CircleAvatarAppBar但 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,
          ),
        ),
      ),
    );
  }
}

在此处输入图像描述

标签: flutterflutter-layoutflutter-appbar

解决方案


您可以将其包装CircleAvatarRow

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

结果:

资源


推荐阅读