Files
prosappco/lib/screens/authentication/sign_up_screen.dart
T
Lizandro GuarnizoandClaude Opus 5 8631e6f729 fix: port 7 web features and repair the endless-loading screens
Root cause behind most "stuck loading" reports: the backend changed shape
(schedules became an array, location_preferences a string) while the mobile
parser still hard-cast to Map/int. The TypeError was swallowed by a silent
catch that returned null, and screens only handled the success state, so a
parse failure rendered as a permanent spinner. Same class of bug appeared
across service lists via non-null map lookups and a total absence of
request timeouts.

Ported from prosappweb:
- in-app suggestions (POST /suggestions)
- policies/terms from GET /settings/policies
- configurable appointment length (slot_duration_minutes)
- block/unblock calendar slots (POST /services/block)
- GPS city detection on the profile (Nominatim)
- server-side professional search with haversine distance
- retry cooldown after a rejected professional application

Reliability:
- parse schedules array (day_of_week 0=Mon) and string location_preferences
- read times as wall clock, so 08:00 stays 08:00 across timezones
- carry minutes into hours in TimeOfDay.add; a minute-based step used to
  loop forever and freeze the calendar (covered by test/time_slots_test.dart)
- semver update check instead of string equality, which blocked every build
  that did not exactly match the configured version
- request timeouts across all repositories
- surface HTTP >= 400 instead of reporting failed writes as success
- error states with retry instead of an indefinite shimmer

Includes pre-existing uncommitted work from the UI redesign.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-24 16:45:42 -05:00

288 lines
11 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:prosappco/components/general_primary_button.dart';
import 'package:user_repository/user_repository.dart';
import '../../blocs/sign_up_bloc/sign_up_bloc.dart';
import '../../components/strings.dart';
import '../../components/textfield.dart';
class SignUpScreen extends StatefulWidget {
const SignUpScreen({super.key});
@override
State<SignUpScreen> createState() => _SignUpScreenState();
}
class _SignUpScreenState extends State<SignUpScreen> {
final _formKey = GlobalKey<FormState>();
final emailController = TextEditingController();
final passwordController = TextEditingController();
bool obscurePassword = true;
IconData iconPassword = CupertinoIcons.eye_fill;
final nameController = TextEditingController();
bool signUpRequired = false;
bool containsUpperCase = false;
bool containsLowerCase = false;
bool containsNumber = false;
bool containsSpecialChar = false;
bool contains8Length = false;
@override
Widget build(BuildContext context) {
final width = MediaQuery.of(context).size.width;
return BlocListener<SignUpBloc, SignUpState>(
listener: (context, state) {
if (state is SignUpSuccess) {
setState(() {
signUpRequired = false;
});
} else if (state is SignUpProcess) {
setState(() {
signUpRequired = true;
});
} else if (state is SignUpFailure) {
setState(() {
signUpRequired = false;
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(state.message)),
);
}
},
child: Column(
children: [
SizedBox(
width: double.infinity,
child: Row(
children: [
IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: const Icon(
CupertinoIcons.arrow_left,
size: 30,
),
),
Text(
'Registrate',
style: TextStyle(
// fontSize: 30,
fontSize: width * 0.08,
fontWeight: FontWeight.bold,
),
),
],
),
),
Form(
key: _formKey,
child: Center(
child: Column(
children: [
const SizedBox(height: 20),
SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: MyTextField(
controller: emailController,
hintText: 'Email',
obscureText: false,
keyboardType: TextInputType.emailAddress,
prefixIcon: const Icon(CupertinoIcons.mail_solid),
validator: (val) {
if (val!.isEmpty) {
return 'Please fill in this field';
} else if (!emailRexExp.hasMatch(val)) {
return 'Please enter a valid email';
}
return null;
}),
),
const SizedBox(height: 10),
SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: MyTextField(
controller: passwordController,
hintText: 'Password',
obscureText: obscurePassword,
keyboardType: TextInputType.visiblePassword,
prefixIcon: const Icon(CupertinoIcons.lock_fill),
onChanged: (val) {
if (val!.contains(RegExp(r'[A-Z]'))) {
setState(() {
containsUpperCase = true;
});
} else {
setState(() {
containsUpperCase = false;
});
}
if (val.contains(RegExp(r'[a-z]'))) {
setState(() {
containsLowerCase = true;
});
} else {
setState(() {
containsLowerCase = false;
});
}
if (val.contains(RegExp(r'[0-9]'))) {
setState(() {
containsNumber = true;
});
} else {
setState(() {
containsNumber = false;
});
}
if (val.contains(specialCharRexExp)) {
setState(() {
containsSpecialChar = true;
});
} else {
setState(() {
containsSpecialChar = false;
});
}
if (val.length >= 8) {
setState(() {
contains8Length = true;
});
} else {
setState(() {
contains8Length = false;
});
}
return null;
},
suffixIcon: IconButton(
onPressed: () {
setState(() {
obscurePassword = !obscurePassword;
if (obscurePassword) {
iconPassword = CupertinoIcons.eye_fill;
} else {
iconPassword = CupertinoIcons.eye_slash_fill;
}
});
},
icon: Icon(iconPassword),
),
validator: (val) {
if (val!.isEmpty) {
return 'Please fill in this field';
} else if (!passwordRexExp.hasMatch(val)) {
return 'Please enter a valid password';
}
return null;
}),
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"⚈ 1 uppercase",
style: TextStyle(
color: containsUpperCase
? Colors.green
: Theme.of(context)
.colorScheme
.onBackground),
),
Text(
"⚈ 1 lowercase",
style: TextStyle(
color: containsLowerCase
? Colors.green
: Theme.of(context)
.colorScheme
.onBackground),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"⚈ 8 minimum character",
style: TextStyle(
color: contains8Length
? Colors.green
: Theme.of(context)
.colorScheme
.onBackground),
),
Text(
"⚈ 1 number",
style: TextStyle(
color: containsNumber
? Colors.green
: Theme.of(context)
.colorScheme
.onBackground),
),
],
),
],
),
const SizedBox(height: 10),
SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: MyTextField(
labelText: 'Nombre',
controller: nameController,
hintText: 'Ingresa tu nombre',
obscureText: false,
keyboardType: TextInputType.name,
prefixIcon: const Icon(CupertinoIcons.person_fill),
validator: (val) {
if (val!.isEmpty) {
return 'Please fill in this field';
} else if (val.length > 30) {
return 'Name too long';
}
return null;
},),
),
SizedBox(height: MediaQuery.of(context).size.height * 0.02),
!signUpRequired
? SizedBox(
width: MediaQuery.of(context).size.width * 0.5,
child: GeneralPrimaryButton(
label: 'Registrarme',
onPressed: () {
if (_formKey.currentState!.validate()) {
MyUser myUser = MyUser.empty;
myUser = myUser.copyWith(
email: emailController.text,
name: nameController.text,
);
setState(() {
context.read<SignUpBloc>().add(SignUpRequired(
myUser, passwordController.text));
});
}
},
),
)
: const CircularProgressIndicator(),
],
),
),
),
],
),
);
}
}