bloc
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:prosappco/blocs/authentication_bloc/authentication_bloc.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
|
||||
import 'app_view.dart';
|
||||
|
||||
class MainApp extends StatelessWidget {
|
||||
final UserRepository userRepository;
|
||||
const MainApp(this.userRepository, {super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiRepositoryProvider(providers: [
|
||||
RepositoryProvider<AuthenticationBloc>(
|
||||
create: (_) => AuthenticationBloc(myUserRepository: userRepository))
|
||||
], child: const MyAppView());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
|
||||
import 'package:prosappco/blocs/sing_in_bloc/sign_in_bloc.dart';
|
||||
import 'package:prosappco/blocs/update_user_info_bloc/update_user_info_bloc.dart';
|
||||
import 'package:prosappco/screens/authentication/welcome_screen.dart';
|
||||
import 'package:prosappco/screens/home/home_screen.dart';
|
||||
import 'package:prosappco/screens/profile/profile_screen.dart';
|
||||
|
||||
import 'blocs/authentication_bloc/authentication_bloc.dart';
|
||||
|
||||
class MyAppView extends StatelessWidget {
|
||||
const MyAppView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
title: 'Prosappco',
|
||||
theme: ThemeData(
|
||||
colorScheme: const ColorScheme.light(
|
||||
background: Colors.white,
|
||||
onBackground: Colors.black,
|
||||
primary: Color.fromRGBO(66, 164, 239, 1),
|
||||
onPrimary: Colors.black,
|
||||
secondary: Color.fromRGBO(35, 108, 244, 1),
|
||||
onSecondary: Colors.white,
|
||||
tertiary: Color.fromRGBO(255, 204, 128, 1),
|
||||
error: Colors.red,
|
||||
outline: Color(0xFF424242)),
|
||||
),
|
||||
home: BlocBuilder<AuthenticationBloc, AuthenticationState>(
|
||||
builder: (context, state) {
|
||||
if (state.status == AuthenticationStatus.authenticated) {
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(
|
||||
create: (context) => SignInBloc(
|
||||
userRepository:
|
||||
context.read<AuthenticationBloc>().userRepository),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) => UpdateUserInfoBloc(
|
||||
userRepository:
|
||||
context.read<AuthenticationBloc>().userRepository),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) => MyUserBloc(
|
||||
myUserRepository:
|
||||
context.read<AuthenticationBloc>().userRepository)
|
||||
..add(GetMyUser(
|
||||
myUserId:
|
||||
context.read<AuthenticationBloc>().state.user!.uid)),
|
||||
),
|
||||
],
|
||||
child: const HomeScreen(),
|
||||
);
|
||||
} else {
|
||||
return const WelcomeScreen();
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
|
||||
part 'authentication_event.dart';
|
||||
part 'authentication_state.dart';
|
||||
|
||||
class AuthenticationBloc
|
||||
extends Bloc<AuthenticationEvent, AuthenticationState> {
|
||||
final UserRepository userRepository;
|
||||
late final StreamSubscription<User?> _userSubscription;
|
||||
|
||||
AuthenticationBloc({required UserRepository myUserRepository})
|
||||
: userRepository = myUserRepository,
|
||||
super(const AuthenticationState.unknown()) {
|
||||
_userSubscription = userRepository.user.listen((authUser) {
|
||||
add(AuthenticationUserChanged(authUser));
|
||||
});
|
||||
on<AuthenticationUserChanged>((event, emit) {
|
||||
if (event.user != null) {
|
||||
emit(AuthenticationState.authenticated(event.user!));
|
||||
} else {
|
||||
emit(const AuthenticationState.unauthenticated());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
_userSubscription.cancel();
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
part of 'authentication_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class AuthenticationEvent extends Equatable {
|
||||
const AuthenticationEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class AuthenticationUserChanged extends AuthenticationEvent {
|
||||
const AuthenticationUserChanged(this.user);
|
||||
|
||||
final User? user;
|
||||
}
|
||||
|
||||
class AuthenticationLogoutRequested extends AuthenticationEvent {}
|
||||
@@ -0,0 +1,24 @@
|
||||
part of 'authentication_bloc.dart';
|
||||
|
||||
enum AuthenticationStatus { authenticated, unauthenticated, unknown }
|
||||
|
||||
class AuthenticationState extends Equatable {
|
||||
final AuthenticationStatus status;
|
||||
final User? user;
|
||||
|
||||
const AuthenticationState._({
|
||||
this.status = AuthenticationStatus.unknown,
|
||||
this.user,
|
||||
});
|
||||
|
||||
const AuthenticationState.unknown() : this._();
|
||||
|
||||
const AuthenticationState.authenticated(User user)
|
||||
: this._(status: AuthenticationStatus.authenticated, user: user);
|
||||
|
||||
const AuthenticationState.unauthenticated()
|
||||
: this._(status: AuthenticationStatus.unauthenticated);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [status, user];
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
|
||||
part 'my_user_event.dart';
|
||||
part 'my_user_state.dart';
|
||||
|
||||
class MyUserBloc extends Bloc<MyUserEvent, MyUserState> {
|
||||
final UserRepository _userRepository;
|
||||
|
||||
MyUserBloc({required UserRepository myUserRepository})
|
||||
: _userRepository = myUserRepository,
|
||||
super(const MyUserState.loading()) {
|
||||
on<GetMyUser>(_onGetMyUser);
|
||||
}
|
||||
|
||||
void _onGetMyUser(GetMyUser event, Emitter<MyUserState> emit) async {
|
||||
emit(const MyUserState.loading());
|
||||
try {
|
||||
MyUser myUser = await _userRepository.getMyUser(event.myUserId);
|
||||
emit(MyUserState.success(myUser));
|
||||
} catch (e) {
|
||||
emit(const MyUserState.failure());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
part of 'my_user_bloc.dart';
|
||||
|
||||
abstract class MyUserEvent extends Equatable {
|
||||
const MyUserEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class GetMyUser extends MyUserEvent {
|
||||
final String myUserId;
|
||||
|
||||
const GetMyUser({required this.myUserId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [myUserId];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
part of 'my_user_bloc.dart';
|
||||
|
||||
enum MyUserStatus { success, loading, failure }
|
||||
|
||||
class MyUserState extends Equatable {
|
||||
final MyUserStatus status;
|
||||
final MyUser? user;
|
||||
|
||||
const MyUserState._({
|
||||
this.status = MyUserStatus.loading,
|
||||
this.user,
|
||||
});
|
||||
|
||||
const MyUserState.loading() : this._();
|
||||
|
||||
const MyUserState.success(MyUser user)
|
||||
: this._(status: MyUserStatus.success, user: user);
|
||||
|
||||
const MyUserState.failure() : this._(status: MyUserStatus.failure);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [status, user];
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
|
||||
part 'sign_up_event.dart';
|
||||
part 'sign_up_state.dart';
|
||||
|
||||
class SignUpBloc extends Bloc<SignUpEvent, SignUpState> {
|
||||
final UserRepository _userRepository;
|
||||
|
||||
SignUpBloc({required UserRepository userRepository})
|
||||
: _userRepository = userRepository,
|
||||
super(SignUpInitial()) {
|
||||
on<SignUpRequired>((event, emit) async {
|
||||
emit(SignUpProcess());
|
||||
try {
|
||||
MyUser user = await _userRepository.signUp(event.user, event.password);
|
||||
await _userRepository.setUserData(user);
|
||||
emit(SignUpSuccess());
|
||||
} catch (e) {
|
||||
emit(SignUpFailure());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
part of 'sign_up_bloc.dart';
|
||||
|
||||
abstract class SignUpEvent extends Equatable {
|
||||
const SignUpEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class SignUpRequired extends SignUpEvent {
|
||||
final MyUser user;
|
||||
final String password;
|
||||
|
||||
const SignUpRequired(this.user, this.password);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
part of 'sign_up_bloc.dart';
|
||||
|
||||
abstract class SignUpState extends Equatable {
|
||||
const SignUpState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class SignUpInitial extends SignUpState {}
|
||||
|
||||
class SignUpSuccess extends SignUpState {}
|
||||
|
||||
class SignUpFailure extends SignUpState {}
|
||||
|
||||
class SignUpProcess extends SignUpState {}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
|
||||
part 'sign_in_event.dart';
|
||||
part 'sign_in_state.dart';
|
||||
|
||||
class SignInBloc extends Bloc<SignInEvent, SignInState> {
|
||||
final UserRepository _userRepository;
|
||||
|
||||
SignInBloc({required UserRepository userRepository})
|
||||
: _userRepository = userRepository,
|
||||
super(SignInInitial()) {
|
||||
on<SignInRequired>((event, emit) async {
|
||||
emit(SignInProcess());
|
||||
try {
|
||||
await _userRepository.signIn(event.email, event.password);
|
||||
emit(SignInSuccess());
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
emit(const SignInFailure());
|
||||
}
|
||||
});
|
||||
on<SignOutRequired>((event, emit) async {
|
||||
await _userRepository.logOut();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
part of 'sign_in_bloc.dart';
|
||||
|
||||
abstract class SignInEvent extends Equatable {
|
||||
const SignInEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class SignInRequired extends SignInEvent {
|
||||
final String email;
|
||||
final String password;
|
||||
|
||||
const SignInRequired(this.email, this.password);
|
||||
}
|
||||
|
||||
class SignOutRequired extends SignInEvent {
|
||||
const SignOutRequired();
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
part of 'sign_in_bloc.dart';
|
||||
|
||||
@immutable
|
||||
abstract class SignInState extends Equatable {
|
||||
const SignInState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class SignInInitial extends SignInState {}
|
||||
|
||||
class SignInSuccess extends SignInState {}
|
||||
|
||||
class SignInFailure extends SignInState {
|
||||
final String? message;
|
||||
|
||||
const SignInFailure({this.message});
|
||||
}
|
||||
|
||||
class SignInProcess extends SignInState {}
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
|
||||
part 'update_user_info_event.dart';
|
||||
part 'update_user_info_state.dart';
|
||||
|
||||
class UpdateUserInfoBloc
|
||||
extends Bloc<UpdateUserInfoEvent, UpdateUserInfoState> {
|
||||
final UserRepository _userRepository;
|
||||
|
||||
UpdateUserInfoBloc({required UserRepository userRepository})
|
||||
: _userRepository = userRepository,
|
||||
super(UpdateUserInfoInitial()) {
|
||||
on<UploadPicture>(_onUploadPicture);
|
||||
}
|
||||
|
||||
void _onUploadPicture(
|
||||
UploadPicture event, Emitter<UpdateUserInfoState> emit) async {
|
||||
emit(UploadPictureLoading());
|
||||
try {
|
||||
String userImage =
|
||||
await _userRepository.uploadPicture(event.file, event.userId);
|
||||
emit(UploadPictureSuccess(userImage));
|
||||
} catch (e) {
|
||||
emit(UploadPictureFailure());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
part of 'update_user_info_bloc.dart';
|
||||
|
||||
abstract class UpdateUserInfoEvent extends Equatable {
|
||||
const UpdateUserInfoEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class UploadPicture extends UpdateUserInfoEvent {
|
||||
final String file;
|
||||
final String userId;
|
||||
|
||||
const UploadPicture(this.file, this.userId);
|
||||
|
||||
@override
|
||||
List<Object> get props => [file, userId];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
part of 'update_user_info_bloc.dart';
|
||||
|
||||
abstract class UpdateUserInfoState extends Equatable {
|
||||
const UpdateUserInfoState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class UpdateUserInfoInitial extends UpdateUserInfoState {}
|
||||
|
||||
class UploadPictureFailure extends UpdateUserInfoState {}
|
||||
|
||||
class UploadPictureLoading extends UpdateUserInfoState {}
|
||||
|
||||
class UploadPictureSuccess extends UpdateUserInfoState {
|
||||
final String userImage;
|
||||
|
||||
const UploadPictureSuccess(this.userImage);
|
||||
|
||||
@override
|
||||
List<Object> get props => [userImage];
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
RegExp emailRexExp = RegExp(r'^[\w-\.]+@([\w-]+.)+[\w-]{2,4}$');
|
||||
|
||||
RegExp passwordRexExp = RegExp(
|
||||
r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#\$&*~`)\%\-(_+=;:,.<>/?"[{\]}\|^]).{8,}$');
|
||||
|
||||
RegExp specialCharRexExp =
|
||||
RegExp(r'^(?=.*?[!@#$&*~`)\%\-(_+=;:,.<>/?"[{\]}\|^])');
|
||||
@@ -0,0 +1,61 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MyTextField extends StatelessWidget {
|
||||
final TextEditingController controller;
|
||||
final String hintText;
|
||||
final bool obscureText;
|
||||
final TextInputType keyboardType;
|
||||
final Widget? suffixIcon;
|
||||
final VoidCallback? onTap;
|
||||
final Widget? prefixIcon;
|
||||
final String? Function(String?)? validator;
|
||||
final FocusNode? focusNode;
|
||||
final String? errorMsg;
|
||||
final String? Function(String?)? onChanged;
|
||||
|
||||
const MyTextField(
|
||||
{super.key,
|
||||
required this.controller,
|
||||
required this.hintText,
|
||||
required this.obscureText,
|
||||
required this.keyboardType,
|
||||
this.suffixIcon,
|
||||
this.onTap,
|
||||
this.prefixIcon,
|
||||
this.validator,
|
||||
this.focusNode,
|
||||
this.errorMsg,
|
||||
this.onChanged});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextFormField(
|
||||
validator: validator,
|
||||
controller: controller,
|
||||
obscureText: obscureText,
|
||||
keyboardType: keyboardType,
|
||||
focusNode: focusNode,
|
||||
onTap: onTap,
|
||||
textInputAction: TextInputAction.next,
|
||||
onChanged: onChanged,
|
||||
decoration: InputDecoration(
|
||||
suffixIcon: suffixIcon,
|
||||
prefixIcon: prefixIcon,
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: const BorderSide(color: Colors.transparent),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderSide:
|
||||
BorderSide(color: Theme.of(context).colorScheme.secondary),
|
||||
),
|
||||
fillColor: Colors.grey.shade200,
|
||||
filled: true,
|
||||
hintText: hintText,
|
||||
hintStyle: TextStyle(color: Colors.grey[500]),
|
||||
errorText: errorMsg,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+180
-166
@@ -1,172 +1,186 @@
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:flutter/services.dart';
|
||||
// import 'package:get/get.dart';
|
||||
// import 'package:intl/date_symbol_data_local.dart';
|
||||
// import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/service_web.dart';
|
||||
// import 'package:prosappco/src/providers/user_provider.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/calendar.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/city.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/login/login.dart';
|
||||
// import 'package:firebase_core/firebase_core.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/login/login_email.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/my_services.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/my_services_pro.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/new_number.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/new_password.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/profession.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/professional_profile.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/professional_revision.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/profile/profile.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/profile/profile_pro.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/register/register.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/request_sent.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/reset_password/reset_password.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/map/service.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/solicitudes.dart';
|
||||
// import 'package:prosappco/src/services/local_notifications.dart';
|
||||
// import 'firebase_options.dart';
|
||||
// import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
// import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
// import 'package:provider/provider.dart';
|
||||
// import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
|
||||
// Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
||||
// await Firebase.initializeApp();
|
||||
|
||||
// print('Handling a backdround message: ${message.messageId}');
|
||||
// }
|
||||
|
||||
// void main() async {
|
||||
// WidgetsFlutterBinding.ensureInitialized();
|
||||
// await Firebase.initializeApp(
|
||||
// options: DefaultFirebaseOptions.currentPlatform,
|
||||
// ).then((value) => Get.put(AuthenticationRepository()));
|
||||
|
||||
// // Evitar la solicitud de permiso en la versión web
|
||||
// if (!kIsWeb) {
|
||||
// FirebaseMessaging messaging = FirebaseMessaging.instance;
|
||||
|
||||
// await messaging.requestPermission(
|
||||
// alert: true,
|
||||
// announcement: false,
|
||||
// badge: true,
|
||||
// carPlay: false,
|
||||
// criticalAlert: false,
|
||||
// provisional: false,
|
||||
// sound: true,
|
||||
// );
|
||||
|
||||
// FirebaseMessaging.onBackgroundMessage(
|
||||
// (_firebaseMessagingBackgroundHandler));
|
||||
|
||||
// FirebaseMessaging.onMessage.listen((RemoteMessage message) {});
|
||||
// }
|
||||
|
||||
// await initNotifications();
|
||||
|
||||
// await initializeDateFormatting('es_MX', null);
|
||||
|
||||
// SystemChrome.setPreferredOrientations([
|
||||
// DeviceOrientation.portraitUp,
|
||||
// DeviceOrientation.portraitDown,
|
||||
// ]);
|
||||
|
||||
// runApp(const MyApp());
|
||||
// }
|
||||
|
||||
// class MyApp extends StatelessWidget {
|
||||
// const MyApp({super.key});
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return MultiProvider(
|
||||
// providers: [
|
||||
// ChangeNotifierProvider(
|
||||
// create: (_) => UserProvider(),
|
||||
// ),
|
||||
// ],
|
||||
// child: GetMaterialApp(
|
||||
// theme: ThemeData(fontFamily: 'Poppins'),
|
||||
// debugShowCheckedModeBanner: false,
|
||||
// localizationsDelegates: const [
|
||||
// GlobalMaterialLocalizations.delegate,
|
||||
// GlobalWidgetsLocalizations.delegate,
|
||||
// GlobalCupertinoLocalizations.delegate,
|
||||
// ],
|
||||
// supportedLocales: const [
|
||||
// Locale('es', 'US'),
|
||||
// ],
|
||||
// title: 'ProsApp',
|
||||
// initialRoute: '/',
|
||||
// routes: {
|
||||
// '/': (context) => const LoginScreen(),
|
||||
// '/splash': (context) => const SplashScreen(),
|
||||
// '/login': (context) => const LoginEmailScreen(),
|
||||
// '/profile': (context) => const ProfileScreen(),
|
||||
// '/register': (context) => const RegisterScreen(),
|
||||
// '/city': (context) => const CityScreen(),
|
||||
// '/profession': (context) => const ProfessionScreen(),
|
||||
// '/newNumber': (context) => const NewNumberScreen(),
|
||||
// '/profesionalRevision': (context) =>
|
||||
// const ProfessionalRevisionScreen(),
|
||||
// '/profesionalProfile': (context) => const ProfessionalProfileScreen(),
|
||||
// '/solicitudEnviada': (context) => const RequestSentScreen(),
|
||||
// '/nuevaPassword': (context) => NewPasswordScreen(),
|
||||
// '/servicio': (context) => const ServiceScreen(),
|
||||
// '/servicioWeb': (context) => const ServiceWebScreen(),
|
||||
// '/profilePro': (context) => const ProfileProScreen(),
|
||||
// '/calendar': (context) => const CalendarScreen(),
|
||||
// '/solicitud': (context) => SolicitudScreen(),
|
||||
// '/misserviciospro': (context) => MyServicesProScreen(),
|
||||
// '/misservicios': (context) => MyServicesScreen(),
|
||||
// '/resetpassword': (context) => const ResetPasswordScreen(),
|
||||
// },
|
||||
// onGenerateRoute: (settings) {
|
||||
// throw Exception('Ruta desconocida: ${settings.name}');
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// class SplashScreen extends StatefulWidget {
|
||||
// const SplashScreen({super.key});
|
||||
|
||||
// @override
|
||||
// State<SplashScreen> createState() => _SplashScreenState();
|
||||
// }
|
||||
|
||||
// class _SplashScreenState extends State<SplashScreen> {
|
||||
// @override
|
||||
// void initState() {
|
||||
// super.initState();
|
||||
// if (kIsWeb) {
|
||||
// // Espera 3 segundos y luego redirige a LoginScreen
|
||||
// Future.delayed(const Duration(seconds: 3), () {
|
||||
// Navigator.pushReplacement(
|
||||
// context,
|
||||
// MaterialPageRoute(builder: (context) => const LoginScreen()),
|
||||
// );
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Scaffold(
|
||||
// backgroundColor: Colors.blue,
|
||||
// body: Center(
|
||||
// child: kIsWeb ? Image.asset('/images/splash.png') : const LoginScreen(),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// // splash: 'images/splashgif.gif',
|
||||
// // backgroundColor: Colors.black,
|
||||
// // nextScreen: const LoginScreen(),
|
||||
// // splashIconSize: 50,
|
||||
// // duration: 80000,
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||
import 'package:prosappco/src/presentation/screens/service_web.dart';
|
||||
import 'package:prosappco/src/providers/user_provider.dart';
|
||||
import 'package:prosappco/src/presentation/screens/calendar.dart';
|
||||
import 'package:prosappco/src/presentation/screens/city.dart';
|
||||
import 'package:prosappco/src/presentation/screens/login/login.dart';
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:prosappco/src/presentation/screens/login/login_email.dart';
|
||||
import 'package:prosappco/src/presentation/screens/my_services.dart';
|
||||
import 'package:prosappco/src/presentation/screens/my_services_pro.dart';
|
||||
import 'package:prosappco/src/presentation/screens/new_number.dart';
|
||||
import 'package:prosappco/src/presentation/screens/new_password.dart';
|
||||
import 'package:prosappco/src/presentation/screens/profession.dart';
|
||||
import 'package:prosappco/src/presentation/screens/professional_profile.dart';
|
||||
import 'package:prosappco/src/presentation/screens/professional_revision.dart';
|
||||
import 'package:prosappco/src/presentation/screens/profile/profile.dart';
|
||||
import 'package:prosappco/src/presentation/screens/profile/profile_pro.dart';
|
||||
import 'package:prosappco/src/presentation/screens/register/register.dart';
|
||||
import 'package:prosappco/src/presentation/screens/request_sent.dart';
|
||||
import 'package:prosappco/src/presentation/screens/reset_password/reset_password.dart';
|
||||
import 'package:prosappco/src/presentation/screens/map/service.dart';
|
||||
import 'package:prosappco/src/presentation/screens/solicitudes.dart';
|
||||
import 'package:prosappco/src/services/local_notifications.dart';
|
||||
import 'firebase_options.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
|
||||
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
||||
await Firebase.initializeApp();
|
||||
|
||||
print('Handling a backdround message: ${message.messageId}');
|
||||
}
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
import 'app.dart';
|
||||
import 'simple_bloc_observer.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Firebase.initializeApp(
|
||||
options: DefaultFirebaseOptions.currentPlatform,
|
||||
).then((value) => Get.put(AuthenticationRepository()));
|
||||
|
||||
// Evitar la solicitud de permiso en la versión web
|
||||
if (!kIsWeb) {
|
||||
FirebaseMessaging messaging = FirebaseMessaging.instance;
|
||||
|
||||
await messaging.requestPermission(
|
||||
alert: true,
|
||||
announcement: false,
|
||||
badge: true,
|
||||
carPlay: false,
|
||||
criticalAlert: false,
|
||||
provisional: false,
|
||||
sound: true,
|
||||
);
|
||||
|
||||
FirebaseMessaging.onBackgroundMessage(
|
||||
(_firebaseMessagingBackgroundHandler));
|
||||
|
||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {});
|
||||
}
|
||||
|
||||
await initNotifications();
|
||||
|
||||
await initializeDateFormatting('es_MX', null);
|
||||
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
|
||||
runApp(const MyApp());
|
||||
await Firebase.initializeApp();
|
||||
Bloc.observer = SimpleBlocObserver();
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
||||
runApp(MainApp(FirebaseUserRepository()));
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => UserProvider(),
|
||||
),
|
||||
],
|
||||
child: GetMaterialApp(
|
||||
theme: ThemeData(fontFamily: 'Poppins'),
|
||||
debugShowCheckedModeBanner: false,
|
||||
localizationsDelegates: const [
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [
|
||||
Locale('es', 'US'),
|
||||
],
|
||||
title: 'ProsApp',
|
||||
initialRoute: '/',
|
||||
routes: {
|
||||
'/': (context) => const LoginScreen(),
|
||||
'/splash': (context) => const SplashScreen(),
|
||||
'/login': (context) => const LoginEmailScreen(),
|
||||
'/profile': (context) => const ProfileScreen(),
|
||||
'/register': (context) => const RegisterScreen(),
|
||||
'/city': (context) => const CityScreen(),
|
||||
'/profession': (context) => const ProfessionScreen(),
|
||||
'/newNumber': (context) => const NewNumberScreen(),
|
||||
'/profesionalRevision': (context) =>
|
||||
const ProfessionalRevisionScreen(),
|
||||
'/profesionalProfile': (context) => const ProfessionalProfileScreen(),
|
||||
'/solicitudEnviada': (context) => const RequestSentScreen(),
|
||||
'/nuevaPassword': (context) => NewPasswordScreen(),
|
||||
'/servicio': (context) => const ServiceScreen(),
|
||||
'/servicioWeb': (context) => const ServiceWebScreen(),
|
||||
'/profilePro': (context) => const ProfileProScreen(),
|
||||
'/calendar': (context) => const CalendarScreen(),
|
||||
'/solicitud': (context) => SolicitudScreen(),
|
||||
'/misserviciospro': (context) => MyServicesProScreen(),
|
||||
'/misservicios': (context) => MyServicesScreen(),
|
||||
'/resetpassword': (context) => const ResetPasswordScreen(),
|
||||
},
|
||||
onGenerateRoute: (settings) {
|
||||
throw Exception('Ruta desconocida: ${settings.name}');
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SplashScreen extends StatefulWidget {
|
||||
const SplashScreen({super.key});
|
||||
|
||||
@override
|
||||
State<SplashScreen> createState() => _SplashScreenState();
|
||||
}
|
||||
|
||||
class _SplashScreenState extends State<SplashScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (kIsWeb) {
|
||||
// Espera 3 segundos y luego redirige a LoginScreen
|
||||
Future.delayed(const Duration(seconds: 3), () {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const LoginScreen()),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.blue,
|
||||
body: Center(
|
||||
child: kIsWeb ? Image.asset('/images/splash.png') : const LoginScreen(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// splash: 'images/splashgif.gif',
|
||||
// backgroundColor: Colors.black,
|
||||
// nextScreen: const LoginScreen(),
|
||||
// splashIconSize: 50,
|
||||
// duration: 80000,
|
||||
@@ -0,0 +1,138 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:prosappco/blocs/sing_in_bloc/sign_in_bloc.dart';
|
||||
|
||||
import '../../components/strings.dart';
|
||||
import '../../components/textfield.dart';
|
||||
|
||||
class SignInScreen extends StatefulWidget {
|
||||
const SignInScreen({super.key});
|
||||
|
||||
@override
|
||||
State<SignInScreen> createState() => _SignInScreenState();
|
||||
}
|
||||
|
||||
class _SignInScreenState extends State<SignInScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final emailController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
String? _errorMsg;
|
||||
bool obscurePassword = true;
|
||||
IconData iconPassword = CupertinoIcons.eye_fill;
|
||||
bool signInRequired = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<SignInBloc, SignInState>(
|
||||
listener: (context, state) {
|
||||
if (state is SignInSuccess) {
|
||||
setState(() {
|
||||
signInRequired = false;
|
||||
});
|
||||
} else if (state is SignInProcess) {
|
||||
setState(() {
|
||||
signInRequired = true;
|
||||
});
|
||||
} else if (state is SignInFailure) {
|
||||
setState(() {
|
||||
signInRequired = false;
|
||||
_errorMsg = 'Invalid email or password';
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
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),
|
||||
errorMsg: _errorMsg,
|
||||
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),
|
||||
errorMsg: _errorMsg,
|
||||
validator: (val) {
|
||||
if (val!.isEmpty) {
|
||||
return 'Please fill in this field';
|
||||
} else if (!passwordRexExp.hasMatch(val)) {
|
||||
return 'Please enter a valid password';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
suffixIcon: IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
obscurePassword = !obscurePassword;
|
||||
if (obscurePassword) {
|
||||
iconPassword = CupertinoIcons.eye_fill;
|
||||
} else {
|
||||
iconPassword = CupertinoIcons.eye_slash_fill;
|
||||
}
|
||||
});
|
||||
},
|
||||
icon: Icon(iconPassword),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
!signInRequired
|
||||
? SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.9,
|
||||
height: 50,
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
context.read<SignInBloc>().add(SignInRequired(
|
||||
emailController.text,
|
||||
passwordController.text));
|
||||
}
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
elevation: 3.0,
|
||||
backgroundColor:
|
||||
Theme.of(context).colorScheme.primary,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(60))),
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 25, vertical: 5),
|
||||
child: Text(
|
||||
'Sign In',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
)),
|
||||
)
|
||||
: const CircularProgressIndicator()
|
||||
],
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.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) {
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
},
|
||||
child: 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),
|
||||
),
|
||||
Text(
|
||||
"⚈ 1 number",
|
||||
style: TextStyle(
|
||||
color: containsNumber
|
||||
? Colors.green
|
||||
: Theme.of(context).colorScheme.onBackground),
|
||||
),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"⚈ 1 special character",
|
||||
style: TextStyle(
|
||||
color: containsSpecialChar
|
||||
? Colors.green
|
||||
: Theme.of(context).colorScheme.onBackground),
|
||||
),
|
||||
Text(
|
||||
"⚈ 8 minimum character",
|
||||
style: TextStyle(
|
||||
color: contains8Length
|
||||
? Colors.green
|
||||
: Theme.of(context).colorScheme.onBackground),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.9,
|
||||
child: MyTextField(
|
||||
controller: nameController,
|
||||
hintText: 'Name',
|
||||
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: TextButton(
|
||||
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));
|
||||
});
|
||||
}
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
elevation: 3.0,
|
||||
backgroundColor:
|
||||
Theme.of(context).colorScheme.primary,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(60))),
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 25, vertical: 5),
|
||||
child: Text(
|
||||
'Sign Up',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
)),
|
||||
)
|
||||
: const CircularProgressIndicator()
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:prosappco/blocs/sing_in_bloc/sign_in_bloc.dart';
|
||||
import 'package:prosappco/screens/authentication/sign_in_screen.dart';
|
||||
import 'package:prosappco/screens/authentication/sign_up_screen.dart';
|
||||
|
||||
import '../../blocs/authentication_bloc/authentication_bloc.dart';
|
||||
import '../../blocs/sign_up_bloc/sign_up_bloc.dart';
|
||||
|
||||
class WelcomeScreen extends StatefulWidget {
|
||||
const WelcomeScreen({super.key});
|
||||
|
||||
@override
|
||||
State<WelcomeScreen> createState() => _WelcomeScreenState();
|
||||
}
|
||||
|
||||
class _WelcomeScreenState extends State<WelcomeScreen>
|
||||
with TickerProviderStateMixin {
|
||||
late TabController tabController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
tabController = TabController(
|
||||
initialIndex: 0,
|
||||
length: 2,
|
||||
vsync: this,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
appBar: AppBar(
|
||||
elevation: 0,
|
||||
backgroundColor: Colors.transparent,
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: SizedBox(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
children: [
|
||||
const Text(
|
||||
'Welcome Back !',
|
||||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: kToolbarHeight),
|
||||
TabBar(
|
||||
controller: tabController,
|
||||
unselectedLabelColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.onBackground
|
||||
.withOpacity(0.5),
|
||||
labelColor: Theme.of(context).colorScheme.onBackground,
|
||||
tabs: const [
|
||||
Padding(
|
||||
padding: EdgeInsets.all(12.0),
|
||||
child: Text(
|
||||
'Sign In',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(12.0),
|
||||
child: Text(
|
||||
'Sign Up',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
Expanded(
|
||||
child: TabBarView(controller: tabController, children: [
|
||||
BlocProvider<SignInBloc>(
|
||||
create: (context) => SignInBloc(
|
||||
userRepository: context
|
||||
.read<AuthenticationBloc>()
|
||||
.userRepository),
|
||||
child: const SignInScreen(),
|
||||
),
|
||||
BlocProvider<SignUpBloc>(
|
||||
create: (context) => SignUpBloc(
|
||||
userRepository: context
|
||||
.read<AuthenticationBloc>()
|
||||
.userRepository),
|
||||
child: const SignUpScreen(),
|
||||
),
|
||||
]),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
|
||||
import 'package:prosappco/blocs/sing_in_bloc/sign_in_bloc.dart';
|
||||
import 'package:prosappco/blocs/update_user_info_bloc/update_user_info_bloc.dart';
|
||||
import 'package:prosappco/screens/profile/profile_screen.dart';
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
const HomeScreen({super.key});
|
||||
|
||||
@override
|
||||
State<HomeScreen> createState() => _HomeScreenState();
|
||||
}
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocListener<UpdateUserInfoBloc, UpdateUserInfoState>(
|
||||
listener: (context, state) {
|
||||
if (state is UploadPictureSuccess) {
|
||||
setState(() {
|
||||
context.read<MyUserBloc>().state.user!.picture = state.userImage;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
drawer: BlocBuilder<MyUserBloc, MyUserState>(builder: (context, state) {
|
||||
if (state.status == MyUserStatus.success) {
|
||||
return Drawer(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Material(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => const ProfileScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(
|
||||
top: 20 + MediaQuery.of(context).padding.top,
|
||||
bottom: 20,
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
state.user!.picture == ""
|
||||
? Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade300,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
CupertinoIcons.person,
|
||||
color: Colors.grey.shade400,
|
||||
size: 35,
|
||||
),
|
||||
)
|
||||
: Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey,
|
||||
shape: BoxShape.circle,
|
||||
image: DecorationImage(
|
||||
image: NetworkImage(
|
||||
state.user!.picture!,
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
context.read<MyUserBloc>().state.user!.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 24,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
state.user!.email,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
color: Theme.of(context).colorScheme.background,
|
||||
child: ListView(
|
||||
children: [
|
||||
ListTile(
|
||||
onTap: () {
|
||||
context
|
||||
.read<SignInBloc>()
|
||||
.add(const SignOutRequired());
|
||||
},
|
||||
title: const Text(
|
||||
'Cerrar Sesión',
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Drawer(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
));
|
||||
}
|
||||
}),
|
||||
appBar: AppBar(),
|
||||
body: const Placeholder(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:prosappco/blocs/authentication_bloc/authentication_bloc.dart';
|
||||
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
|
||||
import 'package:prosappco/blocs/update_user_info_bloc/update_user_info_bloc.dart';
|
||||
import 'package:prosappco/src/components/pop_appbar.dart';
|
||||
|
||||
class ProfileScreen extends StatefulWidget {
|
||||
const ProfileScreen({super.key});
|
||||
|
||||
@override
|
||||
State<ProfileScreen> createState() => _ProfileScreenState();
|
||||
}
|
||||
|
||||
class _ProfileScreenState extends State<ProfileScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(
|
||||
create: (context) => MyUserBloc(
|
||||
myUserRepository:
|
||||
context.read<AuthenticationBloc>().userRepository)
|
||||
..add(GetMyUser(
|
||||
myUserId: context.read<AuthenticationBloc>().state.user!.uid)),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (context) => UpdateUserInfoBloc(
|
||||
userRepository: context.read<AuthenticationBloc>().userRepository,
|
||||
),
|
||||
)
|
||||
],
|
||||
child: BlocListener<UpdateUserInfoBloc, UpdateUserInfoState>(
|
||||
listener: (context, state) {
|
||||
if (state is UploadPictureSuccess) {
|
||||
setState(() {
|
||||
context.read<MyUserBloc>().state.user!.picture = state.userImage;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: PopAppbar(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
label: 'Perfil',
|
||||
),
|
||||
body:
|
||||
BlocBuilder<MyUserBloc, MyUserState>(builder: (context, state) {
|
||||
if (state.status == MyUserStatus.success) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
final ImagePicker picker = ImagePicker();
|
||||
final XFile? image = await picker.pickImage(
|
||||
source: ImageSource.gallery,
|
||||
maxHeight: 500,
|
||||
maxWidth: 500,
|
||||
imageQuality: 40,
|
||||
);
|
||||
|
||||
if (image != null) {
|
||||
context.read<UpdateUserInfoBloc>().add(
|
||||
UploadPicture(image.path, state.user!.id),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: state.user!.picture == ""
|
||||
? Container(
|
||||
width: 120,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade300,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
CupertinoIcons.person,
|
||||
color: Colors.grey.shade400,
|
||||
size: 40,
|
||||
),
|
||||
)
|
||||
: Container(
|
||||
width: 120,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey,
|
||||
shape: BoxShape.circle,
|
||||
image: DecorationImage(
|
||||
image: NetworkImage(
|
||||
state.user!.picture!,
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
TextFormField(
|
||||
initialValue: state.user?.name,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Nombre',
|
||||
prefixIcon: Icon(Icons.person),
|
||||
hintText: 'Nombre (obligatorio)',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(25.0),
|
||||
)),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.red),
|
||||
),
|
||||
focusedErrorBorder: OutlineInputBorder(
|
||||
borderSide:
|
||||
BorderSide(color: Colors.red, width: 2.0),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Por favor, ingrese su nombre';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
TextFormField(
|
||||
initialValue: state.user?.email,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Nombre',
|
||||
prefixIcon: Icon(Icons.person),
|
||||
hintText: 'Nombre (obligatorio)',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(25.0),
|
||||
)),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.red),
|
||||
),
|
||||
focusedErrorBorder: OutlineInputBorder(
|
||||
borderSide:
|
||||
BorderSide(color: Colors.red, width: 2.0),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Por favor, ingrese su nombre';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {},
|
||||
child: const Text('Guardar'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
})),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class SimpleBlocObserver extends BlocObserver {
|
||||
@override
|
||||
void onCreate(BlocBase bloc) {
|
||||
super.onCreate(bloc);
|
||||
log('onCreate -- bloc: ${bloc.runtimeType}');
|
||||
}
|
||||
|
||||
@override
|
||||
void onEvent(Bloc bloc, Object? event) {
|
||||
super.onEvent(bloc, event);
|
||||
log('onEvent -- bloc: ${bloc.runtimeType}, event: $event');
|
||||
}
|
||||
|
||||
@override
|
||||
void onChange(BlocBase bloc, Change change) {
|
||||
super.onChange(bloc, change);
|
||||
log('onChange -- bloc: ${bloc.runtimeType}, change: $change');
|
||||
}
|
||||
|
||||
@override
|
||||
void onTransition(Bloc bloc, Transition transition) {
|
||||
super.onTransition(bloc, transition);
|
||||
log('onTransition -- bloc: ${bloc.runtimeType}, transition: $transition');
|
||||
}
|
||||
|
||||
@override
|
||||
void onError(BlocBase bloc, Object error, StackTrace stackTrace) {
|
||||
log('onError -- bloc: ${bloc.runtimeType}, error: $error');
|
||||
super.onError(bloc, error, stackTrace);
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose(BlocBase bloc) {
|
||||
super.onClose(bloc);
|
||||
log('onClose -- bloc: ${bloc.runtimeType}');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user