标签: flutter-form-builder

Flutter:滚动到长表单验证失败的表单字段

我的应用程序中有一个表单,它足够长,可以超出屏幕,并放入 ListView 中以启用滚动。我的验证器工作正常。虽然如果验证失败的表单字段超出了屏幕,我需要将屏幕滚动到验证失败的表单字段。

我怎样才能做到这一点?

flutter flutter-form-builder

8
推荐指数
0
解决办法
576
查看次数

flutter_form_builder 以编程方式设置字段值不起作用

我正在尝试使用flutter_form_builder以编程方式设置字段的值,但它似乎不在文档中。

控制器:

class LoggedOutNicknameController extends GetxController {
  AnimationController animateController;
  bool formValid;

  final GlobalKey<FormBuilderState> formKey = GlobalKey<FormBuilderState>();

  @override
  void onInit() {}

  @override
  void onReady() {
    final box = GetStorage();
    box.erase();
    if (box.read<dynamic>('nickname') != null &&
        box.read<dynamic>('nickname') != '') {
      print(box.read<dynamic>('nickname')); // prints the value eg 'James'
      final fff = box.read<String>('nickname');
      formKey.currentState.setAttributeValue('nickname', fff);
    }
  }

  @override
  void onClose() {}

  void onFormChange() {
    formValid = formKey.currentState.validate();
  }
}
Run Code Online (Sandbox Code Playgroud)

在该代码之后应该设置该值,该值不会显示在我的文本输入中。

风景:

Expanded(
              flex: 4,
              child: FormBuilder(
                  key: controller.formKey,
                  autovalidateMode: AutovalidateMode.onUserInteraction,
                  child: Column(
                      crossAxisAlignment: …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-form-builder

7
推荐指数
1
解决办法
4882
查看次数

Flutter GetX 表单验证

我正在寻找如何在 GetX 的最佳实践中处理表单和验证的示例?有没有很好的例子,或者有人可以向我展示我们如何最好地做到这一点的例子?

forms validation flutter flutter-form-builder getx

6
推荐指数
2
解决办法
7289
查看次数

如何让 Flutter FormBuilderDateTimePicker 仅显示日期选择器

如何让 FlutterFormBuilderDateTimePicker只显示日期?下面的代码在日期选择器关闭后生成一个时间选择器,输出为:

扑动:2022-04-02 00:00:00.000

我可以利用时间来节省时间DateTime.timeonly(),但这并不能解决问题。这应该是一个仅限日期的字段。

FormBuilderDateTimePicker(
    name: 'date_established',
    format: DateFormat('dd/MM/yyyy'),
    enabled: true,
    decoration: InputDecoration(
        labelText: 'Date Established',
        labelStyle: TextStyle(
            color: Colors.white,
            fontSize: 16.0,
            fontWeight: FontWeight.normal)),
        style: TextStyle(
            color: Colors.white,
            fontSize: 16.0,
            fontWeight: FontWeight.normal),
),
Run Code Online (Sandbox Code Playgroud)

flutter flutter-form-builder flutter-datetime-picker

6
推荐指数
2
解决办法
4629
查看次数

Flutter Forms:获取错误字段列表

我们能否在验证后从 Flutter 表单中获取错误字段列表?这将帮助开发人员使用焦点节点将注意力重定向到错误的字段。

flutter flutter-form-builder

5
推荐指数
1
解决办法
2690
查看次数

Flutter 表单验证不起作用(_formKey.currentState.save())

我的登录表单验证器未按预期工作。当我将emailpassword字段留空或输入根据我设置的内容不被接受的内容时,validator会显示错误,但当我单击登录按钮时,我会被定向到登录成功页面,但情况不应该如此。我想留在登录页面,直到输入正确的值。

登录表格

class SignForm extends StatefulWidget {
  @override
  _SignFormState createState() => _SignFormState();
}

class _SignFormState extends State<SignForm> {
  // GlobalKey This uniquely identifies the Form , and allows validation of the form in a later step.
  final _formKey = GlobalKey<FormState>();
  String email, password;
  bool remember = false;
  final List<String> errors = [];

// func with named parameter
  void addError({String error}) {
    if (!errors.contains(error))
      setState(() {
        errors.add(error);
      });
  } …
Run Code Online (Sandbox Code Playgroud)

validation dart flutter flutter-form-builder

5
推荐指数
1
解决办法
2万
查看次数

错误:无法在“FormState”上调用“save”方法?因为它可能为空

Flutter 表单保存错误有一个 formKey 但我仍然收到错误

这是我的代码

class _TextFormFieldsState extends State<TextFormFields> {
  String _name = "";

  final formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return Theme(
      data: Theme.of(context).copyWith(    
          primaryColor: Colors.red,
          accentColor: Colors.purpleAccent,
          errorColor: Colors.black
      ),
      child: Scaffold(
        floatingActionButton: FloatingActionButton(
          onPressed: () {},
          child: Icon(Icons.save),
        ),
        appBar: AppBar(
          title: Text("Text Form Field"),
        ),
        body: Padding(
          padding: EdgeInsets.all(20),
          child: Form(
            key: formKey,
            autovalidateMode: AutovalidateMode.always,
            child: ListView(
              children: [
                TextFormField(
                  decoration: InputDecoration(
                    prefixIcon: Icon(Icons.account_circle),
                    hintText: "Your Name",
                    labelText: "FullName",
                    border: OutlineInputBorder(
                      borderRadius: BorderRadius.all(Radius.circular(10)),
                    ), …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-form-builder flutter-textinputfield

1
推荐指数
1
解决办法
3213
查看次数

如何使用 Flutter 将表单居中对齐?

我有一个用 Flutter 编写的程序,我想将表单居中于屏幕中间,但我无法实现。我尝试使用对齐,但我认为我没有正确使用它!有人可以帮助我吗?谢谢

class _Defini extends State<Definicoes> {

  GlobalKey<FormState> _formkey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      bottomNavigationBar:
        ...

      body: Container(
        color: Colors.amber.withOpacity(0.80),
    child: Align(
    alignment: Alignment(0, 0),
        child: Form(
          key: _formkey,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              Container(
                        width: 300,
                        height: 300,
                        child: TextFormField(
                          keyboardType: TextInputType.number,
                          decoration: InputDecoration(
                              labelText: "RaspberryPi",
                              labelStyle: TextStyle(color: Colors.white)),
                          textAlign: TextAlign.center,
                          style: TextStyle(color: Colors.white, fontSize: 25.0),
                          validator: (value) {
                            if (value.isEmpty){
                              return "Insira";
                            }
                          },
                        ),
                      ),
                      Container(
                        decoration: BoxDecoration(
                          boxShadow: [
                            BoxShadow( …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-form-builder

0
推荐指数
1
解决办法
4411
查看次数

Flutter Forms:多个小部件使用相同的 GlobalKey

我看过很多关于这个问题的帖子,但没有一个答案适用于我的情况(我想我也知道为什么)。我的 Flutter 移动应用程序中有一个登录页面,用户可以在其中注册登录或要求接收电子邮件以重置密码。对于每个功能,我都有一个Form小部件。每个表单都需要一个表单键 (a GlobalKey<FormState>)。用户可以通过IndexedStack. 在表单之间切换时收到的错误是:

The following assertion was thrown while finalizing the widget tree:
Multiple widgets used the same GlobalKey.

The key [LabeledGlobalKey<FormState>#eebb6] was used by multiple widgets. The parents of those widgets were different widgets that both had the following description:
  RegisterPage(dependencies: [_LocalizationsScope-[GlobalKey#f7403], _InheritedProviderScope<LandingPageModel>, _InheritedTheme])
A GlobalKey can only be specified on one widget at a time in the widget tree.
Run Code Online (Sandbox Code Playgroud)

现在这个问题是类似的,但解决方案不起作用,因为我需要键的类型为 …

dart flutter flutter-form-builder

0
推荐指数
1
解决办法
2731
查看次数