dart 底部溢出11像素

ws51t4hk  于 2023-01-15  发布在  其他
关注(0)|答案(2)|浏览(159)

我有底部溢出的像素抖动时显示键盘,我尝试了SingleChildSCrollView,仍然找不到解决办法。我的目标是使Get.defaultDialog滚动。
下面是我代码:

class AddCard extends StatelessWidget {
  final homeCtrl = Get.find<HomeController>();
  AddCard({super.key});

  @override
  Widget build(BuildContext context) {
    final icons = getIcons();
    var squareWidth = Get.width - 12.0.wp;
    return Container(
      width: squareWidth / 2,
      height: squareWidth / 2,
      margin: EdgeInsets.all(3.0.wp),
      child: InkWell(
        onTap: () async {
          await Get.defaultDialog(
              titlePadding: EdgeInsets.symmetric(vertical: 5.0.wp),
              radius: 5,
              title: 'Task Type',
              content: Form(
                key: homeCtrl.formKey,
                child: Column(
                  children: [
                    Padding(
                      padding: EdgeInsets.symmetric(horizontal: 3.0.wp),
                      child: TextFormField(
                        controller: homeCtrl.editCtrl,
                        decoration: const InputDecoration(
                          border: OutlineInputBorder(),
                          labelText: 'title',
                        ),
                        validator: (value) {
                          if (value == null || value.trim().isEmpty) {
                            return 'Please enter your task title';
                          }
                          return null;
                        },
                      ),
                    ),
                    Padding(
                      padding: EdgeInsets.symmetric(vertical: 5.0.wp),
                      child: Wrap(
                        spacing: 2.0.wp,
                        children: icons
                            .map((e) => Obx(() {
                                  final index = icons.indexOf(e);
                                  return ChoiceChip(
                                    selectedColor: Colors.grey[200],
                                    pressElevation: 0,
                                    backgroundColor: Colors.white,
                                    label: e,
                                    selected: homeCtrl.chipIndex.value == index,
                                    onSelected: (bool selected) {
                                      homeCtrl.chipIndex.value =
                                          selected ? index : 0;
                                    },
                                  );
                                }))
                            .toList(),
                      ),
                    ),
                    ElevatedButton(
                      style: ElevatedButton.styleFrom(
                        backgroundColor: blue,
                        shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(20),
                        ),
                        minimumSize: const Size(150, 40),
                      ),
                      onPressed: () {
                        if (homeCtrl.formKey.currentState!.validate()) {
                          int icon =
                              icons[homeCtrl.chipIndex.value].icon!.codePoint;
                          String color =
                              icons[homeCtrl.chipIndex.value].color!.toHex();
                          var task = Task(
                            title: homeCtrl.editCtrl.text,
                            icon: icon,
                            color: color,
                          );
                        }
                      },
                      child: const Text("Confirm"),
                    ),
                  ],
                ),
              ));
        },
        child: DottedBorder(
            color: Colors.grey[400]!,
            dashPattern: const [8, 4],
            child: Center(
              child: Icon(
                Icons.add,
                size: 10.0.wp,
                color: Colors.grey,
              ),
            )),
      ),
    );
  }
}

产生错误的小部件是Get.defaultDialog()。

cvxl0en2

cvxl0en21#

我真的不能很好地理解你的问题,因为你只发布了部分代码,但尝试用SingleChildSCrollView Package 你的“脚手架体:“。
可能您在错误的位置使用了SingleChildSCrollView

xfyts7mz

xfyts7mz2#

有两种方法:
1.您可以使用"脚手架"小部件上的resizeToAvoidBottomInset属性。
1.您可以使用ListView代替Column

onTap: () async {
          await Get.defaultDialog(
                  radius: 5,
                  titlePadding: EdgeInsets.symmetric(vertical: 5.0),
                  title: Text('Task Type'),
                  content: SizedBox(
                    height: 500,//your height
                    width: 300, //your width
                    child:
                      Form(
                        child: ListView(
                          children: [
                            Expanded(
                              child: Padding(
                                padding: EdgeInsets.symmetric(horizontal: 3.0),
                                child: TextFormField(
                                  decoration: const InputDecoration(
                                    border: OutlineInputBorder(),
                                    labelText: 'title',
                                  ),
                                ),
                              ),
                            ),
                            Expanded(
                              child: Padding(
                                padding: EdgeInsets.symmetric(vertical: 5.0),
                                child: Wrap(
                                    spacing: 2.0,
                                    children: List.generate(//replace with your content
                                        100,
                                        (index) => Container( 
                                              height: 20,
                                              width: 50,
                                              padding: EdgeInsets.all(20),
                                              color: Colors.red,
                                            ))),
                              ),
                            ),
                            Expanded(
                              child: ElevatedButton(
                                style: ElevatedButton.styleFrom(
                                  backgroundColor: Colors.blue,
                                  shape: RoundedRectangleBorder(
                                    borderRadius: BorderRadius.circular(20),
                                  ),
                                  minimumSize: const Size(150, 40),
                                ),
                                onPressed: () {},
                                child: const Text("Confirm"),
                              ),
                            ),
                          ],
                        ),
                      ),

                  ),
                ),
              );

给你的对话框一个固定的高度和宽度是很重要的,在这个定义好的区域内,可以让一个可滚动的小工具工作。

相关问题