|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'app_colors.dart'; |
| 3 | + |
| 4 | +/// The master layout template for all authentication screens. |
| 5 | +/// Handles the UI skeleton, loading states, backgrounds, and responsive scrolling. |
| 6 | +class AuthLayoutTemplate extends StatelessWidget { |
| 7 | + final String title; |
| 8 | + final String subtitle; |
| 9 | + final Widget formContent; |
| 10 | + final String submitText; |
| 11 | + final VoidCallback onSubmit; |
| 12 | + final bool isLoading; |
| 13 | + final bool showSocial; |
| 14 | + final bool useCard; |
| 15 | + final Widget? customHeaderIcon; |
| 16 | + final Widget? footerContent; |
| 17 | + |
| 18 | + const AuthLayoutTemplate({ |
| 19 | + super.key, |
| 20 | + required this.title, |
| 21 | + required this.subtitle, |
| 22 | + required this.formContent, |
| 23 | + required this.submitText, |
| 24 | + required this.onSubmit, |
| 25 | + this.isLoading = false, |
| 26 | + this.showSocial = false, |
| 27 | + this.useCard = true, |
| 28 | + this.customHeaderIcon, |
| 29 | + this.footerContent, |
| 30 | + }); |
| 31 | + |
| 32 | + @override |
| 33 | + Widget build(BuildContext context) { |
| 34 | + return Scaffold( |
| 35 | + backgroundColor: AppColors.background, |
| 36 | + appBar: AppBar( |
| 37 | + backgroundColor: Colors.transparent, |
| 38 | + elevation: 0, |
| 39 | + leading: Navigator.canPop(context) |
| 40 | + ? IconButton( |
| 41 | + icon: const Icon(Icons.arrow_back, color: AppColors.primary), |
| 42 | + onPressed: () => Navigator.pop(context), |
| 43 | + ) |
| 44 | + : null, |
| 45 | + ), |
| 46 | + body: SafeArea( |
| 47 | + child: Center( |
| 48 | + child: SingleChildScrollView( |
| 49 | + padding: const EdgeInsets.fromLTRB(24.0, 16.0, 24.0, 48.0), |
| 50 | + child: Column( |
| 51 | + mainAxisAlignment: MainAxisAlignment.center, |
| 52 | + children: [ |
| 53 | + _buildHeader(), |
| 54 | + const SizedBox(height: 32), |
| 55 | + useCard ? _buildCardContainer() : _buildTransparentContainer(), |
| 56 | + const SizedBox(height: 32), |
| 57 | + if (footerContent != null) footerContent!, |
| 58 | + ], |
| 59 | + ), |
| 60 | + ), |
| 61 | + ), |
| 62 | + ), |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + Widget _buildHeader() { |
| 67 | + return Column( |
| 68 | + children: [ |
| 69 | + customHeaderIcon ?? |
| 70 | + Container( |
| 71 | + width: 80, |
| 72 | + height: 80, |
| 73 | + decoration: BoxDecoration( |
| 74 | + color: AppColors.white, |
| 75 | + borderRadius: BorderRadius.circular(24), |
| 76 | + boxShadow: [ |
| 77 | + BoxShadow( |
| 78 | + color: AppColors.primary.withOpacity(0.1), |
| 79 | + blurRadius: 20, |
| 80 | + offset: const Offset(0, 10), |
| 81 | + ), |
| 82 | + ], |
| 83 | + ), |
| 84 | + child: const Center( |
| 85 | + child: Icon(Icons.task_alt, size: 48, color: AppColors.primary), |
| 86 | + ), |
| 87 | + ), |
| 88 | + const SizedBox(height: 24), |
| 89 | + Text( |
| 90 | + title, |
| 91 | + style: const TextStyle( |
| 92 | + fontSize: 28, |
| 93 | + fontWeight: FontWeight.w800, |
| 94 | + color: AppColors.textDark, |
| 95 | + letterSpacing: -0.5, |
| 96 | + ), |
| 97 | + ), |
| 98 | + const SizedBox(height: 8), |
| 99 | + Text( |
| 100 | + subtitle, |
| 101 | + style: const TextStyle( |
| 102 | + fontSize: 14, |
| 103 | + fontWeight: FontWeight.w500, |
| 104 | + color: AppColors.textSecondary, |
| 105 | + ), |
| 106 | + textAlign: TextAlign.center, |
| 107 | + ), |
| 108 | + ], |
| 109 | + ); |
| 110 | + } |
| 111 | + |
| 112 | + Widget _buildCardContainer() { |
| 113 | + return Container( |
| 114 | + padding: const EdgeInsets.all(32), |
| 115 | + decoration: BoxDecoration( |
| 116 | + color: AppColors.white, |
| 117 | + borderRadius: BorderRadius.circular(32), |
| 118 | + boxShadow: [ |
| 119 | + BoxShadow( |
| 120 | + color: AppColors.primary.withOpacity(0.08), |
| 121 | + blurRadius: 30, |
| 122 | + offset: const Offset(0, 10), |
| 123 | + ), |
| 124 | + ], |
| 125 | + ), |
| 126 | + child: _buildFormElements(), |
| 127 | + ); |
| 128 | + } |
| 129 | + |
| 130 | + Widget _buildTransparentContainer() => _buildFormElements(); |
| 131 | + |
| 132 | + Widget _buildFormElements() { |
| 133 | + return Column( |
| 134 | + crossAxisAlignment: CrossAxisAlignment.stretch, |
| 135 | + children: [ |
| 136 | + formContent, |
| 137 | + const SizedBox(height: 16), |
| 138 | + ElevatedButton( |
| 139 | + // Disable button if loading |
| 140 | + onPressed: isLoading ? null : onSubmit, |
| 141 | + style: ElevatedButton.styleFrom( |
| 142 | + backgroundColor: AppColors.primary, |
| 143 | + disabledBackgroundColor: AppColors.primary.withOpacity(0.6), |
| 144 | + padding: const EdgeInsets.symmetric(vertical: 20), |
| 145 | + shape: RoundedRectangleBorder( |
| 146 | + borderRadius: BorderRadius.circular(16), |
| 147 | + ), |
| 148 | + elevation: isLoading ? 0 : 4, |
| 149 | + ), |
| 150 | + child: isLoading |
| 151 | + ? const SizedBox( |
| 152 | + height: 20, |
| 153 | + width: 20, |
| 154 | + child: CircularProgressIndicator( |
| 155 | + color: AppColors.white, |
| 156 | + strokeWidth: 2, |
| 157 | + ), |
| 158 | + ) |
| 159 | + : Row( |
| 160 | + mainAxisAlignment: MainAxisAlignment.center, |
| 161 | + children: [ |
| 162 | + Text( |
| 163 | + submitText, |
| 164 | + style: const TextStyle( |
| 165 | + fontSize: 16, |
| 166 | + fontWeight: FontWeight.bold, |
| 167 | + color: AppColors.white, |
| 168 | + ), |
| 169 | + ), |
| 170 | + const SizedBox(width: 8), |
| 171 | + const Icon( |
| 172 | + Icons.arrow_forward, |
| 173 | + color: AppColors.white, |
| 174 | + size: 20, |
| 175 | + ), |
| 176 | + ], |
| 177 | + ), |
| 178 | + ), |
| 179 | + if (showSocial) ...[ |
| 180 | + const SizedBox(height: 32), |
| 181 | + const Row( |
| 182 | + children: [ |
| 183 | + Expanded(child: Divider(color: AppColors.border)), |
| 184 | + Padding( |
| 185 | + padding: EdgeInsets.symmetric(horizontal: 16), |
| 186 | + child: Text( |
| 187 | + 'OR', |
| 188 | + style: TextStyle( |
| 189 | + fontSize: 10, |
| 190 | + fontWeight: FontWeight.bold, |
| 191 | + color: AppColors.textSecondary, |
| 192 | + ), |
| 193 | + ), |
| 194 | + ), |
| 195 | + Expanded(child: Divider(color: AppColors.border)), |
| 196 | + ], |
| 197 | + ), |
| 198 | + const SizedBox(height: 24), |
| 199 | + Row( |
| 200 | + children: [ |
| 201 | + Expanded( |
| 202 | + child: OutlinedButton.icon( |
| 203 | + onPressed: () {}, |
| 204 | + icon: const Icon( |
| 205 | + Icons.g_mobiledata, |
| 206 | + color: Colors.red, |
| 207 | + size: 28, |
| 208 | + ), |
| 209 | + label: const Text('Google'), |
| 210 | + ), |
| 211 | + ), |
| 212 | + const SizedBox(width: 16), |
| 213 | + Expanded( |
| 214 | + child: OutlinedButton.icon( |
| 215 | + onPressed: () {}, |
| 216 | + icon: const Icon(Icons.facebook, color: Color(0xFF1877F2)), |
| 217 | + label: const Text('Facebook'), |
| 218 | + ), |
| 219 | + ), |
| 220 | + ], |
| 221 | + ), |
| 222 | + ], |
| 223 | + ], |
| 224 | + ); |
| 225 | + } |
| 226 | +} |
0 commit comments