如何在 flutter 中使用 GetX 创建带有文本字段的警报对话框

Ven*_*amy 6 dialog flutter flutter-getx

我可以使用Get.defaultDialog()函数创建弹出对话框。我在 GetX 中找不到用于创建自定义警报对话框的方法。

我正在使用下面的函数来实现使用本机 flutter showDialog api 的函数。

showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
              content: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  TextField(
                    controller: categoryNameController,
                    keyboardType: TextInputType.text,
                    maxLines: 1,
                    decoration: InputDecoration(
                        labelText: 'Category Name',
                        hintMaxLines: 1,
                        border: OutlineInputBorder(
                            borderSide:
                                BorderSide(color: Colors.green, width: 4.0))),
                  ),
                  SizedBox(
                    height: 30.0,
                  ),
                  RaisedButton(
                    onPressed: () {
                      if (categoryNameController.text.isNotEmpty) {
                        var expenseCategory = ExpenseCategory(
                            categoryNameController.text,
                            id: _addExpenseController.expenseCategories.length);
                        _expenseController.addExpenseCategory(expenseCategory);
                        _addExpenseController.expenseCategories
                            .add(expenseCategory);
                        Get.back();
                      }
                    },
                    child: Text(
                      'ADD CATEGORY',
                      style: TextStyle(color: Colors.white, fontSize: 16.0),
                    ),
                    color: Colors.redAccent,
                  )
                ],
              ),
              elevation: 12.0,
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(10.0)));
        });
Run Code Online (Sandbox Code Playgroud)

Ven*_*amy 8

我可以使用下面的函数来实现这一点

Get.defaultDialog(
      title: '',
        content: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            TextField(
              controller: settingsScreenController.categoryNameController,
              keyboardType: TextInputType.text,
              maxLines: 1,
              decoration: InputDecoration(
                  labelText: 'Category Name',
                  hintMaxLines: 1,
                  border: OutlineInputBorder(
                      borderSide: BorderSide(color: Colors.green, width: 4.0))),
            ),
            SizedBox(
              height: 30.0,
            ),
            RaisedButton(
              onPressed: () {
                if (settingsScreenController
                    .categoryNameController.text.isNotEmpty) {
                  var expenseCategory = ExpenseCategory(
                      settingsScreenController.categoryNameController.text,
                      id: _addExpenseController.expenseCategories.length);
                  settingsScreenController.addExpenseCategory(expenseCategory);
                  _addExpenseController.expenseCategories.add(expenseCategory);
                  Get.back();
                } else {
                  Utils.showSnackBar("Enter category name");
                }
              },
              child: Text(
                'ADD CATEGORY',
                style: TextStyle(color: Colors.white, fontSize: 16.0),
              ),
              color: Colors.redAccent,
            )
          ],
        ),
        radius: 10.0);
Run Code Online (Sandbox Code Playgroud)

但我无法删除对话框中的标题区域。

没有标题的本机 API 对话框

在此输入图像描述

带标题的 GetX 对话框 api 在此输入图像描述

  • `titleStyle: TextStyle(fontSize: 0)` 应该删除标题空间 (8认同)