Валидатор флаттера ничего не возвращает - PullRequest
0 голосов
/ 01 мая 2020

это мой код файла signup.dart:

это ничего не показывает что-то вроде ошибки. Но я просто хотел бы, чтобы в текстовом поле отображалась ошибка, но она ничего не показывает. Кто-нибудь может сказать, что я делаю неправильно?

import 'package:flutter/material.dart';

class SignupPage extends StatefulWidget {
  @override
  _SignupPageState createState() => _SignupPageState();
}

class _SignupPageState extends State<SignupPage> {
  final formkey = new GlobalKey<FormState>();
  registered() {
    print("validation form...$formkey");
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        resizeToAvoidBottomPadding: false,
        body: Column(crossAxisAlignment: CrossAxisAlignment.start, children: <
            Widget>[
          Container(
            child: Stack(
              children: <Widget>[
                Container(
                  padding: EdgeInsets.fromLTRB(15.0, 110.0, 0.0, 0.0),
                  child: Text(
                    'Qeydiyyat',
                    style:
                        TextStyle(fontSize: 60.0, fontWeight: FontWeight.bold),
                  ),
                ),
              ],
            ),
          ),
          SizedBox(height: 30.0),
          Container(
              padding: EdgeInsets.only(top: 35.0, left: 20.0, right: 20.0),
              child: Form(
                key: formkey,
                child: Column(
                  children: <Widget>[
                    TextFormField(
                      decoration: InputDecoration(
                          labelText: 'E-Poçt',
                          labelStyle: TextStyle(
                              fontFamily: 'Montserrat',
                              fontWeight: FontWeight.bold,
                              color: Colors.grey),
                          // hintText: 'EMAIL',
                          // hintStyle: ,
                          focusedBorder: UnderlineInputBorder(
                              borderSide: BorderSide(color: Colors.green))),
                      validator: (val) {
                        return "sea";
                      },
                    ),
                    SizedBox(height: 10.0),
                    TextFormField(
                      keyboardType: TextInputType.text,
                      decoration: InputDecoration(
                          labelText: 'Şifrə ',
                          labelStyle: TextStyle(
                              fontFamily: 'Montserrat',
                              fontWeight: FontWeight.bold,
                              color: Colors.grey),
                          focusedBorder: UnderlineInputBorder(
                              borderSide: BorderSide(color: Colors.green))),
                      obscureText: true,
                      validator: (val) {
                        return "sea";
                      },
                    ),
                    SizedBox(height: 10.0),
                    TextFormField(
                      decoration: InputDecoration(
                          labelText: 'Ad Soyad',
                          labelStyle: TextStyle(
                              fontFamily: 'Montserrat',
                              fontWeight: FontWeight.bold,
                              color: Colors.grey),
                          focusedBorder: UnderlineInputBorder(
                              borderSide: BorderSide(color: Colors.green))),
                      validator: (val) {
                        return "sea";
                      },
                    ),
                    SizedBox(height: 50.0),
                    Container(
                        height: 40.0,
                        child: RaisedButton(
                          color: Colors.blue,
                          onPressed: registered,
                          shape: RoundedRectangleBorder(
                            side: BorderSide(color: Colors.blue),
                            borderRadius: BorderRadius.circular(50),
                          ),
                          child: Center(
                            child: Text(
                              'Qeydiyyat',
                              style: TextStyle(
                                  color: Colors.white,
                                  fontWeight: FontWeight.bold,
                                  fontFamily: 'Montserrat'),
                            ),
                          ),
                        )),
                    SizedBox(height: 20.0),
                    Container(
                      height: 40.0,
                      child: RaisedButton(
                        color: Colors.red,
                        disabledColor: Colors.transparent,
                        shape: RoundedRectangleBorder(
                          side: BorderSide(color: Colors.blue),
                          borderRadius: BorderRadius.circular(50),
                        ),
                        child: InkWell(
                          onTap: () {
                            Navigator.of(context).pop();
                          },
                          child: Center(
                            child: Text('Daxil ol',
                                style: TextStyle(
                                    color: Colors.blue,
                                    fontWeight: FontWeight.bold,
                                    fontFamily: 'Montserrat')),
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              )),
        ]));
  }
}

это ничего не показывает что-то вроде ошибки. Но я просто хотел бы, чтобы в текстовом поле отображалась ошибка, но она ничего не показывает. Кто-нибудь может сказать, что я делаю неправильно?

1 Ответ

2 голосов
/ 01 мая 2020

, если вы хотите, чтобы проверка работала автоматически, установите для свойства autoValidate TextField значение true. в противном случае, если вы хотите проверить после события такие нажатия кнопки, вы можете вызвать метод validate (). Ваш метод регистрации может измениться на что-то вроде этого:

registered() {
  if (formKey.currentState.validate()) {
    //do something
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...