import 'package:didvan/views/authentication/authentication_state.dart'; import 'package:didvan/views/authentication/widgets/authentication_layout.dart'; import 'package:didvan/views/widgets/didvan/button.dart'; import 'package:didvan/views/widgets/didvan/text_field.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:url_launcher/url_launcher.dart'; 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: [ Form( key: _formKey, child: DidvanTextField( initialValue: state.username, title: 'نام کاربری یا شماره موبایل', hintText: 'نام کاربری یا شماره موبایل', textAlign: TextAlign.center, acceptSpace: false, onSubmitted: (value) => state.confirmUsername(), validator: (value) { if (value.contains(' ')) { return 'نام کاربری باید بدون فاصله باشد'; } if (value.length < 4) { return 'نام کاربری نمی‌تواند از 4 کاراکتر کمتر باشد'; } return null; }, onChanged: (value) { state.username = value; }, ), ), const SizedBox( height: 20, ), DidvanButton( title: 'ورود', onPressed: () { if (_formKey.currentState!.validate()) { state.confirmUsername(); } }, ), const Spacer(), Padding( padding: const EdgeInsets.symmetric(horizontal: 60), child: RichText( textAlign: TextAlign.center, text: TextSpan( style: Theme.of(context).textTheme.caption, children: [ const TextSpan(text: 'با و ورود به دیدوان،'), TextSpan( text: ' شرایط ', style: Theme.of(context) .textTheme .caption! .copyWith(color: Theme.of(context).colorScheme.primary), recognizer: TapGestureRecognizer()..onTap = _openTermsOfUse, ), const TextSpan(text: 'و\n'), TextSpan( text: ' قوانین حریم خصوصی ', style: Theme.of(context) .textTheme .caption! .copyWith(color: Theme.of(context).colorScheme.primary), recognizer: TapGestureRecognizer()..onTap = _openTermsOfUse, ), const TextSpan(text: 'را می‌پذیرم'), ], ), ), ), const SizedBox( height: 48, ), ], ); } void _openTermsOfUse() { launch('https://didvan.app/termsOfUse.html'); } }