134 lines
4.7 KiB
Dart
134 lines
4.7 KiB
Dart
import 'package:didvan/providers/server_data.dart';
|
|
import 'package:didvan/providers/user.dart';
|
|
import 'package:didvan/routes/routes.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';
|
|
|
|
class PasswordInput extends StatefulWidget {
|
|
const PasswordInput({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<PasswordInput> createState() => _PasswordInputState();
|
|
}
|
|
|
|
class _PasswordInputState extends State<PasswordInput> {
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final AuthenticationState state = context.read<AuthenticationState>();
|
|
return AuthenticationLayout(
|
|
// appBarTitle:
|
|
// 'ورود با ${state.username.contains('09') ? 'شماره موبایل' : 'نام کاربری'} ${state.username}',
|
|
children: [
|
|
Form(
|
|
key: _formKey,
|
|
child: DidvanTextField(
|
|
onChanged: (value) => state.password = value,
|
|
onSubmitted: (value) => _onLogin(context),
|
|
autoFocus: true,
|
|
title: 'کلمه عبور',
|
|
hintText: 'رمز عبور خود را وارد کنید.',
|
|
prefixSvgPath: 'lib/assets/icons/key.svg',
|
|
obsecureText: true,
|
|
validator: (value) => value.length < 8
|
|
? 'کلمه عبور نمیتواند از 8 کاراکتر کمتر باشد'
|
|
: null,
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: 15,
|
|
),
|
|
Center(
|
|
child: GestureDetector(
|
|
onTap: () => state.currentPageIndex++,
|
|
child: DidvanText(
|
|
'فراموشی رمز عبور',
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.titleSmall
|
|
?.copyWith(fontWeight: FontWeight.normal),
|
|
color: Theme.of(context).colorScheme.primary,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(
|
|
height: 50,
|
|
),
|
|
DidvanButton(
|
|
onPressed: () => _onLogin(context),
|
|
title: 'تایید و ادامه',
|
|
),
|
|
const SizedBox(
|
|
height: 15,
|
|
),
|
|
const SizedBox(
|
|
height: 20,
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
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: 'را میپذیرم'),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Future<void> _onLogin(BuildContext context) async {
|
|
if (!_formKey.currentState!.validate()) {
|
|
return;
|
|
}
|
|
final state = context.read<AuthenticationState>();
|
|
final userProvider = context.read<UserProvider>();
|
|
final token = await state.login(userProvider);
|
|
if (token != null) {
|
|
await ServerDataProvider.getData();
|
|
|
|
if (mounted) {
|
|
await Future.delayed(
|
|
Duration.zero,
|
|
() => Navigator.of(context)
|
|
.pushReplacementNamed(Routes.home, arguments: true));
|
|
}
|
|
}
|
|
}
|
|
}
|