forked from eatvio/eatvio_app
164 lines
6.6 KiB
Dart
164 lines
6.6 KiB
Dart
import 'package:eatvio_app/core/const.dart';
|
||
import 'package:eatvio_app/core/locator_service.dart';
|
||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||
import 'package:eatvio_app/core/utils/image_constant.dart';
|
||
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
||
import 'package:eatvio_app/features/auth/presentation/bloc/auth_cubit.dart';
|
||
import 'package:eatvio_app/generated/l10n.dart';
|
||
import 'package:flutter/cupertino.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
||
import 'package:flutter_svg/flutter_svg.dart';
|
||
import 'package:go_router/go_router.dart';
|
||
import 'package:url_launcher/url_launcher.dart';
|
||
|
||
import '../bloc/auth_state.dart';
|
||
|
||
class AuthScreen extends StatefulWidget {
|
||
const AuthScreen();
|
||
|
||
@override
|
||
State<AuthScreen> createState() => _AuthScreenState();
|
||
}
|
||
|
||
class _AuthScreenState extends State<AuthScreen> {
|
||
final emailController = TextEditingController();
|
||
final passwordController = TextEditingController();
|
||
bool checkboxState = false;
|
||
bool hidePassword = true;
|
||
final authCubit = sl<AuthCubit>();
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final s = S.of(context);
|
||
FlutterNativeSplash.remove();
|
||
return BlocProvider<AuthCubit>(
|
||
create: (BuildContext context) => authCubit,
|
||
child: BlocBuilder<AuthCubit, AuthState>(
|
||
builder: (BuildContext context, AuthState state) {
|
||
return Scaffold(
|
||
appBar: AppBar(
|
||
centerTitle: true,
|
||
title: SvgPicture.asset(
|
||
ImageConstant.imgLogoEatvio,
|
||
height: 64,
|
||
fit: BoxFit.contain,
|
||
),
|
||
),
|
||
body: SafeArea(
|
||
child: Padding(
|
||
padding: EdgeInsets.all(16),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: [
|
||
Text(s.email),
|
||
const SizedBox(height: 4),
|
||
CustomTextFormField(
|
||
controller: emailController,
|
||
textInputAction: TextInputAction.next,
|
||
keyboardType: TextInputType.emailAddress,
|
||
textInputType: TextInputType.emailAddress,
|
||
hintText: 'Введите email',
|
||
),
|
||
const SizedBox(height: 16),
|
||
Text(s.password),
|
||
const SizedBox(height: 4),
|
||
CustomTextFormField(
|
||
obscureText: hidePassword,
|
||
controller: passwordController,
|
||
hintText: 'Введите пароль',
|
||
suffix: IconButton(
|
||
onPressed: () {
|
||
setState(() {
|
||
hidePassword = !hidePassword;
|
||
});
|
||
},
|
||
icon: Icon(
|
||
hidePassword ? Icons.visibility_outlined : Icons.visibility_off_outlined,
|
||
color: Colors.grey,
|
||
),
|
||
),
|
||
),
|
||
const SizedBox(height: 16),
|
||
Row(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
Text('Нет аккаунта? '),
|
||
GestureDetector(
|
||
onTap: () => GoRouter.of(context).goNamed('webViewRegistrationScreen'),
|
||
child: Text(
|
||
'Зарегистрироваться',
|
||
style: TextStyle(
|
||
color: appTheme.blueA400,
|
||
decorationColor: appTheme.blueA400,
|
||
decoration: TextDecoration.underline,
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
Spacer(),
|
||
Row(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: [
|
||
Text(
|
||
'Нажимая "Войти", Вы соглашаетесь с ',
|
||
style: TextStyle(
|
||
fontSize: 12,
|
||
),
|
||
),
|
||
GestureDetector(
|
||
onTap: () async {
|
||
await launchUrl(Uri.parse(baseUrl + '/oferta_bs.pdf'));
|
||
},
|
||
child: Text(
|
||
'Публичной офертой',
|
||
style: TextStyle(
|
||
fontSize: 12,
|
||
color: appTheme.blueA400,
|
||
decorationColor: appTheme.blueA400,
|
||
decoration: TextDecoration.underline,
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
const SizedBox(height: 16),
|
||
Container(
|
||
height: 48,
|
||
width: MediaQuery.of(context).size.width - 32,
|
||
child: FloatingActionButton.extended(
|
||
heroTag: 'authButton',
|
||
highlightElevation: 0,
|
||
elevation: 0,
|
||
focusElevation: 0,
|
||
shape: RoundedRectangleBorder(
|
||
borderRadius: BorderRadius.circular(20),
|
||
),
|
||
backgroundColor: state is AuthStateLoading ? Colors.black.withAlpha(50) : appTheme.blueA400,
|
||
onPressed: state is AuthStateLoading
|
||
? null
|
||
: () => authCubit.getTokenByCredentials(
|
||
emailController.text,
|
||
passwordController.text,
|
||
),
|
||
label: state is AuthStateLoading
|
||
? CupertinoActivityIndicator()
|
||
: Text(
|
||
'Войти',
|
||
style: theme.textTheme.titleSmall!.copyWith(color: Colors.white),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
);
|
||
},
|
||
),
|
||
);
|
||
}
|
||
}
|