Commit d4d5d2bc authored by Dasun Madushanka's avatar Dasun Madushanka

update form

parent 6f49ad08
import 'package:DMTI_app/screens/Form/user.dart';
import 'package:flutter/material.dart';
typedef OnDelete();
class UserForm extends StatefulWidget {
final User user;
final state = _UserFormState();
final OnDelete onDelete;
UserForm({Key key, this.user, this.onDelete}) : super(key: key);
@override
_UserFormState createState() => state;
bool isValid() => state.validate();
}
class _UserFormState extends State<UserForm> {
final form = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.all(16),
child: Material(
elevation: 1,
clipBehavior: Clip.antiAlias,
borderRadius: BorderRadius.circular(8),
child: Form(
key: form,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
AppBar(
leading: Icon(Icons.verified_user),
elevation: 0,
title: Text('User Details'),
backgroundColor: Theme.of(context).accentColor,
centerTitle: true,
actions: <Widget>[
IconButton(
icon: Icon(Icons.delete),
onPressed: widget.onDelete,
)
],
),
Padding(
padding: EdgeInsets.only(left: 16, right: 16, top: 16),
child: TextFormField(
initialValue: widget.user.fullName,
onSaved: (val) => widget.user.fullName = val,
validator: (val) =>
val.length > 3 ? null : 'Full name is invalid',
decoration: InputDecoration(
labelText: 'Full Name',
hintText: 'Enter your full name',
icon: Icon(Icons.person),
isDense: true,
),
),
),
Padding(
padding: EdgeInsets.only(left: 16, right: 16, bottom: 24),
child: TextFormField(
initialValue: widget.user.email,
onSaved: (val) => widget.user.email = val,
validator: (val) =>
val.contains('@') ? null : 'Email is invalid',
decoration: InputDecoration(
labelText: 'Email Address',
hintText: 'Enter your email',
icon: Icon(Icons.email),
isDense: true,
),
),
),
Padding(
padding: EdgeInsets.only(left: 16, right: 16, top: 16),
child: TextFormField(
initialValue: widget.user.age,
onSaved: (val) => widget.user.age = val,
validator: (val) => val.length > 3 ? null : 'Age is invalid',
decoration: InputDecoration(
labelText: '4 years',
hintText: 'Enter Actual Age',
icon: Icon(Icons.child_care),
isDense: true,
),
),
),
Padding(
padding: EdgeInsets.only(left: 16, right: 16, top: 16),
child: TextFormField(
initialValue: widget.user.mentalage,
onSaved: (val) => widget.user.mentalage = val,
validator: (val) =>
val.length > 3 ? null : 'Mental age is invalid',
decoration: InputDecoration(
labelText: '4 years',
hintText: 'Enter Mental age',
icon: Icon(Icons.score),
isDense: true,
),
),
)
],
),
),
),
);
}
///form validator
bool validate() {
var valid = form.currentState.validate();
if (valid) form.currentState.save();
return valid;
}
}
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