feat: Refactor code structure and optimize performance across multiple modules

This commit is contained in:
Achintha Isuru
2025-11-17 23:29:28 -05:00
parent 831570f2e0
commit a64cbd9edf
1508 changed files with 105319 additions and 0 deletions

View File

@@ -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),
),
],
),
)
],
);
}
}

View File

@@ -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',
);
}
}

View File

@@ -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),
],
),
),
],
),
);
}
}

View File

@@ -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,
),
);
},
),
),
],
);
}
}