didvan-app/lib/views/authentication/screens/username.dart

110 lines
3.9 KiB
Dart

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.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_string.dart';
// import 'package:url_launcher/url_launcher.dart';
class UsernameInput extends StatefulWidget {
const UsernameInput({
Key? key,
}) : super(key: key);
@override
State<UsernameInput> createState() => _UsernameInputState();
}
class _UsernameInputState extends State<UsernameInput> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
final AuthenticationState state = context.read<AuthenticationState>();
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;
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: DidvanText(
'نام کاربری می‌تواند شامل کاراکترهای انگلیسی و اعداد باشد.',
style: Theme.of(context).textTheme.labelSmall,
),
),
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.bodySmall,
children: [
const TextSpan(text: 'با ورود به دیدوان،'),
TextSpan(
text: ' شرایط ',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Theme.of(context).colorScheme.primary),
recognizer: TapGestureRecognizer()
..onTap = () => launchUrlString(
'https://didvan.com/terms-of-use#conditions',
mode: LaunchMode.inAppWebView),
),
const TextSpan(text: 'و\n'),
TextSpan(
text: ' قوانین حریم خصوصی ',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Theme.of(context).colorScheme.primary),
recognizer: TapGestureRecognizer()
..onTap = () => launchUrlString(
'https://didvan.com/terms-of-use#privacy',
mode: LaunchMode.inAppWebView),
),
const TextSpan(text: 'را می‌پذیرم'),
],
),
),
),
const SizedBox(
height: 48,
),
],
);
}
}