Flutter AlertDialog с динамической высотой

#listview #dart #flutter #height #android-alertdialog

#listview #dart #flutter #высота #android-alertdialog

Вопрос:

У меня есть ListView в AlertDialog . В этом случае как я могу установить динамическую высоту AlertDialog согласно данным списка?

 return AlertDialog(
    contentPadding: EdgeInsets.all(0.0),
    shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.all(Radius.circular(5.0))), 
    content: new Container(
      width: screenSize.width * 0.9,
      height: screenSize.height * 0.5, 
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          Container(
            width: screenSize.width,
            height: 40,
            padding: EdgeInsets.only(left: 10, right: 10),
            color: const Color(colorPrimary),
            child: Align(
              child: Text(
                  selectedProductName != null ? selectedProductName : "",
                  style: TextStyle(
                      fontSize: 14.0,
                      fontWeight: FontWeight.w500,
                      fontFamily: 'helvetica',
                      color: Colors.white)),
              alignment: Alignment.center,
            ),
          ),
          Container(
            height: 35,
            color: const Color(colorAccent),
            child: Row(
              children: <Widget>[
                Expanded(
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Text(
                        "City",
                        style: prifixTxtPrimaryStyle,
                      ),
                    ],
                  ),
                  flex: 1,
                ),
                Container(
                  width: 1,
                  color: Colors.white70,
                ),
                Expanded(
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Text(
                        "Name",
                        style: prifixTxtPrimaryStyle,
                      ),
                    ],
                  ),
                  flex: 1,
                ),
                Container(
                  width: 1,
                  color: Colors.white70,
                ),
                Expanded(
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Text(
                        "Qty",
                        style: prifixTxtPrimaryStyle,
                      ),
                    ],
                  ),
                  flex: 1,
                ),
              ],
            ),
          ),
          new Expanded(
            child: ListView.builder(
              itemCount: listDialogDisplay.length,
              shrinkWrap: true,
              itemBuilder: (BuildContext context, int index) {
                return listDialogDisplay.length > 0
                    ? Column(
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    Container(
                      //height: 35,
                      width: screenSize.width,
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment:
                        MainAxisAlignment.spaceAround,
                        children: <Widget>[
                          Expanded(
                            child: Align(
                              alignment: Alignment.center,
                              child: Padding(
                                padding: EdgeInsets.only(
                                    left: 2, right: 2),
                                child: Text(
                                  listDialogDisplay[index]
                                      .City
                                      .toString(),
                                  style: TextStyle(
                                    fontSize: 14.0,
                                    fontWeight: FontWeight.w500,
                                    fontFamily: 'helvetica',
                                  ),
                                ),
                              ),
                            ),
                            flex: 1,
                          ),
                          Container(
                            width: 1,
                            color: Colors.black12,
                            height: 25,
                            margin:
                            EdgeInsets.only(top: 5, bottom: 5),
                          ),
                          Expanded(
                            child: Align(
                              alignment: Alignment.center,
                              child: Padding(
                                padding: EdgeInsets.only(
                                    left: 2, right: 2),
                                child: Text(
                                    listDialogDisplay[index]
                                        .Name
                                        .toString(),
                                    style: TextStyle(
                                      fontSize: 14.0,
                                      fontWeight: FontWeight.w500,
                                      fontFamily: 'helvetica',
                                    )),
                              ),
                            ),
                            flex: 1,
                          ),
                          Container(
                            width: 1,
                            color: Colors.black12,
                            height: 25,
                            margin:
                            EdgeInsets.only(top: 5, bottom: 5),
                          ),
                          Expanded(
                            child: Align(
                              alignment: Alignment.center,
                              child: Padding(
                                padding: EdgeInsets.only(
                                    left: 2, right: 2),
                                child: Text(
                                    listDialogDisplay[index]
                                        .Qty
                                        .toString(),
                                    style: TextStyle(
                                      fontSize: 14.0,
                                      fontWeight: FontWeight.w500,
                                      fontFamily: 'helvetica',
                                    )),
                              ),
                            ),
                            flex: 1,
                          ),
                        ],
                      ),
                    ),
                    Container(
                      width: screenSize.width,
                      color: Colors.black12,
                      height: 1, 
                    ), 
                  ],
                )
                    : Container();
              },
            ),
          ),
          Container(
            width: screenSize.width,
            height: 45,
            child: Row(
              children: <Widget>[
                Expanded(
                  child: ButtonDialogWidgets(
                    buttonName: 'Exit',
                    buttonColor: const Color(colorPrimary),
                    textColor: Colors.white,
                    onTap: () {
                      Navigator.of(context).pop();
                    },
                  ),
                  flex: 1,
                ),
              ],
            ),
          ),
        ],
      ),
    )
);