refactor: Enhance ForgotPasswordScreen and LoginOptionScreen for improved readability and maintainability by extracting widget methods and optimizing variable declarations.

This commit is contained in:
Vaibhav Surve 2025-08-02 16:54:57 +05:30
parent 9d9afe37b8
commit d799093537
2 changed files with 228 additions and 228 deletions

View File

@ -1,13 +1,12 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_lucide/flutter_lucide.dart'; import 'package:flutter_lucide/flutter_lucide.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:marco/controller/auth/forgot_password_controller.dart'; import 'package:marco/controller/auth/forgot_password_controller.dart';
import 'package:marco/helpers/widgets/my_button.dart';
import 'package:marco/helpers/widgets/my_text.dart';
import 'package:marco/helpers/services/api_endpoints.dart'; import 'package:marco/helpers/services/api_endpoints.dart';
import 'package:marco/helpers/services/storage/local_storage.dart'; import 'package:marco/helpers/services/storage/local_storage.dart';
import 'package:marco/helpers/utils/mixins/ui_mixin.dart'; import 'package:marco/helpers/utils/mixins/ui_mixin.dart';
import 'package:marco/helpers/widgets/my_button.dart';
import 'package:marco/helpers/widgets/my_text.dart';
import 'package:marco/images.dart'; import 'package:marco/images.dart';
class ForgotPasswordScreen extends StatefulWidget { class ForgotPasswordScreen extends StatefulWidget {
@ -22,10 +21,10 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen>
final ForgotPasswordController controller = final ForgotPasswordController controller =
Get.put(ForgotPasswordController()); Get.put(ForgotPasswordController());
late AnimationController _controller; late final AnimationController _controller;
late Animation<double> _logoAnimation; late final Animation<double> _logoAnimation;
bool get _isBetaEnvironment => ApiEndpoints.baseUrl.contains("stage"); final bool _isBetaEnvironment = ApiEndpoints.baseUrl.contains("stage");
bool _isLoading = false; bool _isLoading = false;
@override @override
@ -64,29 +63,9 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen>
SafeArea( SafeArea(
child: Center( child: Center(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min,
children: [ children: [
const SizedBox(height: 24), const SizedBox(height: 24),
ScaleTransition( _buildAnimatedLogo(),
scale: _logoAnimation,
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
boxShadow: const [
BoxShadow(
color: Colors.black12,
blurRadius: 10,
offset: Offset(0, 4),
),
],
),
padding: const EdgeInsets.all(20),
child: Image.asset(Images.logoDark),
),
),
const SizedBox(height: 8), const SizedBox(height: 8),
Expanded( Expanded(
child: SingleChildScrollView( child: SingleChildScrollView(
@ -96,36 +75,10 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen>
child: Column( child: Column(
children: [ children: [
const SizedBox(height: 12), const SizedBox(height: 12),
MyText( _buildWelcomeText(),
"Welcome to Marco",
fontSize: 24,
fontWeight: 800,
color: Colors.black87,
textAlign: TextAlign.center,
),
const SizedBox(height: 10),
MyText(
"Streamline Project Management\nBoost Productivity with Automation.",
fontSize: 14,
color: Colors.black54,
textAlign: TextAlign.center,
),
if (_isBetaEnvironment) ...[ if (_isBetaEnvironment) ...[
const SizedBox(height: 12), const SizedBox(height: 12),
Container( _buildBetaBadge(),
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: Colors.orangeAccent,
borderRadius: BorderRadius.circular(6),
),
child: MyText(
'BETA',
color: Colors.white,
fontWeight: 600,
fontSize: 12,
),
),
], ],
const SizedBox(height: 36), const SizedBox(height: 36),
_buildForgotCard(), _buildForgotCard(),
@ -143,6 +96,66 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen>
); );
} }
Widget _buildAnimatedLogo() {
return ScaleTransition(
scale: _logoAnimation,
child: Container(
width: 100,
height: 100,
padding: const EdgeInsets.all(20),
decoration: const BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black12,
blurRadius: 10,
offset: Offset(0, 4),
),
],
),
child: Image.asset(Images.logoDark),
),
);
}
Widget _buildWelcomeText() {
return Column(
children: [
MyText(
"Welcome to Marco",
fontSize: 24,
fontWeight: 600,
color: Colors.black87,
textAlign: TextAlign.center,
),
const SizedBox(height: 10),
MyText(
"Streamline Project Management\nBoost Productivity with Automation.",
fontSize: 14,
color: Colors.black54,
textAlign: TextAlign.center,
),
],
);
}
Widget _buildBetaBadge() {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: Colors.orangeAccent,
borderRadius: BorderRadius.circular(6),
),
child: MyText(
'BETA',
color: Colors.white,
fontWeight: 600,
fontSize: 12,
),
);
}
Widget _buildForgotCard() { Widget _buildForgotCard() {
return Container( return Container(
padding: const EdgeInsets.all(24), padding: const EdgeInsets.all(24),
@ -165,7 +178,7 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen>
MyText( MyText(
'Forgot Password', 'Forgot Password',
fontSize: 20, fontSize: 20,
fontWeight: 700, fontWeight: 600,
color: Colors.black87, color: Colors.black87,
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
@ -177,70 +190,80 @@ class _ForgotPasswordScreenState extends State<ForgotPasswordScreen>
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
const SizedBox(height: 30), const SizedBox(height: 30),
TextFormField( _buildEmailInput(),
validator: controller.basicValidator.getValidation('email'),
controller: controller.basicValidator.getController('email'),
keyboardType: TextInputType.emailAddress,
style: const TextStyle(fontSize: 14),
decoration: InputDecoration(
labelText: "Email Address",
labelStyle: const TextStyle(color: Colors.black54),
filled: true,
fillColor: Colors.grey.shade100,
prefixIcon: const Icon(LucideIcons.mail, size: 20),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
contentPadding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
),
),
const SizedBox(height: 32), const SizedBox(height: 32),
MyButton.rounded( _buildResetButton(),
onPressed: _isLoading ? null : _handleForgotPassword,
elevation: 2,
padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 16),
borderRadiusAll: 10,
backgroundColor: _isLoading
? contentTheme.brandRed.withOpacity(0.6)
: contentTheme.brandRed,
child: _isLoading
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
color: Colors.white,
strokeWidth: 2,
),
)
: MyText.bodyMedium(
'Send Reset Link',
color: Colors.white,
fontWeight: 700,
fontSize: 16,
),
),
const SizedBox(height: 20), const SizedBox(height: 20),
TextButton.icon( _buildBackButton(),
onPressed: () async => await LocalStorage.logout(),
icon: const Icon(Icons.arrow_back,
size: 18, color: Colors.redAccent),
label: MyText.bodyMedium(
'Back to Login',
color: contentTheme.brandRed,
fontWeight: 600,
fontSize: 14,
),
),
], ],
), ),
), ),
); );
} }
Widget _buildEmailInput() {
return TextFormField(
validator: controller.basicValidator.getValidation('email'),
controller: controller.basicValidator.getController('email'),
keyboardType: TextInputType.emailAddress,
style: const TextStyle(fontSize: 14),
decoration: InputDecoration(
labelText: "Email Address",
labelStyle: const TextStyle(color: Colors.black54),
filled: true,
fillColor: Colors.grey.shade100,
prefixIcon: const Icon(LucideIcons.mail, size: 20),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
contentPadding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
),
);
}
Widget _buildResetButton() {
return MyButton.rounded(
onPressed: _isLoading ? null : _handleForgotPassword,
elevation: 2,
padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 16),
borderRadiusAll: 10,
backgroundColor: _isLoading
? contentTheme.brandRed.withOpacity(0.6)
: contentTheme.brandRed,
child: _isLoading
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
color: Colors.white,
strokeWidth: 2,
),
)
: MyText.bodyMedium(
'Send Reset Link',
color: Colors.white,
fontWeight: 600,
fontSize: 16,
),
);
}
Widget _buildBackButton() {
return TextButton.icon(
onPressed: () async => await LocalStorage.logout(),
icon: const Icon(Icons.arrow_back, size: 18, color: Colors.redAccent),
label: MyText.bodyMedium(
'Back to Login',
color: contentTheme.brandRed,
fontWeight: 600,
fontSize: 14,
),
);
}
} }
// Red background using dynamic brandRed
class _RedWaveBackground extends StatelessWidget { class _RedWaveBackground extends StatelessWidget {
final Color brandRed; final Color brandRed;
const _RedWaveBackground({required this.brandRed}); const _RedWaveBackground({required this.brandRed});

View File

@ -26,9 +26,8 @@ class WelcomeScreen extends StatefulWidget {
class _WelcomeScreenState extends State<WelcomeScreen> class _WelcomeScreenState extends State<WelcomeScreen>
with SingleTickerProviderStateMixin, UIMixin { with SingleTickerProviderStateMixin, UIMixin {
late AnimationController _controller; late final AnimationController _controller;
late Animation<double> _logoAnimation; late final Animation<double> _logoAnimation;
bool get _isBetaEnvironment => ApiEndpoints.baseUrl.contains("stage"); bool get _isBetaEnvironment => ApiEndpoints.baseUrl.contains("stage");
@override @override
@ -54,42 +53,39 @@ class _WelcomeScreenState extends State<WelcomeScreen>
void _showLoginDialog(BuildContext context, LoginOption option) { void _showLoginDialog(BuildContext context, LoginOption option) {
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, // Prevent dismiss on outside tap barrierDismissible: false,
builder: (_) => Dialog( builder: (_) => Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)), shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
insetPadding: const EdgeInsets.all(24), insetPadding: const EdgeInsets.all(24),
child: SingleChildScrollView( child: SingleChildScrollView(
child: Padding( padding: const EdgeInsets.all(24),
padding: const EdgeInsets.all(24), child: ConstrainedBox(
child: ConstrainedBox( constraints: const BoxConstraints(maxWidth: 420),
constraints: const BoxConstraints(maxWidth: 420), child: Column(
child: Column( mainAxisSize: MainAxisSize.min,
mainAxisSize: MainAxisSize.min, children: [
children: [ Row(
// Row with title and close button children: [
Row( Expanded(
children: [ child: MyText(
Expanded( option == LoginOption.email
child: MyText( ? "Login with Email"
option == LoginOption.email : "Login with OTP",
? "Login with Email" fontSize: 20,
: "Login with OTP", fontWeight: 700,
fontSize: 20,
fontWeight: 700,
),
), ),
IconButton( ),
icon: const Icon(Icons.close), IconButton(
onPressed: () => Navigator.of(context).pop(), icon: const Icon(Icons.close),
), onPressed: () => Navigator.of(context).pop(),
], ),
), ],
const SizedBox(height: 20), ),
option == LoginOption.email const SizedBox(height: 20),
? EmailLoginForm() option == LoginOption.email
: const OTPLoginScreen(), ? EmailLoginForm()
], : const OTPLoginScreen(),
), ],
), ),
), ),
), ),
@ -100,6 +96,7 @@ class _WelcomeScreenState extends State<WelcomeScreen>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width; final screenWidth = MediaQuery.of(context).size.width;
final isNarrow = screenWidth < 500;
return Scaffold( return Scaffold(
body: Stack( body: Stack(
@ -110,72 +107,18 @@ class _WelcomeScreenState extends State<WelcomeScreen>
child: SingleChildScrollView( child: SingleChildScrollView(
padding: const EdgeInsets.all(24), padding: const EdgeInsets.all(24),
child: ConstrainedBox( child: ConstrainedBox(
constraints: BoxConstraints( constraints: BoxConstraints(maxWidth: isNarrow ? double.infinity : 420),
maxWidth: screenWidth < 500 ? double.infinity : 420,
),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
// Logo with circular background _buildLogo(),
ScaleTransition(
scale: _logoAnimation,
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black12,
blurRadius: 10,
offset: Offset(0, 4),
),
],
),
padding: const EdgeInsets.all(20),
child: Image.asset(Images.logoDark),
),
),
const SizedBox(height: 24), const SizedBox(height: 24),
_buildWelcomeText(),
// Welcome Text
MyText(
"Welcome to Marco",
fontSize: 26,
fontWeight: 800,
color: Colors.black87,
textAlign: TextAlign.center,
),
const SizedBox(height: 10),
MyText(
"Streamline Project Management\nBoost Productivity with Automation.",
fontSize: 14,
color: Colors.black54,
textAlign: TextAlign.center,
),
if (_isBetaEnvironment) ...[ if (_isBetaEnvironment) ...[
const SizedBox(height: 12), const SizedBox(height: 12),
Container( _buildBetaBadge(),
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: Colors.orangeAccent,
borderRadius: BorderRadius.circular(6),
),
child: MyText(
'BETA',
color: Colors.white,
fontWeight: 600,
fontSize: 12,
),
),
], ],
const SizedBox(height: 36), const SizedBox(height: 36),
_buildActionButton( _buildActionButton(
context, context,
label: "Login with Username", label: "Login with Username",
@ -196,7 +139,6 @@ class _WelcomeScreenState extends State<WelcomeScreen>
icon: LucideIcons.phone_call, icon: LucideIcons.phone_call,
option: null, option: null,
), ),
const SizedBox(height: 36), const SizedBox(height: 36),
MyText( MyText(
'App version 1.0.0', 'App version 1.0.0',
@ -214,6 +156,60 @@ class _WelcomeScreenState extends State<WelcomeScreen>
); );
} }
Widget _buildLogo() {
return ScaleTransition(
scale: _logoAnimation,
child: Container(
width: 100,
height: 100,
padding: const EdgeInsets.all(20),
decoration: const BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 10, offset: Offset(0, 4))],
),
child: Image.asset(Images.logoDark),
),
);
}
Widget _buildWelcomeText() {
return Column(
children: [
MyText(
"Welcome to Marco",
fontSize: 26,
fontWeight: 800,
color: Colors.black87,
textAlign: TextAlign.center,
),
const SizedBox(height: 10),
MyText(
"Streamline Project Management\nBoost Productivity with Automation.",
fontSize: 14,
color: Colors.black54,
textAlign: TextAlign.center,
),
],
);
}
Widget _buildBetaBadge() {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: Colors.orangeAccent,
borderRadius: BorderRadius.circular(6),
),
child: MyText(
'BETA',
color: Colors.white,
fontWeight: 600,
fontSize: 12,
),
);
}
Widget _buildActionButton( Widget _buildActionButton(
BuildContext context, { BuildContext context, {
required String label, required String label,
@ -236,9 +232,7 @@ class _WelcomeScreenState extends State<WelcomeScreen>
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: contentTheme.brandRed, backgroundColor: contentTheme.brandRed,
foregroundColor: Colors.white, foregroundColor: Colors.white,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
borderRadius: BorderRadius.circular(14),
),
elevation: 4, elevation: 4,
shadowColor: Colors.black26, shadowColor: Colors.black26,
), ),
@ -254,7 +248,7 @@ class _WelcomeScreenState extends State<WelcomeScreen>
} }
} }
/// Custom red wave background shifted lower to reduce red area at top // Red wave background painter
class _RedWaveBackground extends StatelessWidget { class _RedWaveBackground extends StatelessWidget {
final Color brandRed; final Color brandRed;
const _RedWaveBackground({required this.brandRed}); const _RedWaveBackground({required this.brandRed});
@ -270,7 +264,6 @@ class _RedWaveBackground extends StatelessWidget {
class _WavePainter extends CustomPainter { class _WavePainter extends CustomPainter {
final Color brandRed; final Color brandRed;
_WavePainter(this.brandRed); _WavePainter(this.brandRed);
@override @override
@ -284,18 +277,8 @@ class _WavePainter extends CustomPainter {
final path1 = Path() final path1 = Path()
..moveTo(0, size.height * 0.2) ..moveTo(0, size.height * 0.2)
..quadraticBezierTo( ..quadraticBezierTo(size.width * 0.25, size.height * 0.05, size.width * 0.5, size.height * 0.15)
size.width * 0.25, ..quadraticBezierTo(size.width * 0.75, size.height * 0.25, size.width, size.height * 0.1)
size.height * 0.05,
size.width * 0.5,
size.height * 0.15,
)
..quadraticBezierTo(
size.width * 0.75,
size.height * 0.25,
size.width,
size.height * 0.1,
)
..lineTo(size.width, 0) ..lineTo(size.width, 0)
..lineTo(0, 0) ..lineTo(0, 0)
..close(); ..close();
@ -303,15 +286,9 @@ class _WavePainter extends CustomPainter {
canvas.drawPath(path1, paint1); canvas.drawPath(path1, paint1);
final paint2 = Paint()..color = Colors.redAccent.withOpacity(0.15); final paint2 = Paint()..color = Colors.redAccent.withOpacity(0.15);
final path2 = Path() final path2 = Path()
..moveTo(0, size.height * 0.25) ..moveTo(0, size.height * 0.25)
..quadraticBezierTo( ..quadraticBezierTo(size.width * 0.4, size.height * 0.1, size.width, size.height * 0.2)
size.width * 0.4,
size.height * 0.1,
size.width,
size.height * 0.2,
)
..lineTo(size.width, 0) ..lineTo(size.width, 0)
..lineTo(0, 0) ..lineTo(0, 0)
..close(); ..close();