Commit aaea8849 authored by r.manan@eksad.com's avatar r.manan@eksad.com

widget form verifikasi

parent c46ba368
import 'package:flutter/material.dart';
class FormVerifikasi extends StatefulWidget {
const FormVerifikasi({Key? key}) : super(key: key);
@override
_FormVerifikasiState createState() => _FormVerifikasiState();
}
class _FormVerifikasiState extends State<FormVerifikasi> {
// apa aja yang mau diminta?
final _formKey = GlobalKey<FormState>();
String _userEmail = '';
String _userName = '';
String _password = '';
String _confirmPassword = '';
// Fungsi ini ke trigger ketika ada user yang pencet tombol verif
void _trySubmitForm() {
final bool? isValid = _formKey.currentState?.validate();
if (isValid == true) {
debugPrint('Everything looks good!');
debugPrint(_userEmail);
debugPrint(_userName);
debugPrint(_password);
debugPrint(_confirmPassword);
/*
lanjut buat kirim HTTP requests, atau save ke database SQL, dll.
*/
}
}
@override
Widget build(BuildContext context) {
return Container(
color: Colors.blueAccent,
alignment: Alignment.center,
child: Center(
child: Card(
margin: const EdgeInsets.symmetric(horizontal: 35),
child: Padding(
padding: const EdgeInsets.all(20),
child: Form(
key: _formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
/// Email
TextFormField(
decoration: const InputDecoration(labelText: 'Email'),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Please enter your email address';
}
// Check if the entered email has the right format
if (!RegExp(r'\S+@\S+\.\S+').hasMatch(value)) {
return 'Please enter a valid email address';
}
// Return null if the entered email is valid
return null;
},
onChanged: (value) => _userEmail = value,
),
/// username
TextFormField(
decoration: const InputDecoration(labelText: 'Username'),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'This field is required';
}
if (value.trim().length < 4) {
return 'Username must be at least 4 characters in length';
}
// Return null if the entered username is valid
return null;
},
onChanged: (value) => _userName = value,
),
/// Password
TextFormField(
decoration: const InputDecoration(labelText: 'Password'),
obscureText: true,
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'This field is required';
}
if (value.trim().length < 8) {
return 'Password must be at least 8 characters in length';
}
// Return null if the entered password is valid
return null;
},
onChanged: (value) => _password = value,
),
/// Confirm Password
TextFormField(
decoration:
const InputDecoration(labelText: 'Confirm Password'),
obscureText: true,
validator: (value) {
if (value == null || value.isEmpty) {
return 'This field is required';
}
if (value != _password) {
return 'Confimation password does not match the entered password';
}
return null;
},
onChanged: (value) => _confirmPassword = value,
),
const SizedBox(height: 20),
Container(
alignment: Alignment.centerRight,
child: OutlinedButton(
onPressed: _trySubmitForm,
child: const Text('Verification')))
],
)),
),
),
),
);
}
}
......@@ -142,6 +142,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "10.1.0"
form_field_validator:
dependency: "direct main"
description:
name: form_field_validator
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
form_validator:
dependency: "direct main"
description:
name: form_validator
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
google_fonts:
dependency: "direct main"
description:
......
......@@ -36,6 +36,9 @@ dependencies:
intl: ^0.17.0
dropdown_search: ^5.0.2
easy_sidemenu: ^0.3.1
form_validator: ^1.0.0
form_field_validator: ^1.0.1
flutter_web_plugins:
sdk: flutter
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment