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