0

我正在尝试显示这样的容器

在此处输入图像描述

使用GridView, 2 个容器将连续。

错误:_


════════ Exception caught by rendering library ═════════════════════════════════
A RenderFlex overflowed by 23 pixels on the bottom.
The relevant error-causing widget was
Column

这是我的这个容器的代码

final double coverheight = 280;
  final double profileHeight = 144;

 Widget doctorsCard() {
    return Stack(
      alignment: Alignment.center,
      clipBehavior: Clip.none,
      children: <Widget>[
        Container(
          width: MediaQuery.of(context).size.width * 0.55,
          height: MediaQuery.of(context).size.height * 0.3,
          decoration: BoxDecoration(boxShadow: [
            BoxShadow(
              color: Colors.grey.withOpacity(0.6),
              spreadRadius: 3,
              blurRadius: 15,
              offset: const Offset(0, 3),
            ),
          ], color: containerColor, borderRadius: BorderRadius.circular(20.0)),
          child: Padding(
            padding: const EdgeInsets.only(top: 50, left: 10, right: 80),
            child: Align(
              alignment: Alignment.topLeft,
              child: Column(         //----------------Error is pointing here
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  SizedBox80(),
                  customText(context, "Dr. Maria Saleem", 15.0, FontWeight.w600,
                      blackColor),
                  customText(context, "MBBS, BDS- Dentist", 14.0,
                      FontWeight.w400, blackColor),
                  SizedBox20(),
                  Row(
                    children: [
                      Icon(
                        Icons.star,
                        size: 25,
                        color: Colors.yellow,
                      ),
                      SizedBox(
                        width: MediaQuery.of(context).size.width * 0.02,
                      ),
                      customText(
                          context, "4.7", 15.0, FontWeight.normal, blackColor)
                    ],
                  )
                ],
              ),
            ),
          ),
        ),
        Positioned(
          bottom: coverheight - profileHeight / 0.999,
          child: CircleAvatar(
            backgroundColor: Colors.white,
            radius: 115 / 2,
            backgroundImage: AssetImage(
              'assets/img/doctorImage2 PNG.png',
            ),
          ),
        ),
      ],
    );
  }

我在这里显示代码

Widget build(BuildContext context) {
    var providerContext = context.read<ProviderModel>();
    return SafeArea(
        child: SingleChildScrollView(
      child:Center(
                      child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        SizedBox(
                            height: MediaQuery.of(context).size.height * 0.25,
                            width: MediaQuery.of(context).size.width,
                            child: Container(
                              color: appThemeColor,
                              child: Padding(
                                padding: const EdgeInsets.all(15.0),
                                child: Align(
                                  alignment: Alignment.topLeft,
                                  child: Column(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    mainAxisSize: MainAxisSize.min,
                                    children: [
                                      customText(context, "Available", 25.0,
                                          FontWeight.w600, Colors.white),
                                      customText(context, "Specialist", 35.0,
                                          FontWeight.w600, Colors.white),
                                      SizedBox20(),

                                      //categories
                                      Expanded(
                                          child: ListView.builder(
                                        shrinkWrap: true,
                                        scrollDirection: Axis.horizontal,
                                        itemCount: category.length,
                                        itemBuilder:
                                            (BuildContext context, int index) =>
                                                Padding(
                                          padding:
                                              const EdgeInsets.only(left: 30),
                                          child: InkWell(
                                            onTap: () {
                                              setState(() {
                                                setState(() {
                                                  _itemIndex = index;
                                                  categoryTitle =
                                                      category[index].title;
                                                  print(categoryTitle);
                                                });
                                              });
                                            },
                                            child: DecoratedBox(
                                              decoration: BoxDecoration(
                                                  borderRadius:
                                                      BorderRadius.circular(
                                                          10.0),
                                                  color: _itemIndex == index
                                                      ? containerColor
                                                      : Colors.blue[800]),
                                              child: Padding(
                                                padding:
                                                    const EdgeInsets.all(5.0),
                                                child: customText(
                                                  context,
                                                  category[index].title,
                                                  15.0,
                                                  FontWeight.normal,
                                                  _itemIndex == index
                                                      ? appThemeColor
                                                      : Colors.white,
                                                ),
                                              ),
                                            ),
                                          ),
                                        ),
                                      )),
                                    ],
                                  ),
                                ),
                              ),
                            )),

                       
                        SizedBox(
                          height: 600,
                          child: GridView.count(
                              crossAxisCount: 2,
                              children: List.generate(6, (index) {
                                return InkWell(
                                    onTap: () {
                                    },
                                    child: Padding(
                                        padding: const EdgeInsets.all(8.0),
                                        child: doctorsCard()));
                              })),
                        )
                      ],
                    )),
    ));
  }
}

我的屏幕看起来像这样

在此处输入图像描述

请帮助如何解决这个问题。

4

1 回答 1

0

尝试在 grid view.count 中使用 childAspectRatio: ,就像我为我的代码所做的那样:

根据您需要的大小使用 childAspectRatio

GridView.count(
      crossAxisCount: 2,
      childAspectRatio: 0.5,
      controller: new ScrollController(keepScrollOffset: false),
      shrinkWrap: true,
      scrollDirection: Axis.vertical,
      children: widgetList.map((String value) {
        return new Container(
          color: Colors.green,
          margin: new EdgeInsets.all(1.0),
          child: new Center(
            child: new Text(
              value,
              style: new TextStyle(
                fontSize: 50.0,
                color: Colors.white,
              ),
            ),
          ),
        );
      }).toList(),
    ),
  ),
于 2022-03-03T07:23:17.230 回答