update
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_otp_text_field/flutter_otp_text_field.dart';
|
||||
import 'package:injector/injector.dart';
|
||||
import 'package:prosappco/blocs/auth_bloc/auth_bloc.dart';
|
||||
import 'package:prosappco/components/general_primary_button.dart';
|
||||
|
||||
class OtpAuthScreen extends StatefulWidget {
|
||||
final String phoneNumber;
|
||||
@@ -16,87 +15,67 @@ class OtpAuthScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _OtpAuthScreenState extends State<OtpAuthScreen> {
|
||||
bool _isRequestSent = false;
|
||||
late final AuthBloc authBloc;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
authBloc = Injector.appInstance.get<AuthBloc>();
|
||||
authBloc.add(AuthEventLoginOAuth(phone: widget.phoneNumber));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final authBloc = Injector.appInstance.get<AuthBloc>();
|
||||
|
||||
if (!_isRequestSent) {
|
||||
authBloc.add(AuthEventLoginOAuth(phone: widget.phoneNumber));
|
||||
_isRequestSent = true;
|
||||
}
|
||||
|
||||
return BlocProvider<AuthBloc>(
|
||||
create: (context) => authBloc,
|
||||
child: BlocConsumer<AuthBloc, AuthState>(
|
||||
listener: (context, state) {
|
||||
if (state is AuthStateSuccess) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
if (state is AuthStateVerifyOAuth) {
|
||||
if (state.isWrongCode) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('El Código es incorrecto'),
|
||||
));
|
||||
}
|
||||
} else if (state is AuthStateVerifyOAuth && state.isWrongCode) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('El Código es incorrecto'),
|
||||
));
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Scaffold(
|
||||
body: Column(children: [
|
||||
getContent(state, authBloc: authBloc),
|
||||
]),
|
||||
appBar: AppBar(
|
||||
title: const Text('Verificación de código'),
|
||||
),
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(height: MediaQuery.of(context).size.height * 0.1),
|
||||
const Text('Te enviaremos un Código de verificación a'),
|
||||
Text(
|
||||
widget.phoneNumber,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
OtpTextField(
|
||||
numberOfFields: 6,
|
||||
borderColor: const Color(0xFF512DA8),
|
||||
showFieldAsBox: true,
|
||||
onCodeChanged: (String code) {},
|
||||
onSubmit: (String verificationCode) {
|
||||
authBloc.add(AuthEventVerifyOAuth(code: verificationCode));
|
||||
},
|
||||
),
|
||||
Expanded(child: Container()),
|
||||
GeneralPrimaryButton(
|
||||
onPressed: () {},
|
||||
label: 'Continuar',
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getContent(AuthState state, {required AuthBloc authBloc}) {
|
||||
if (state is AuthStateInitial) {
|
||||
return const Text('Inicio');
|
||||
} else if (state is AuthStateProcess) {
|
||||
return Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Text('${widget.phoneNumber} - $_isRequestSent'),
|
||||
OtpTextField(
|
||||
numberOfFields: 6,
|
||||
borderColor: const Color(0xFF512DA8),
|
||||
showFieldAsBox: true,
|
||||
onCodeChanged: (String code) {},
|
||||
onSubmit: (String verificationCode) {
|
||||
authBloc.add(AuthEventVerifyOAuth(code: verificationCode));
|
||||
}, // end onSubmit
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else if (state is AuthStateVerifyOAuth) {
|
||||
return Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Text('${widget.phoneNumber} - $_isRequestSent'),
|
||||
state.isWrongCode ? const Text('❌') : const Text(''),
|
||||
OtpTextField(
|
||||
numberOfFields: 6,
|
||||
borderColor: const Color(0xFF512DA8),
|
||||
showFieldAsBox: true,
|
||||
onCodeChanged: (String code) {},
|
||||
onSubmit: (String verificationCode) {
|
||||
authBloc.add(AuthEventVerifyOAuth(code: verificationCode));
|
||||
}, // end onSubmit
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else if (state is AuthStateSuccess) {
|
||||
return const CircularProgressIndicator();
|
||||
} else if (state is AuthStateFailure) {
|
||||
return const Text('❌');
|
||||
} else {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ class _SignUpScreenState extends State<SignUpScreen> {
|
||||
return 'Name too long';
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
},),
|
||||
),
|
||||
SizedBox(height: MediaQuery.of(context).size.height * 0.02),
|
||||
!signUpRequired
|
||||
|
||||
Reference in New Issue
Block a user