“Forme de flottement avec validation” Réponses codées

Validation de la forme de flottement

final _formKey = GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    // Build a Form widget using the _formKey created above.
    return Form(
      key: _formKey,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          TextFormField(
            // The validator receives the text that the user has entered.
            validator: (value) {
              if (value == null || value.isEmpty) {
                return 'Please enter some text';
              }
              return null;
            },
          ),
          Padding(
            padding: const EdgeInsets.symmetric(vertical: 16.0),
            child: ElevatedButton(
              onPressed: () {
                // Validate returns true if the form is valid, or false otherwise.
                if (_formKey.currentState!.validate()) {
                  // If the form is valid, display a snackbar. In the real world,
                  // you'd often call a server or save the information in a database.
                  ScaffoldMessenger.of(context).showSnackBar(
                    const SnackBar(content: Text('Processing Data')),
                  );
                }
              },
              child: const Text('Submit'),
            ),
          ),
        ],
      ),
    );
Sore Seahorse

validation d'entrée de flottement


// First Add this 4 line to create contoller

final TextEditingController _emailController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();

String get _email => _emailController.text;
String get _password => _passwordController.text;

//Validator

bool submitEnabled =
        _email.isNotEmpty && _password.isNotEmpty && (_password.length >= 5);
        
//*****************
// Inputs ***set as you want

TextField(
          controller: _passwordController,
           onChanged: (email) => _updateState(),
           )

TextField(
          controller: _emailController,
           onChanged: password => _updateState(),
           )
//****************

// for Button
onPressed: submitEnabled ? _submit : null,

//check textinput state every change for the enable button
 _updateState() {
    setState(() {});
  }
Dineth S

Forme de flottement avec validation

/*** testing ***/
Aso Ndubuisi

Réponses similaires à “Forme de flottement avec validation”

Questions similaires à “Forme de flottement avec validation”

Plus de réponses similaires à “Forme de flottement avec validation” dans Dart

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code