“bentuk flutter dengan validasi” Kode Jawaban

Validasi bentuk flutter

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

Validasi input flutter


// 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

bentuk flutter dengan validasi

/*** testing ***/
Aso Ndubuisi

Jawaban yang mirip dengan “bentuk flutter dengan validasi”

Pertanyaan yang mirip dengan “bentuk flutter dengan validasi”

Lebih banyak jawaban terkait untuk “bentuk flutter dengan validasi” di Dart

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya