D1APP-43
This commit is contained in:
parent
b3605b008c
commit
026c3a9f59
|
|
@ -8,19 +8,34 @@ import 'package:flutter/material.dart';
|
|||
import 'package:provider/provider.dart';
|
||||
|
||||
class Authentication extends StatefulWidget {
|
||||
const Authentication({Key? key}) : super(key: key);
|
||||
final bool isResetPassword;
|
||||
const Authentication({Key? key, required this.isResetPassword})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
State<Authentication> createState() => _AuthenticationState();
|
||||
}
|
||||
|
||||
class _AuthenticationState extends State<Authentication> {
|
||||
final List<Widget> _pages = const [
|
||||
UsernameInput(),
|
||||
PasswordInput(),
|
||||
Verification(),
|
||||
ResetPassword(),
|
||||
];
|
||||
late final List<Widget> _pages;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
if (widget.isResetPassword) {
|
||||
_pages = const [
|
||||
Verification(),
|
||||
ResetPassword(),
|
||||
];
|
||||
} else {
|
||||
_pages = const [
|
||||
UsernameInput(),
|
||||
PasswordInput(),
|
||||
Verification(),
|
||||
ResetPassword(),
|
||||
];
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:didvan/models/enums.dart';
|
||||
import 'package:didvan/models/view/alert_data.dart';
|
||||
import 'package:didvan/providers/core_provider.dart';
|
||||
import 'package:didvan/providers/user_provider.dart';
|
||||
import 'package:didvan/services/network/request.dart';
|
||||
import 'package:didvan/services/network/request_helper.dart';
|
||||
import 'package:didvan/utils/action_sheet.dart';
|
||||
|
|
@ -35,7 +36,7 @@ class AuthenticationState extends CoreProvier {
|
|||
}
|
||||
}
|
||||
|
||||
Future<String?> login() async {
|
||||
Future<String?> login(UserProvider userProvider) async {
|
||||
appState = AppState.isolatedBusy;
|
||||
final RequestService service = RequestService(
|
||||
RequestHelper.login,
|
||||
|
|
@ -44,8 +45,12 @@ class AuthenticationState extends CoreProvier {
|
|||
);
|
||||
await service.post();
|
||||
if (service.isSuccess && service.result['loggedIn']) {
|
||||
final token = service.result['token'];
|
||||
appState = AppState.idle;
|
||||
return service.result['token'];
|
||||
await userProvider.setAndGetToken(token: token);
|
||||
RequestService.token = token;
|
||||
await userProvider.getUserInfo();
|
||||
return token;
|
||||
} else {
|
||||
appState = AppState.failed;
|
||||
ActionSheetUtils.showAlert(AlertData(message: service.errorMessage));
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import 'package:didvan/pages/authentication/authentication_state.dart';
|
|||
import 'package:didvan/pages/authentication/widgets/authentication_layout.dart';
|
||||
import 'package:didvan/providers/user_provider.dart';
|
||||
import 'package:didvan/routes/routes.dart';
|
||||
import 'package:didvan/services/network/request.dart';
|
||||
import 'package:didvan/widgets/didvan/button.dart';
|
||||
import 'package:didvan/widgets/didvan/text.dart';
|
||||
import 'package:didvan/widgets/didvan/text_field.dart';
|
||||
|
|
@ -34,7 +33,7 @@ class _PasswordInputState extends State<PasswordInput> {
|
|||
title: 'کلمه عبور',
|
||||
hintText: 'کلمه عبور',
|
||||
obsecureText: true,
|
||||
validator: (value) => value!.length < 8
|
||||
validator: (value) => value.length < 8
|
||||
? 'کلمه عبور نمیتواند از 8 کاراکتر کمتر باشد'
|
||||
: null,
|
||||
),
|
||||
|
|
@ -67,11 +66,9 @@ class _PasswordInputState extends State<PasswordInput> {
|
|||
return;
|
||||
}
|
||||
final state = context.read<AuthenticationState>();
|
||||
final token = await state.login();
|
||||
final userProvider = context.read<UserProvider>();
|
||||
final token = await state.login(userProvider);
|
||||
if (token != null) {
|
||||
final userProvider = context.read<UserProvider>();
|
||||
await userProvider.setAndGetToken(token: token);
|
||||
RequestService.token = token;
|
||||
Navigator.of(context).pushReplacementNamed(Routes.home);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,9 +29,14 @@ class _UsernameInputState extends State<UsernameInput> {
|
|||
title: 'نام کاربری یا شماره موبایل',
|
||||
hintText: 'نام کاربری یا شماره موبایل',
|
||||
textAlign: TextAlign.center,
|
||||
validator: (value) => value!.length < 4
|
||||
? 'نام کاربری نمیتواند از 4 کاراکتر کوچکتر باشد'
|
||||
: null,
|
||||
validator: (value) {
|
||||
if (value.contains(' ')) {
|
||||
return 'نام کاربری باید بدون فاصله باشد';
|
||||
}
|
||||
if (value.length < 4) {
|
||||
return 'نام کاربری نمیتواند از 4 کاراکتر کوچکتر باشد';
|
||||
}
|
||||
},
|
||||
onChanged: (value) {
|
||||
state.username = value;
|
||||
},
|
||||
|
|
@ -56,7 +61,7 @@ class _UsernameInputState extends State<UsernameInput> {
|
|||
text: TextSpan(
|
||||
style: Theme.of(context).textTheme.caption,
|
||||
children: [
|
||||
const TextSpan(text: 'با ثبت نام و ورود به دیدوان،'),
|
||||
const TextSpan(text: 'با و ورود به دیدوان،'),
|
||||
TextSpan(
|
||||
text: ' شرایط ',
|
||||
style: Theme.of(context)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:didvan/config/theme_data.dart';
|
||||
import 'package:didvan/pages/authentication/authentication_state.dart';
|
||||
import 'package:didvan/widgets/didvan/icon_button.dart';
|
||||
import 'package:didvan/widgets/didvan/text.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
|
@ -10,28 +11,28 @@ class AuthenticationAppBar extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top + 12),
|
||||
child: Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => context.read<AuthenticationState>().currentPageIndex--,
|
||||
child: Icon(
|
||||
Icons.arrow_back,
|
||||
color: Theme.of(context).colorScheme.title,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 20,
|
||||
),
|
||||
if (title != null)
|
||||
DidvanText(
|
||||
title!,
|
||||
style: Theme.of(context).textTheme.subtitle2,
|
||||
color: Theme.of(context).colorScheme.title,
|
||||
)
|
||||
],
|
||||
),
|
||||
final state = context.read<AuthenticationState>();
|
||||
return Row(
|
||||
children: [
|
||||
DidvanIconButton(
|
||||
icon: Icons.arrow_back,
|
||||
onPressed: () {
|
||||
if (state.currentPageIndex == 0) {
|
||||
Navigator.of(context).pop();
|
||||
return;
|
||||
}
|
||||
state.currentPageIndex--;
|
||||
}),
|
||||
const SizedBox(
|
||||
width: 4,
|
||||
),
|
||||
if (title != null)
|
||||
DidvanText(
|
||||
title!,
|
||||
style: Theme.of(context).textTheme.subtitle2,
|
||||
color: Theme.of(context).colorScheme.title,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,35 +12,50 @@ class AuthenticationLayout extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: SizedBox(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
child: Column(
|
||||
children: [
|
||||
if (appBarTitle != null)
|
||||
AuthenticationAppBar(
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
if (appBarTitle != null)
|
||||
SliverAppBar(
|
||||
automaticallyImplyLeading: false,
|
||||
pinned: true,
|
||||
toolbarHeight: 56,
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
flexibleSpace: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 16,
|
||||
right: 16,
|
||||
top: MediaQuery.of(context).padding.top,
|
||||
),
|
||||
child: AuthenticationAppBar(
|
||||
title: appBarTitle,
|
||||
),
|
||||
if (appBarTitle == null)
|
||||
const SizedBox(
|
||||
height: 66,
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: 44,
|
||||
left: 100,
|
||||
right: 100,
|
||||
bottom: 40,
|
||||
),
|
||||
child: DidvanVerticalLogo(
|
||||
height: 200,
|
||||
),
|
||||
),
|
||||
...children,
|
||||
],
|
||||
),
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
top: appBarTitle == null ? 100 : 44,
|
||||
left: 100,
|
||||
right: 100,
|
||||
bottom: 40,
|
||||
),
|
||||
sliver: const SliverToBoxAdapter(
|
||||
child: DidvanVerticalLogo(
|
||||
height: 200,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
sliver: SliverFillRemaining(
|
||||
hasScrollBody: false,
|
||||
child: Column(
|
||||
children: [
|
||||
for (var i = 0; i < children.length; i++) children[i],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue