D1APP-43 username validation added

This commit is contained in:
MohammadTaha Basiri 2022-01-05 14:21:49 +03:30
parent 07e009f5bd
commit ba321e4233
1 changed files with 26 additions and 13 deletions

View File

@ -6,34 +6,47 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
class UsernameInput extends StatelessWidget { class UsernameInput extends StatefulWidget {
const UsernameInput({ const UsernameInput({
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@override
State<UsernameInput> createState() => _UsernameInputState();
}
class _UsernameInputState extends State<UsernameInput> {
final _formKey = GlobalKey<FormState>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final AuthenticationState state = context.read<AuthenticationState>(); final AuthenticationState state = context.read<AuthenticationState>();
return AuthenticationLayout( return AuthenticationLayout(
children: [ children: [
DidvanTextField( Form(
initialValue: state.username, key: _formKey,
title: 'نام کاربری یا شماره موبایل', child: DidvanTextField(
hintText: 'نام کاربری یا شماره موبایل', initialValue: state.username,
textAlign: TextAlign.center, title: 'نام کاربری یا شماره موبایل',
validator: (value) => value!.length < 4 hintText: 'نام کاربری یا شماره موبایل',
? 'نام کاربری نمی‌تواند از 4 کاراکتر کوچکتر باشد' textAlign: TextAlign.center,
: null, validator: (value) => value!.length < 4
onChanged: (value) { ? 'نام کاربری نمی‌تواند از 4 کاراکتر کوچکتر باشد'
state.username = value; : null,
}, onChanged: (value) {
state.username = value;
},
),
), ),
const SizedBox( const SizedBox(
height: 20, height: 20,
), ),
DidvanButton( DidvanButton(
title: 'ورود', title: 'ورود',
onPressed: state.confirmUsername, onPressed: () {
if (_formKey.currentState!.validate()) {
state.confirmUsername();
}
},
), ),
const Spacer(), const Spacer(),
Padding( Padding(