import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:first/Login/login2.dart'; import 'package:first/Login/component/api_service.dart'; String SendPhone = ""; String OTP1 = ""; String userStatus2 = ""; class Login extends StatefulWidget { const Login({Key? key}) : super(key: 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() async { if (_formKey.currentState!.validate()) { var name = _nameController.text; var phone = _phoneController.text; var jsonResponse = await ApiService.login(name, phone); if (jsonResponse != null) { var userStatus = jsonResponse['USER STATUS']; var otp = jsonResponse['otp']; OTP1 = otp; userStatus2 = userStatus; SendPhone = phone; print("otp"); print(otp); if (userStatus == '0' || userStatus == '1') { Navigator.push( context, MaterialPageRoute(builder: (context) => Login2()), ); } else { print('Unknown user status: $userStatus'); } } } } @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), 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), ), ], ), ), ), ), ); } } class MainPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Main Page'), ), body: const Center( child: Text('Welcome to Main Page'), ), ); } }
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