feat: Add optional agentTypeId field to RegisterRequest model.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:real_estate_mobile/core/constants/app_colors.dart';
|
||||
import 'package:real_estate_mobile/features/agents/data/models/agent_type.dart';
|
||||
import 'package:real_estate_mobile/features/agents/presentation/providers/agents_provider.dart';
|
||||
import 'package:real_estate_mobile/features/auth/presentation/providers/auth_provider.dart';
|
||||
import 'package:real_estate_mobile/features/auth/presentation/widgets/auth_text_field.dart';
|
||||
import 'package:real_estate_mobile/features/auth/presentation/widgets/or_divider.dart';
|
||||
@@ -22,6 +24,16 @@ class _SignupScreenState extends ConsumerState<SignupScreen> {
|
||||
String _selectedRole = 'USER';
|
||||
bool _obscurePassword = true;
|
||||
|
||||
List<AgentType> _agentTypes = [];
|
||||
String? _selectedAgentTypeId;
|
||||
bool _loadingAgentTypes = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_fetchAgentTypes();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nameController.dispose();
|
||||
@@ -30,6 +42,22 @@ class _SignupScreenState extends ConsumerState<SignupScreen> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _fetchAgentTypes() async {
|
||||
setState(() => _loadingAgentTypes = true);
|
||||
try {
|
||||
final repo = ref.read(agentsRepositoryProvider);
|
||||
final types = await repo.getAgentTypes();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_agentTypes = types;
|
||||
_loadingAgentTypes = false;
|
||||
});
|
||||
}
|
||||
} catch (_) {
|
||||
if (mounted) setState(() => _loadingAgentTypes = false);
|
||||
}
|
||||
}
|
||||
|
||||
String? _validateLocally() {
|
||||
if (_nameController.text.trim().isEmpty) {
|
||||
return 'Please enter your name';
|
||||
@@ -40,6 +68,9 @@ class _SignupScreenState extends ConsumerState<SignupScreen> {
|
||||
if (_passwordController.text.isEmpty) {
|
||||
return 'Please enter a password';
|
||||
}
|
||||
if (_selectedRole == 'AGENT' && (_selectedAgentTypeId == null || _selectedAgentTypeId!.isEmpty)) {
|
||||
return 'Please select an agent type';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -60,6 +91,7 @@ class _SignupScreenState extends ConsumerState<SignupScreen> {
|
||||
email: _emailController.text.trim(),
|
||||
password: _passwordController.text,
|
||||
role: _selectedRole,
|
||||
agentTypeId: _selectedRole == 'AGENT' ? _selectedAgentTypeId : null,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -206,19 +238,10 @@ class _SignupScreenState extends ConsumerState<SignupScreen> {
|
||||
// Role toggle
|
||||
RoleToggle(
|
||||
selectedRole: _selectedRole,
|
||||
onChanged: (role) => setState(() => _selectedRole = role),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Subtitle
|
||||
Text(
|
||||
'Enter Your Name to Continue',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w300,
|
||||
color: AppColors.primaryDark.withValues(alpha: 0.7),
|
||||
),
|
||||
onChanged: (role) => setState(() {
|
||||
_selectedRole = role;
|
||||
if (role != 'AGENT') _selectedAgentTypeId = null;
|
||||
}),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
@@ -296,6 +319,76 @@ class _SignupScreenState extends ConsumerState<SignupScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Agent type selector (only when AGENT role is selected)
|
||||
if (_selectedRole == 'AGENT') ...[
|
||||
const SizedBox(height: 16),
|
||||
Container(
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: _loadingAgentTypes
|
||||
? const Center(
|
||||
child: SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: AppColors.accentOrange,
|
||||
),
|
||||
),
|
||||
)
|
||||
: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
value: _selectedAgentTypeId,
|
||||
hint: Text(
|
||||
'Select Agent Type',
|
||||
style: TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w300,
|
||||
color: AppColors.primaryDark.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
isExpanded: true,
|
||||
icon: const Icon(
|
||||
Icons.keyboard_arrow_down,
|
||||
color: AppColors.primaryDark,
|
||||
size: 22,
|
||||
),
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: AppColors.primaryDark,
|
||||
),
|
||||
items: _agentTypes
|
||||
.map((type) => DropdownMenuItem<String>(
|
||||
value: type.id,
|
||||
child: Text(type.name),
|
||||
))
|
||||
.toList(),
|
||||
onChanged: (value) =>
|
||||
setState(() => _selectedAgentTypeId = value),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (authState.getFieldError('agentTypeId') != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6, left: 12),
|
||||
child: Text(
|
||||
authState.getFieldError('agentTypeId')!,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Fractul',
|
||||
fontSize: 12,
|
||||
color: AppColors.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Sign Up button
|
||||
|
||||
Reference in New Issue
Block a user