feat: legacy mobile apps created
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import 'package:app_links/app_links.dart';
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:krow/app.dart';
|
||||
import 'package:krow/features/auth/domain/bloc/auth_bloc.dart';
|
||||
import 'package:krow/core/application/routing/routes.gr.dart';
|
||||
|
||||
@RoutePage()
|
||||
class AuthFlowScreen extends StatefulWidget implements AutoRouteWrapper {
|
||||
const AuthFlowScreen({super.key});
|
||||
|
||||
@override
|
||||
State<AuthFlowScreen> createState() => _AuthFlowScreenState();
|
||||
|
||||
@override
|
||||
Widget wrappedRoute(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (_) => AuthBloc(),
|
||||
child: this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AuthFlowScreenState extends State<AuthFlowScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
final context = this.context;
|
||||
AppLinks().getInitialLink().then(
|
||||
(initialLink) {
|
||||
if (initialLink == null || !context.mounted) return;
|
||||
|
||||
context
|
||||
.read<AuthBloc>()
|
||||
.add(SignInWithInitialLink(initialLink: initialLink));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<AuthBloc, AuthState>(
|
||||
listener: (context, state) {
|
||||
if (state.autentificated) {
|
||||
if (state.authType == AuthType.login) {
|
||||
appRouter.replace(const SplashRoute());
|
||||
} else {
|
||||
appRouter.replace(const SignupFlowRoute());
|
||||
}
|
||||
}
|
||||
},
|
||||
child: const AutoRouter(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:krow/core/application/common/validators/phone_validator.dart';
|
||||
import 'package:krow/core/application/di/injectable.dart';
|
||||
import 'package:krow/core/sevices/auth_state_service/auth_service.dart';
|
||||
|
||||
part 'auth_event.dart';
|
||||
|
||||
part 'auth_state.dart';
|
||||
|
||||
class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
final FirebaseAuth _auth = FirebaseAuth.instance;
|
||||
String? phone;
|
||||
int? resendToken;
|
||||
String? verificationId;
|
||||
|
||||
AuthBloc() : super(AuthState()) {
|
||||
on<AuthTypeChangedEvent>(_onTypeChanged);
|
||||
on<AuthSendSmsEvent>(_onSendSms);
|
||||
on<AuthSendSmsToPhoneEvent>(_onSendSmsToCurrentPhone);
|
||||
on<AuthPhoneChangedEvent>(_onPhoneChanged);
|
||||
on<PhoneVerificationCompletedEvent>(_onPhoneVerificationCompleted);
|
||||
on<PhoneVerificationFailedEvent>(_onPhoneVerificationFailed);
|
||||
on<CodeSentEvent>(_onCodeSent);
|
||||
on<CodeAutoRetrievalTimeoutEvent>(_onCodeAutoRetrievalTimeout);
|
||||
on<AuthEventResendUpdateTimer>(_onUpdateTimer);
|
||||
on<AuthEventConfirmCode>(_onConfirmCode);
|
||||
on<SignInWithInitialLink>(_onSignInWithInitialLink);
|
||||
}
|
||||
|
||||
FutureOr<void> _onTypeChanged(
|
||||
AuthTypeChangedEvent event,
|
||||
Emitter<AuthState> emit,
|
||||
) {
|
||||
emit(state.copyWith(authType: event.authType));
|
||||
}
|
||||
|
||||
FutureOr<void> _onPhoneChanged(
|
||||
AuthPhoneChangedEvent event,
|
||||
Emitter<AuthState> emit,
|
||||
) {
|
||||
emit(state.copyWith(phoneError: null));
|
||||
}
|
||||
|
||||
Future<void> _handleSendingSmsToPhoneNumber(
|
||||
String? phone,
|
||||
Emitter<AuthState> emit,
|
||||
) async {
|
||||
if (state.resendTimeout > 0) return;
|
||||
|
||||
if (phone != null) {
|
||||
var phoneValidationResult = PhoneValidator.validate(phone);
|
||||
if (phoneValidationResult != null) {
|
||||
return emit(state.copyWith(phoneError: phoneValidationResult));
|
||||
}
|
||||
|
||||
resendToken = null;
|
||||
verificationId = null;
|
||||
this.phone = phone;
|
||||
}
|
||||
|
||||
emit(state.copyWith(isLoading: true));
|
||||
|
||||
try {
|
||||
await _auth.verifyPhoneNumber(
|
||||
forceResendingToken: resendToken,
|
||||
phoneNumber: phone,
|
||||
verificationCompleted: (PhoneAuthCredential credential) {
|
||||
add(PhoneVerificationCompletedEvent(credential));
|
||||
},
|
||||
verificationFailed: (FirebaseAuthException e) {
|
||||
add(PhoneVerificationFailedEvent(e.message));
|
||||
},
|
||||
codeSent: (String verificationId, int? resendToken) {
|
||||
this.verificationId = verificationId;
|
||||
this.resendToken = resendToken;
|
||||
add(CodeSentEvent(verificationId, resendToken));
|
||||
},
|
||||
codeAutoRetrievalTimeout: (String verificationId) {
|
||||
if (isClosed) return;
|
||||
add(CodeAutoRetrievalTimeoutEvent(verificationId));
|
||||
},
|
||||
|
||||
);
|
||||
} catch (e) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
isLoading: false,
|
||||
phoneError: 'Invalid phone number'.tr(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onSendSms(
|
||||
AuthSendSmsEvent event,
|
||||
Emitter<AuthState> emit,
|
||||
) async {
|
||||
return _handleSendingSmsToPhoneNumber(event.phone, emit);
|
||||
}
|
||||
|
||||
FutureOr<void> _onSendSmsToCurrentPhone(
|
||||
AuthSendSmsToPhoneEvent event,
|
||||
Emitter<AuthState> emit,
|
||||
) async {
|
||||
return _handleSendingSmsToPhoneNumber(
|
||||
phone = event.userPhone,
|
||||
emit,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onConfirmCode(
|
||||
AuthEventConfirmCode event,
|
||||
Emitter<AuthState> emit,
|
||||
) async {
|
||||
emit(state.copyWith(isLoading: true));
|
||||
|
||||
PhoneAuthCredential credential = PhoneAuthProvider.credential(
|
||||
verificationId: verificationId ?? '',
|
||||
smsCode: event.smsCode,
|
||||
);
|
||||
|
||||
add(PhoneVerificationCompletedEvent(credential));
|
||||
}
|
||||
|
||||
FutureOr<void> _onUpdateTimer(
|
||||
AuthEventResendUpdateTimer event,
|
||||
Emitter<AuthState> emit,
|
||||
) {
|
||||
emit(state.copyWith(
|
||||
resendTimeout: event.seconds, codeError: state.codeError));
|
||||
}
|
||||
|
||||
FutureOr<void> _onPhoneVerificationCompleted(
|
||||
PhoneVerificationCompletedEvent event,
|
||||
Emitter<AuthState> emit,
|
||||
) async {
|
||||
try {
|
||||
await _auth.signInWithCredential(event.credential);
|
||||
|
||||
emit(state.copyWith(
|
||||
isLoading: false,
|
||||
autentificated: true,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(state.copyWith(
|
||||
isLoading: false,
|
||||
codeError: 'Invalid code'.tr(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onPhoneVerificationFailed(
|
||||
PhoneVerificationFailedEvent event,
|
||||
Emitter<AuthState> emit,
|
||||
) {
|
||||
emit(state.copyWith(
|
||||
isLoading: false,
|
||||
phoneError: event.error,
|
||||
));
|
||||
}
|
||||
|
||||
FutureOr<void> _onCodeSent(
|
||||
CodeSentEvent event,
|
||||
Emitter<AuthState> emit,
|
||||
) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
needNavigateToCodeVerification: true,
|
||||
resendTimeout: 30,
|
||||
),
|
||||
);
|
||||
_startRetryTimer();
|
||||
}
|
||||
|
||||
FutureOr<void> _onCodeAutoRetrievalTimeout(
|
||||
CodeAutoRetrievalTimeoutEvent event,
|
||||
Emitter<AuthState> emit,
|
||||
) {}
|
||||
|
||||
void _startRetryTimer() {
|
||||
var current = 30;
|
||||
Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
if (current <= 0) {
|
||||
timer.cancel();
|
||||
} else {
|
||||
current--;
|
||||
if (isClosed) {
|
||||
timer.cancel();
|
||||
return;
|
||||
}
|
||||
add(AuthEventResendUpdateTimer(current));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
FutureOr<void> _onSignInWithInitialLink(
|
||||
SignInWithInitialLink event,
|
||||
Emitter<AuthState> emit,
|
||||
) async {
|
||||
try {
|
||||
await getIt<AuthService>().signInWithEmailLink(link: event.initialLink);
|
||||
|
||||
emit(
|
||||
state.copyWith(
|
||||
isLoading: false,
|
||||
autentificated: true,
|
||||
),
|
||||
);
|
||||
} catch (except) {
|
||||
log('Failed to authenticate with Initial Link', error: except);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
part of 'auth_bloc.dart';
|
||||
|
||||
@immutable
|
||||
sealed class AuthEvent {
|
||||
const AuthEvent();
|
||||
}
|
||||
|
||||
class AuthTypeChangedEvent extends AuthEvent {
|
||||
final AuthType authType;
|
||||
|
||||
const AuthTypeChangedEvent(this.authType);
|
||||
}
|
||||
|
||||
class AuthPhoneChangedEvent extends AuthEvent {
|
||||
const AuthPhoneChangedEvent();
|
||||
}
|
||||
|
||||
class AuthSendSmsEvent extends AuthEvent {
|
||||
final String? phone;
|
||||
|
||||
const AuthSendSmsEvent(this.phone);
|
||||
}
|
||||
|
||||
class AuthSendSmsToPhoneEvent extends AuthEvent {
|
||||
const AuthSendSmsToPhoneEvent(this.userPhone);
|
||||
|
||||
final String userPhone;
|
||||
}
|
||||
|
||||
class PhoneVerificationCompletedEvent extends AuthEvent {
|
||||
final PhoneAuthCredential credential;
|
||||
|
||||
const PhoneVerificationCompletedEvent(this.credential);
|
||||
}
|
||||
|
||||
class PhoneVerificationFailedEvent extends AuthEvent {
|
||||
final String? error;
|
||||
|
||||
const PhoneVerificationFailedEvent(this.error);
|
||||
}
|
||||
|
||||
class CodeSentEvent extends AuthEvent {
|
||||
final String verificationId;
|
||||
final int? resendToken;
|
||||
|
||||
const CodeSentEvent(this.verificationId, this.resendToken);
|
||||
}
|
||||
|
||||
class CodeAutoRetrievalTimeoutEvent extends AuthEvent {
|
||||
final String verificationId;
|
||||
|
||||
const CodeAutoRetrievalTimeoutEvent(this.verificationId);
|
||||
}
|
||||
|
||||
class AuthEventResendUpdateTimer extends AuthEvent {
|
||||
final int seconds;
|
||||
|
||||
const AuthEventResendUpdateTimer(this.seconds);
|
||||
}
|
||||
|
||||
class AuthEventConfirmCode extends AuthEvent {
|
||||
final String smsCode;
|
||||
|
||||
const AuthEventConfirmCode(this.smsCode);
|
||||
}
|
||||
|
||||
class SignInWithInitialLink extends AuthEvent {
|
||||
const SignInWithInitialLink({required this.initialLink});
|
||||
|
||||
final Uri initialLink;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
part of 'auth_bloc.dart';
|
||||
|
||||
enum AuthType { login, register }
|
||||
|
||||
class AuthState {
|
||||
final AuthType? authType;
|
||||
final String? phoneError;
|
||||
String? codeError;
|
||||
final bool needClearPhone;
|
||||
final bool needNavigateToCodeVerification;
|
||||
final bool isLoading;
|
||||
final bool autentificated;
|
||||
final int resendTimeout;
|
||||
|
||||
AuthState({
|
||||
this.phoneError,
|
||||
this.codeError,
|
||||
this.needClearPhone = false,
|
||||
this.needNavigateToCodeVerification = false,
|
||||
this.isLoading = false,
|
||||
this.authType,
|
||||
this.autentificated = false,
|
||||
this.resendTimeout = 0,
|
||||
});
|
||||
|
||||
AuthState copyWith({
|
||||
AuthType? authType,
|
||||
String? phoneError,
|
||||
String? codeError,
|
||||
bool? needClearPhone,
|
||||
bool? needNavigateToCodeVerification,
|
||||
bool? isLoading,
|
||||
bool? autentificated,
|
||||
int? resendTimeout,
|
||||
}) {
|
||||
return AuthState(
|
||||
authType: authType ?? this.authType,
|
||||
phoneError: phoneError,
|
||||
codeError: codeError,
|
||||
needClearPhone: needClearPhone ?? false,
|
||||
needNavigateToCodeVerification: needNavigateToCodeVerification ?? false,
|
||||
isLoading: isLoading ?? false,
|
||||
autentificated: autentificated ?? false,
|
||||
resendTimeout: resendTimeout ?? this.resendTimeout,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:krow/features/auth/domain/bloc/auth_bloc.dart';
|
||||
|
||||
@RoutePage()
|
||||
class PhoneReLoginFlowScreen extends StatelessWidget
|
||||
implements AutoRouteWrapper {
|
||||
const PhoneReLoginFlowScreen({super.key, required this.userPhone});
|
||||
|
||||
final String userPhone;
|
||||
|
||||
@override
|
||||
Widget wrappedRoute(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (_) => AuthBloc()..add(AuthSendSmsToPhoneEvent(userPhone)),
|
||||
child: this,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<AuthBloc, AuthState>(
|
||||
listenWhen: (previous, current) =>
|
||||
previous.autentificated != current.autentificated,
|
||||
listener: (context, state) {
|
||||
if (state.autentificated) context.maybePop(true);
|
||||
},
|
||||
child: const AutoRouter(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:krow/features/auth/domain/bloc/auth_bloc.dart';
|
||||
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
|
||||
import 'package:krow/core/presentation/styles/theme.dart';
|
||||
import 'package:krow/core/presentation/widgets/ui_kit/kw_app_bar.dart';
|
||||
import 'package:krow/core/presentation/widgets/ui_kit/kw_button.dart';
|
||||
import 'package:krow/core/presentation/widgets/scroll_layout_helper.dart';
|
||||
import 'package:pinput/pinput.dart';
|
||||
|
||||
@RoutePage()
|
||||
class CodeVerificationScreen extends StatefulWidget {
|
||||
const CodeVerificationScreen({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
State<CodeVerificationScreen> createState() => _CodeVerificationScreenState();
|
||||
}
|
||||
|
||||
class _CodeVerificationScreenState extends State<CodeVerificationScreen> {
|
||||
late final TapGestureRecognizer resendRecognizer;
|
||||
String code = '';
|
||||
|
||||
String _title(AuthState state) {
|
||||
switch (state.authType) {
|
||||
case AuthType.login:
|
||||
return 'Welcome Back!'.tr();
|
||||
default:
|
||||
return 'Enter Verification Code'.tr();
|
||||
}
|
||||
}
|
||||
|
||||
String get _subTitle {
|
||||
return 'Enter the 6-digit'.tr();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
resendRecognizer = TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
BlocProvider.of<AuthBloc>(context).add(const AuthSendSmsEvent(null));
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: KwAppBar(
|
||||
titleText: 'Phone Verification'.tr(),
|
||||
showNotification: false,
|
||||
),
|
||||
body: BlocBuilder<AuthBloc, AuthState>(
|
||||
builder: (context, state) {
|
||||
return ScrollLayoutHelper(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 16,
|
||||
),
|
||||
upperWidget: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Gap(20),
|
||||
Text(
|
||||
_title(state),
|
||||
style: AppTextStyles.headingH1,
|
||||
),
|
||||
const Gap(8),
|
||||
Text(
|
||||
_subTitle,
|
||||
style: AppTextStyles.bodyMediumReg
|
||||
.copyWith(color: AppColors.blackGray),
|
||||
),
|
||||
const Gap(24),
|
||||
_buildCodeInput(context, state),
|
||||
const Gap(12),
|
||||
_buildCodeControl(context, state),
|
||||
],
|
||||
),
|
||||
lowerWidget: _buildControlNavButton(context, state.authType),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildControlNavButton(BuildContext context, authType) {
|
||||
return Column(
|
||||
children: [
|
||||
KwButton.primary(
|
||||
label: 'Enter and Continue'.tr(),
|
||||
disabled: code.length != 6,
|
||||
onPressed: () {
|
||||
BlocProvider.of<AuthBloc>(context).add(AuthEventConfirmCode(code));
|
||||
},
|
||||
),
|
||||
const Gap(36),
|
||||
if (authType == AuthType.login) ...[
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
text: '${'New here?'.tr()} ',
|
||||
style: AppTextStyles.bodyMediumReg
|
||||
.copyWith(color: AppColors.blackGray),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: 'Create an account'.tr(),
|
||||
style: AppTextStyles.bodyMediumSmb,
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
BlocProvider.of<AuthBloc>(context)
|
||||
.add(const AuthTypeChangedEvent(AuthType.register));
|
||||
// context.maybePop();
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
const Gap(20),
|
||||
]
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCodeInput(BuildContext context, AuthState state) {
|
||||
final defaultPinTheme = PinTheme(
|
||||
width: 43,
|
||||
height: 52,
|
||||
textStyle: AppTextStyles.headingH1,
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: AppColors.grayStroke),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
);
|
||||
|
||||
var focusedPinTheme = defaultPinTheme.copyWith(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: AppColors.blackBlack),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
);
|
||||
|
||||
var errorPinTheme = defaultPinTheme.copyWith(
|
||||
textStyle: AppTextStyles.headingH1.copyWith(color: AppColors.statusError),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: AppColors.statusError),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
);
|
||||
|
||||
return Pinput(
|
||||
length: 6,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
onCompleted: (pin) =>
|
||||
BlocProvider.of<AuthBloc>(context).add(AuthEventConfirmCode(code)),
|
||||
onChanged: (pin) {
|
||||
setState(() {
|
||||
state.codeError = null;
|
||||
code = pin;
|
||||
});
|
||||
},
|
||||
defaultPinTheme: defaultPinTheme,
|
||||
focusedPinTheme: focusedPinTheme,
|
||||
errorPinTheme: errorPinTheme,
|
||||
forceErrorState: state.codeError != null,
|
||||
);
|
||||
}
|
||||
|
||||
_buildCodeControl(BuildContext context, AuthState state) {
|
||||
return Row(
|
||||
children: [
|
||||
if (state.codeError != null) ...[
|
||||
Expanded(
|
||||
child: Text(
|
||||
state.codeError!,
|
||||
style: AppTextStyles.bodyTinyMed
|
||||
.copyWith(color: AppColors.statusError),
|
||||
),
|
||||
),
|
||||
const Gap(24),
|
||||
],
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
if (state.codeError == null)
|
||||
TextSpan(
|
||||
text: '${'Didn`t get the code?'.tr()} ',
|
||||
style: AppTextStyles.bodyTinyMed,
|
||||
),
|
||||
TextSpan(
|
||||
text: 'Resend Code'.tr(),
|
||||
recognizer: resendRecognizer,
|
||||
style: AppTextStyles.bodyTinyMed.copyWith(
|
||||
decoration: TextDecoration.underline,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
if (state.resendTimeout > 0)
|
||||
TextSpan(
|
||||
text: ' ${'in'.tr()} ${state.resendTimeout} s',
|
||||
recognizer: resendRecognizer,
|
||||
style: AppTextStyles.bodyTinyMed.copyWith(
|
||||
decoration: TextDecoration.underline,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:krow/core/application/routing/routes.gr.dart';
|
||||
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
|
||||
import 'package:krow/core/presentation/styles/theme.dart';
|
||||
import 'package:krow/core/presentation/widgets/scroll_layout_helper.dart';
|
||||
import 'package:krow/core/presentation/widgets/ui_kit/kw_app_bar.dart';
|
||||
import 'package:krow/core/presentation/widgets/ui_kit/kw_button.dart';
|
||||
import 'package:krow/core/presentation/widgets/ui_kit/kw_phone_input.dart';
|
||||
import 'package:krow/features/auth/domain/bloc/auth_bloc.dart';
|
||||
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
|
||||
|
||||
@RoutePage()
|
||||
class PhoneVerificationScreen extends StatefulWidget {
|
||||
const PhoneVerificationScreen({super.key, required this.type});
|
||||
|
||||
final AuthType type;
|
||||
|
||||
@override
|
||||
State<PhoneVerificationScreen> createState() =>
|
||||
_PhoneVerificationScreenState();
|
||||
}
|
||||
|
||||
class _PhoneVerificationScreenState extends State<PhoneVerificationScreen> {
|
||||
late TextEditingController _phoneController;
|
||||
|
||||
String? _appBarTitle(AuthState state) {
|
||||
switch (state.authType) {
|
||||
case AuthType.login:
|
||||
return null;
|
||||
case AuthType.register:
|
||||
return 'Phone Verification'.tr();
|
||||
case null:
|
||||
return ' ';
|
||||
}
|
||||
}
|
||||
|
||||
String _title(AuthState state) {
|
||||
switch (state.authType) {
|
||||
case AuthType.login:
|
||||
return 'Welcome Back!'.tr();
|
||||
case AuthType.register:
|
||||
return "Let's Get Started!".tr();
|
||||
case null:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
String _subTitle(AuthState state) {
|
||||
switch (state.authType) {
|
||||
case AuthType.login:
|
||||
return 'Log in to find work opportunities that match your skills'.tr();
|
||||
case AuthType.register:
|
||||
return 'Verify your phone number to activate your account'.tr();
|
||||
case null:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_phoneController = TextEditingController(text: '+1');
|
||||
_phoneController.addListener(() {
|
||||
context.read<AuthBloc>().add(const AuthPhoneChangedEvent());
|
||||
});
|
||||
|
||||
_debug();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocConsumer<AuthBloc, AuthState>(listener: (context, state) {
|
||||
if (state.needClearPhone) {
|
||||
_phoneController.clear();
|
||||
}
|
||||
if (state.needNavigateToCodeVerification) {
|
||||
context.router.push(const CodeVerificationRoute());
|
||||
}
|
||||
}, builder: (context, state) {
|
||||
return ModalProgressHUD(
|
||||
inAsyncCall: state.isLoading,
|
||||
child: Scaffold(
|
||||
appBar: KwAppBar(
|
||||
titleText: _appBarTitle(state),
|
||||
showNotification: false,
|
||||
),
|
||||
body: ScrollLayoutHelper(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
|
||||
upperWidget: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Gap(20),
|
||||
Text(
|
||||
_title(state),
|
||||
style: AppTextStyles.headingH1,
|
||||
),
|
||||
const Gap(8),
|
||||
Text(
|
||||
_subTitle(state),
|
||||
style: AppTextStyles.bodyMediumReg
|
||||
.copyWith(color: AppColors.blackGray),
|
||||
),
|
||||
const Gap(24),
|
||||
KwPhoneInput(
|
||||
title: 'Phone Number'.tr(),
|
||||
controller: _phoneController,
|
||||
error: state.phoneError,
|
||||
),
|
||||
const Gap(24),
|
||||
],
|
||||
),
|
||||
lowerWidget: _buildControNavButton(context, state),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget _buildControNavButton(context, AuthState state) {
|
||||
return Column(
|
||||
children: [
|
||||
KwButton.primary(
|
||||
label:
|
||||
'${'Continue'.tr()} ${state.resendTimeout > 0 ? '${'in'.tr()} ${state.resendTimeout}' : ''}',
|
||||
disabled: _phoneController.text.isEmpty || state.resendTimeout > 0,
|
||||
onPressed: () => BlocProvider.of<AuthBloc>(context).add(
|
||||
AuthSendSmsEvent(_phoneController.text),
|
||||
),
|
||||
),
|
||||
const Gap(36),
|
||||
if (state.authType == AuthType.login) ...[
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
text: '${'New here?'.tr()} ',
|
||||
style: AppTextStyles.bodyMediumReg
|
||||
.copyWith(color: AppColors.blackGray),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: 'Create an account'.tr(),
|
||||
style: AppTextStyles.bodyMediumSmb,
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
_phoneController.text = '+1';
|
||||
BlocProvider.of<AuthBloc>(context).add(
|
||||
const AuthTypeChangedEvent(AuthType.register),
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
const Gap(20),
|
||||
]
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void _debug() {
|
||||
if (!kDebugMode) return;
|
||||
_phoneController.text = const String.fromEnvironment(
|
||||
'DEBUG_PHONE',
|
||||
defaultValue: '+1',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
|
||||
import 'package:krow/core/presentation/widgets/ui_kit/kw_button.dart';
|
||||
import 'package:krow/features/auth/domain/bloc/auth_bloc.dart';
|
||||
import 'package:krow/core/presentation/gen/assets.gen.dart';
|
||||
import 'package:krow/core/application/routing/routes.gr.dart';
|
||||
import 'package:krow/core/presentation/styles/theme.dart';
|
||||
import 'package:krow/features/auth/presentation/screens/welcome/widgets/showcase_carousel_widget.dart';
|
||||
|
||||
@RoutePage()
|
||||
class WelcomeScreen extends StatefulWidget {
|
||||
const WelcomeScreen({super.key});
|
||||
|
||||
@override
|
||||
State<WelcomeScreen> createState() => _WelcomeScreenState();
|
||||
}
|
||||
|
||||
class _WelcomeScreenState extends State<WelcomeScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.bgColorDark,
|
||||
body: Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: SvgPicture.asset(
|
||||
Assets.images.bg.path,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
SafeArea(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Gap(20),
|
||||
Center(
|
||||
child: Assets.images.logo.svg(),
|
||||
),
|
||||
const Gap(20),
|
||||
const Expanded(
|
||||
child: ShowcaseCarouselWidget(),
|
||||
),
|
||||
const Gap(36),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
'work_that_fits'.tr(),
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.headingH1.copyWith(
|
||||
color: AppColors.grayWhite,
|
||||
height: 1,
|
||||
),
|
||||
),
|
||||
const Gap(8),
|
||||
Text(
|
||||
'join_the_community'.tr(),
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTextStyles.bodyMediumReg.copyWith(
|
||||
color: AppColors.blackDarkBgBody,
|
||||
),
|
||||
),
|
||||
const Gap(36),
|
||||
KwButton.accent(
|
||||
label: 'Sign Up'.tr(),
|
||||
onPressed: () {
|
||||
context
|
||||
.read<AuthBloc>()
|
||||
.add(const AuthTypeChangedEvent(AuthType.register));
|
||||
context.pushRoute(
|
||||
PhoneVerificationRoute(type: AuthType.register));
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
KwButton.outlinedAccent(
|
||||
label: 'Log In'.tr(),
|
||||
onPressed: () {
|
||||
context
|
||||
.read<AuthBloc>()
|
||||
.add(const AuthTypeChangedEvent(AuthType.login));
|
||||
context.pushRoute(
|
||||
PhoneVerificationRoute(type: AuthType.login));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Gap(34),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import 'package:carousel_slider/carousel_slider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:krow/core/presentation/gen/assets.gen.dart';
|
||||
import 'package:krow/core/presentation/styles/theme.dart';
|
||||
|
||||
class ShowcaseCarouselWidget extends StatefulWidget {
|
||||
const ShowcaseCarouselWidget({super.key});
|
||||
|
||||
@override
|
||||
State<ShowcaseCarouselWidget> createState() => _ShowcaseCarouselWidgetState();
|
||||
}
|
||||
|
||||
class _ShowcaseCarouselWidgetState extends State<ShowcaseCarouselWidget> {
|
||||
int _currentIndex = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: CarouselSlider(
|
||||
options: CarouselOptions(
|
||||
aspectRatio: 10 / 9,
|
||||
viewportFraction: 1,
|
||||
autoPlay: true,
|
||||
autoPlayAnimationDuration: Durations.medium4,
|
||||
autoPlayInterval: const Duration(seconds: 2),
|
||||
onPageChanged: (index, _) {
|
||||
setState(() => _currentIndex = index);
|
||||
},
|
||||
),
|
||||
items: [
|
||||
for (final image in Assets.images.slider.values)
|
||||
image.image(
|
||||
fit: BoxFit.fitWidth,
|
||||
width: double.maxFinite,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Gap(20),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(
|
||||
3,
|
||||
(index) {
|
||||
return AnimatedContainer(
|
||||
duration: Durations.short4,
|
||||
width: _currentIndex == index ? 30 : 6.0,
|
||||
height: 6.0,
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: 5.0,
|
||||
),
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(20),
|
||||
),
|
||||
color: AppColors.grayWhite,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user