0

对话框无法与单子滚动视图和软键盘一起正常工作。

问题:

  1. 软键盘下的对话框设计消失了
  2. 打开软键盘时滚动无法正常工作

我的对话在这里:-

Future<void> ShowMessageDetail(
  BuildContext context, String name, String message, String date, int id) async {
txtController.text = message;
edit = false;
return showDialog(
    context: context,
    builder: (context) {
      return StatefulBuilder(
        builder: (BuildContext context, void Function(void Function()) setState) {
          return AlertDialog(
            contentPadding: EdgeInsets.only(left: 25, right: 25),
            content: Wrap(
              children: [
                Column(
                  children: [
                    Container(
                      height: 50,
                      width: double.infinity,
                      color: Colors.blue,
                      child: Center(
                          child: Text(
                        "Detail",
                        style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 20),
                      )),
                    ),
                    Column(
                      children: [
                        Padding(
                          padding: const EdgeInsets.only(top: 10, bottom: 10),
                          child: Row(
                            children: [
                              Text(
                                "Name : ",
                                style: TextStyle(
                                  color: Colors.blue,
                                ),
                              ),
                              Text(name)
                            ],
                          ),
                        ),
                        Divider(
                          color: Colors.grey,
                        ),
                        Padding(
                          padding: const EdgeInsets.only(top: 10, bottom: 8),
                          child: Row(
                            children: [
                              Text(
                                "Date : ",
                                style: TextStyle(
                                  color: Colors.blue,
                                ),
                              ),
                              Text(date.substring(0, 10))
                            ],
                          ),
                        ),
                        Divider(
                          color: Colors.grey,
                        ),
                        Padding(
                          padding: const EdgeInsets.only(top: 8, bottom: 8),
                          child: Column(
                            children: [
                              Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Align(
                                    alignment: Alignment.centerLeft,
                                    child: Text(
                                      "Message : ",
                                      style: TextStyle(
                                        color: Colors.blue,
                                      ),
                                    ),
                                  ),
                                  Row(
                                    children: [
                                      Container(
                                        decoration: BoxDecoration(
                                          color: edit ? Colors.blue : Colors.white,
                                          borderRadius: BorderRadius.circular(30),
                                          border: Border.all(color: Colors.blue, width: 2),
                                        ),
                                        child: IconButton(
                                            onPressed: () {
                                              setState(() {
                                                edit ? edit = false : edit = true;
                                              });
                                            },
                                            icon: Icon(
                                              Icons.edit_outlined,
                                              color: edit ? Colors.white : Colors.blue,
                                            )),
                                      ),
                                      Container(
                                        width: 15,
                                      ),
                                      Container(
                                        decoration: BoxDecoration(
                                          color: Colors.blue,
                                          borderRadius: BorderRadius.circular(30),
                                        ),
                                        child: IconButton(
                                            onPressed: () {
                                              copy(message);
                                            },
                                            icon: Icon(
                                              Icons.copy,
                                              color: Colors.white,
                                            )),
                                      )
                                    ],
                                  ),
                                ],
                              ),
                              ConstrainedBox(
                                constraints: BoxConstraints(
                                  maxHeight: 300,
                                ),
                                child: SingleChildScrollView(
                                  scrollDirection: Axis.vertical,
                                  child: Padding(
                                    padding: const EdgeInsets.only(top: 10),
                                    child: Container(
                                      child: TextFormField(
                                        controller: txtController,
                                        textAlign: TextAlign.justify,
                                        focusNode: contentFocus,
                                        decoration: InputDecoration.collapsed(
                                          hintText: 'Start typing...',
                                          hintStyle: TextStyle(
                                            color: Colors.grey.shade400,
                                            fontSize: 16,
                                            fontWeight: FontWeight.w500,
                                          ),
                                          border: InputBorder.none,
                                        ),
                                        enabled: edit ? true : false,
                                        maxLines: null,
                                        keyboardType: TextInputType.multiline,
                                        style: TextStyle(
                                          fontSize: 15,
                                          height: 1.2,
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              )
                            ],
                          ),
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Visibility(
                              visible: edit ? true : false,
                              child: MaterialButton(
                                onPressed: () {
                                  updateMessage(name, txtController.text.toString(), id);
                                },
                                color: Colors.blue,
                                child: Text(
                                  "Update",
                                  style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
                                ),
                              ),
                            ),
                            Container(
                              width: 15,
                            ),
                            MaterialButton(
                              onPressed: () {
                                Navigator.pop(context);
                              },
                              color: Colors.blue,
                              child: Text(
                                "Cancel",
                                style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
                              ),
                            ),
                          ],
                        )
                      ],
                    ),
                  ],
                ),
              ],
            ),
          );
        },
      );
    });
}

无法正常工作对话框(文本从对话框中消失并且滚动无法正常工作)

我使用 scrollController 进行滚动,但这不起作用。

请帮我解决我的对话框设计问题。

4

0 回答 0