【问题标题】:How to create alert dialog with text field using GetX in flutter如何在颤振中使用 GetX 创建带有文本字段的警报对话框
【发布时间】:2021-04-08 23:50:44
【问题描述】:

我可以使用 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)));
        });

【问题讨论】:

    标签: flutter dialog flutter-getx


    【解决方案1】:

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

    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);
    

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

    没有标题的原生 API 对话框

    GetX 带标题的对话框 api

    【讨论】:

    • titleStyle: TextStyle(fontSize: 0) 应该删除标题空间
    猜你喜欢
    • 1970-01-01
    • 2020-01-27
    • 2021-04-12
    • 2019-09-02
    • 2018-11-30
    • 1970-01-01
    • 1970-01-01
    • 2021-04-16
    • 2019-10-07
    相关资源
    最近更新 更多