small fix, don't worry about it

This commit is contained in:
Tomas Dvorak
2026-04-10 12:05:40 +02:00
parent 7b7ed0083f
commit 5ab2773f98
55 changed files with 3240 additions and 483 deletions
@@ -3,10 +3,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../../../core/widgets/app_scaffold.dart';
import '../../../core/widgets/primary_button.dart';
import '../../../core/widgets/unit_input_field.dart';
import '../../../core/utils/validators.dart';
import '../application/auth_controller.dart';
import '../../../core/utils/unit_conversion_utils.dart';
class SignUpScreen extends ConsumerStatefulWidget {
const SignUpScreen({super.key});
@@ -21,20 +24,57 @@ class _SignUpScreenState extends ConsumerState<SignUpScreen> {
final _passwordController = TextEditingController();
final _confirmPasswordController = TextEditingController();
final _usernameController = TextEditingController();
final _ageController = TextEditingController();
Gender? _selectedGender;
bool _isLoading = false;
bool _obscurePassword = true;
bool _obscureConfirmPassword = true;
bool _showAdditionalInfo = false;
double? _heightCm;
double? _weightKg;
HeightUnit _selectedHeightUnit = HeightUnit.metric;
WeightUnit _selectedWeightUnit = WeightUnit.metric;
Future<void> _handleSignUp() async {
if (!_formKey.currentState!.validate()) return;
setState(() => _isLoading = true);
try {
final age = _ageController.text.trim().isNotEmpty
? int.tryParse(_ageController.text.trim())
: null;
await ref.read(authControllerProvider.notifier).signUpWithEmail(
_emailController.text.trim(),
_passwordController.text,
_usernameController.text.trim(),
heightCm: _heightCm,
weightKg: _weightKg,
age: age,
gender: _selectedGender,
heightUnit: _selectedHeightUnit,
weightUnit: _selectedWeightUnit,
);
// Show success message and navigate to login screen
if (mounted) {
// Mark that registration just happened for the login screen
final prefs = await SharedPreferences.getInstance();
await prefs.setBool('just_registered', true);
await prefs.setInt('registration_time', DateTime.now().millisecondsSinceEpoch);
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Account created successfully! Please check your email and verify it before signing in.'),
backgroundColor: Colors.green,
duration: Duration(seconds: 4),
),
);
// Navigate to login screen after successful registration
context.pushReplacement('/sign-in');
}
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
@@ -54,6 +94,7 @@ class _SignUpScreenState extends ConsumerState<SignUpScreen> {
_passwordController.dispose();
_confirmPasswordController.dispose();
_usernameController.dispose();
_ageController.dispose();
super.dispose();
}
@@ -234,6 +275,121 @@ class _SignUpScreenState extends ConsumerState<SignUpScreen> {
enabled: !_isLoading,
onFieldSubmitted: (_) => _handleSignUp(),
),
const SizedBox(height: 24),
// Additional optional info section
GestureDetector(
onTap: () {
setState(() {
_showAdditionalInfo = !_showAdditionalInfo;
});
},
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surface,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: Theme.of(context).colorScheme.outline.withOpacity(0.2),
),
),
child: Row(
children: [
Icon(
_showAdditionalInfo
? Icons.expand_less
: Icons.expand_more,
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.7),
),
const SizedBox(width: 12),
Expanded(
child: Text(
'Add more info for better recommendations',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
fontWeight: FontWeight.w500,
),
),
),
],
),
),
),
if (_showAdditionalInfo) ...[
const SizedBox(height: 16),
UnitInputField(
labelText: 'Height',
prefixIcon: Icons.height_outlined,
helperText: 'Optional: For personalized recommendations',
enabled: !_isLoading,
onValueChanged: (value) {
setState(() {
_heightCm = value;
});
},
onUnitChanged: (unit) {
setState(() {
_selectedHeightUnit = unit as HeightUnit;
});
},
isHeight: true,
),
const SizedBox(height: 16),
UnitInputField(
labelText: 'Weight',
prefixIcon: Icons.monitor_weight_outlined,
helperText: 'Optional: For personalized recommendations',
enabled: !_isLoading,
onValueChanged: (value) {
setState(() {
_weightKg = value;
});
},
onUnitChanged: (unit) {
setState(() {
_selectedWeightUnit = unit as WeightUnit;
});
},
isHeight: false,
),
const SizedBox(height: 16),
TextFormField(
controller: _ageController,
keyboardType: TextInputType.number,
textInputAction: TextInputAction.next,
decoration: const InputDecoration(
labelText: 'Age',
prefixIcon: Icon(Icons.cake_outlined),
helperText: 'Optional: For age-appropriate recommendations',
),
enabled: !_isLoading,
),
const SizedBox(height: 16),
DropdownButtonFormField<Gender>(
value: _selectedGender,
decoration: const InputDecoration(
labelText: 'Gender',
prefixIcon: Icon(Icons.person_outline),
helperText: 'Optional: For personalized recommendations',
),
items: const [
DropdownMenuItem(
value: Gender.male,
child: Text('Male'),
),
DropdownMenuItem(
value: Gender.female,
child: Text('Female'),
),
],
onChanged: _isLoading ? null : (Gender? value) {
setState(() {
_selectedGender = value;
});
},
),
],
const SizedBox(height: 24),
PrimaryButton(
onPressed: _handleSignUp,