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