generateEmailPasswordLogin static method
Implementation
static String generateEmailPasswordLogin(String projectName) {
return '''
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:$projectName/shared/widgets/widgets.dart';
class LoginScreen extends StatefulWidget {
const LoginScreen({Key? key}) : super(key: key);
@override
State<LoginScreen> createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
final _formKey = GlobalKey<FormState>();
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
bool _isLoading = false;
@override
void dispose() {
_emailController.dispose();
_passwordController.dispose();
super.dispose();
}
Future<void> _handleLogin() async {
if (!_formKey.currentState!.validate()) return;
setState(() => _isLoading = true);
// TODO: Implement your login logic here
await Future.delayed(const Duration(seconds: 2));
if (mounted) {
setState(() => _isLoading = false);
context.go('/');
}
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final size = MediaQuery.of(context).size;
final isTablet = size.width > 600;
return Scaffold(
body: SafeArea(
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: isTablet ? 500 : double.infinity),
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Icon(Icons.lock_outline, size: 80, color: theme.colorScheme.primary),
const SizedBox(height: 24),
Text('Welcome Back', style: theme.textTheme.displaySmall, textAlign: TextAlign.center),
const SizedBox(height: 8),
Text('Sign in with your email', style: theme.textTheme.bodyMedium, textAlign: TextAlign.center),
const SizedBox(height: 48),
AppTextField(
controller: _emailController,
label: 'Email',
hint: 'Enter your email',
prefixIcon: Icons.email_outlined,
keyboardType: TextInputType.emailAddress,
validator: (value) {
if (value == null || value.isEmpty) return 'Please enter your email';
if (!value.contains('@')) return 'Please enter a valid email';
return null;
},
),
const SizedBox(height: 16),
PasswordField(
controller: _passwordController,
label: 'Password',
hint: 'Enter your password',
validator: (value) {
if (value == null || value.isEmpty) return 'Please enter your password';
return null;
},
),
const SizedBox(height: 8),
Align(
alignment: Alignment.centerRight,
child: TextButton(
onPressed: () {},
child: const Text('Forgot Password?'),
),
),
const SizedBox(height: 24),
PrimaryButton(
text: 'Login',
isFullWidth: true,
isLoading: _isLoading,
onPressed: _handleLogin,
),
const SizedBox(height: 16),
SecondaryButton(
text: 'Create Account',
isFullWidth: true,
onPressed: () => context.push('/signup'),
),
],
),
),
),
),
),
),
);
}
}
''';
}