import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class Login extends StatefulWidget { const Login({super.key}); @override State<Login> createState() => _LoginState(); } class _LoginState extends State<Login> { final TextInputFormatter phoneNumberFormatter = FilteringTextInputFormatter.allow( RegExp(r'^\d{0,11}'), ); final _formKey = GlobalKey<FormState>(); final TextEditingController _nameController = TextEditingController(); final TextEditingController _phoneController = TextEditingController(); void _submitForm() { if (_formKey.currentState!.validate()) { // Perform the login action print('Form is valid'); } } @override Widget build(BuildContext context) { return Scaffold( body: Center( child: SingleChildScrollView( padding: const EdgeInsets.all(35.0), child: Form( key: _formKey, child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.stretch, children: <Widget>[ const Text( 'لطفا جهت ورود به برنامه، شماره تلفن خود را وارد نمایید', textAlign: TextAlign.right, style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, color: Colors.black87, ), ), const SizedBox(height: 20), Directionality( textDirection: TextDirection.rtl, child: TextFormField( controller: _nameController, textAlign: TextAlign.end, decoration: const InputDecoration( labelText: 'نام و نام خانوادگی', border: OutlineInputBorder(), focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.blue, width: 2.0), ), ), validator: (value) { if (value == null || value.isEmpty) { return 'لطفا نام و نام خانوادگی خود را وارد کنید'; } return null; }, ), ), const SizedBox(height: 20), Directionality( textDirection: TextDirection.rtl, child: TextFormField( controller: _phoneController, textAlign: TextAlign.end, decoration: const InputDecoration( labelText: 'شماره تلفن', border: OutlineInputBorder(), focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.blue, width: 2.0), ), ), keyboardType: TextInputType.number, inputFormatters: <TextInputFormatter>[ FilteringTextInputFormatter.digitsOnly, phoneNumberFormatter, ], validator: (value) { if (value == null || value.isEmpty) { return 'لطفا شماره تلفن خود را وارد کنید'; } else if (!RegExp(r'^09\d{9}$').hasMatch(value)) { return 'شماره تلفن باید با 09 شروع شود و 11 رقم باشد'; } return null; }, ), ), const SizedBox(height: 20), ElevatedButton( onPressed: _submitForm, style: ElevatedButton.styleFrom( backgroundColor: Colors.blue, padding: const EdgeInsets.symmetric(vertical: 16.0), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(8.0), ), textStyle: const TextStyle( fontSize: 18, color: Colors.white, ), ), child: const Text('ادامه'), ), const SizedBox(height: 20), const Text( 'با ورود و استفاده از برنامه، شما با شرایط و قوانین موافقت مینمایید.', textAlign: TextAlign.end, style: TextStyle(fontSize: 12, color: Colors.grey), ), ], ), ), ), ), ); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter