drawer
This commit is contained in:
@@ -1,6 +1,3 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'dart:developer';
|
|
||||||
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:user_repository/user_repository.dart';
|
import 'package:user_repository/user_repository.dart';
|
||||||
@@ -22,15 +19,4 @@ class MyUserBloc extends Bloc<MyUserEvent, MyUserState> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onUserChanged(UserChanged event, Emitter<MyUserState> emit) {
|
|
||||||
log('UserChanged: ${event.user}');
|
|
||||||
if (event.user == null) {
|
|
||||||
log('UserChanged: ${event.user}');
|
|
||||||
emit(const MyUserState.failure());
|
|
||||||
} else {
|
|
||||||
log('UserChanged: ${event.user}');
|
|
||||||
emit(MyUserState.success(event.user!));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class UpdateUserInfoBloc
|
|||||||
: _userRepository = userRepository,
|
: _userRepository = userRepository,
|
||||||
super(UpdateUserInfoInitial()) {
|
super(UpdateUserInfoInitial()) {
|
||||||
on<UploadPicture>(_onUploadPicture);
|
on<UploadPicture>(_onUploadPicture);
|
||||||
|
on<UpdateUserInfo>(_onUpdateUserInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onUploadPicture(
|
void _onUploadPicture(
|
||||||
@@ -26,4 +27,17 @@ class UpdateUserInfoBloc
|
|||||||
emit(UploadPictureFailure());
|
emit(UploadPictureFailure());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onUpdateUserInfo(
|
||||||
|
UpdateUserInfo event, Emitter<UpdateUserInfoState> emit) async {
|
||||||
|
emit(UpdateUserInfoLoading());
|
||||||
|
try {
|
||||||
|
await _userRepository.updateUserInfo(event.userId, {
|
||||||
|
'name': event.name,
|
||||||
|
});
|
||||||
|
emit(const UpdateUserInfoSuccess());
|
||||||
|
} catch (e) {
|
||||||
|
emit(UpdateUserInfoFailure());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,3 +16,13 @@ class UploadPicture extends UpdateUserInfoEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [file, userId];
|
List<Object> get props => [file, userId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UpdateUserInfo extends UpdateUserInfoEvent {
|
||||||
|
final String userId;
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
const UpdateUserInfo(this.userId, this.name);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [userId, name];
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,3 +21,14 @@ class UploadPictureSuccess extends UpdateUserInfoState {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [userImage];
|
List<Object> get props => [userImage];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UpdateUserInfoFailure extends UpdateUserInfoState {}
|
||||||
|
|
||||||
|
class UpdateUserInfoLoading extends UpdateUserInfoState {}
|
||||||
|
|
||||||
|
class UpdateUserInfoSuccess extends UpdateUserInfoState {
|
||||||
|
const UpdateUserInfoSuccess();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
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/update_user_info_bloc/update_user_info_bloc.dart';
|
||||||
|
import 'package:prosappco/components/general_drawer_header.dart';
|
||||||
|
import 'package:prosappco/components/general_drawer_item.dart';
|
||||||
|
|
||||||
|
class GeneralDrawer extends StatefulWidget {
|
||||||
|
const GeneralDrawer({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<GeneralDrawer> createState() => _GeneralDrawerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _GeneralDrawerState extends State<GeneralDrawer> {
|
||||||
|
@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: Drawer(
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.background,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
const GeneralDrawerHeader(),
|
||||||
|
Divider(
|
||||||
|
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.1),
|
||||||
|
thickness: 0.5,
|
||||||
|
height: 1,
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
GeneralDrawerItem(
|
||||||
|
icon: Icons.person_outline,
|
||||||
|
label: 'Mi Perfil',
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Divider(
|
||||||
|
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.1),
|
||||||
|
thickness: 0.5,
|
||||||
|
height: 1,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 15),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: () {},
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 15),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
)),
|
||||||
|
child: const Text(
|
||||||
|
'Modo Profesional',
|
||||||
|
style: TextStyle(color: Colors.white, fontSize: 18),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 15),
|
||||||
|
// 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',
|
||||||
|
// ),
|
||||||
|
// )
|
||||||
|
// ],
|
||||||
|
// ),
|
||||||
|
// )
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
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/update_user_info_bloc/update_user_info_bloc.dart';
|
||||||
|
import 'package:prosappco/screens/profile/profile_screen.dart';
|
||||||
|
|
||||||
|
class GeneralDrawerHeader extends StatefulWidget {
|
||||||
|
const GeneralDrawerHeader({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<GeneralDrawerHeader> createState() => _GeneralDrawerHeaderState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _GeneralDrawerHeaderState extends State<GeneralDrawerHeader> {
|
||||||
|
@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: ListTile(
|
||||||
|
onTap: () {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
CupertinoPageRoute(
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return const ProfileScreen();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
title: Text(
|
||||||
|
context.read<MyUserBloc>().state.user!.name,
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
subtitle: Text(
|
||||||
|
context.read<MyUserBloc>().state.user!.email,
|
||||||
|
style: const TextStyle(fontSize: 12),
|
||||||
|
),
|
||||||
|
leading: context.read<MyUserBloc>().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: 60,
|
||||||
|
height: 60,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
image: DecorationImage(
|
||||||
|
image: NetworkImage(
|
||||||
|
context.read<MyUserBloc>().state.user!.picture!,
|
||||||
|
),
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
trailing: const Icon(Icons.keyboard_arrow_right, color: Colors.black),
|
||||||
|
contentPadding:
|
||||||
|
const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class GeneralDrawerItem extends StatelessWidget {
|
||||||
|
final String label;
|
||||||
|
final IconData icon;
|
||||||
|
final VoidCallback onTap;
|
||||||
|
|
||||||
|
const GeneralDrawerItem({
|
||||||
|
super.key,
|
||||||
|
required this.label,
|
||||||
|
required this.icon,
|
||||||
|
required this.onTap,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ListTile(
|
||||||
|
onTap: onTap,
|
||||||
|
leading: Icon(
|
||||||
|
icon,
|
||||||
|
color: Colors.black,
|
||||||
|
),
|
||||||
|
title: Text(
|
||||||
|
label,
|
||||||
|
style: const TextStyle(fontSize: 15),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -174,7 +174,6 @@ import 'package:firebase_core/firebase_core.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:prosappco/dependency_user/user_di.dart';
|
import 'package:prosappco/dependency_user/user_di.dart';
|
||||||
import 'package:user_repository/user_repository.dart';
|
|
||||||
import 'app.dart';
|
import 'app.dart';
|
||||||
import 'simple_bloc_observer.dart';
|
import 'simple_bloc_observer.dart';
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,8 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:prosappco/blocs/my_user_bloc/my_user_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/blocs/update_user_info_bloc/update_user_info_bloc.dart';
|
||||||
import 'package:prosappco/screens/profile/profile_screen.dart';
|
import 'package:prosappco/components/general_drawer.dart';
|
||||||
|
|
||||||
class HomeScreen extends StatefulWidget {
|
class HomeScreen extends StatefulWidget {
|
||||||
const HomeScreen({super.key});
|
const HomeScreen({super.key});
|
||||||
@@ -24,112 +23,16 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Scaffold(
|
child: SafeArea(
|
||||||
|
child: Scaffold(
|
||||||
backgroundColor: Theme.of(context).colorScheme.background,
|
backgroundColor: Theme.of(context).colorScheme.background,
|
||||||
drawer: Drawer(
|
drawer: const GeneralDrawer(),
|
||||||
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: [
|
|
||||||
context.read<MyUserBloc>().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(
|
|
||||||
context
|
|
||||||
.read<MyUserBloc>()
|
|
||||||
.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(
|
|
||||||
context.read<MyUserBloc>().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',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
appBar: AppBar(),
|
appBar: AppBar(),
|
||||||
body: Center(
|
body: const Center(
|
||||||
child: Text(
|
child: Text('Bienvenido'),
|
||||||
context.read<MyUserBloc>().state.user?.name ?? 'null',
|
),
|
||||||
),
|
),
|
||||||
)),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:image_picker/image_picker.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/my_user_bloc/my_user_bloc.dart';
|
||||||
import 'package:prosappco/blocs/update_user_info_bloc/update_user_info_bloc.dart';
|
import 'package:prosappco/blocs/update_user_info_bloc/update_user_info_bloc.dart';
|
||||||
import 'package:prosappco/src/components/pop_appbar.dart';
|
import 'package:prosappco/src/components/pop_appbar.dart';
|
||||||
@@ -15,28 +14,17 @@ class ProfileScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ProfileScreenState extends State<ProfileScreen> {
|
class _ProfileScreenState extends State<ProfileScreen> {
|
||||||
|
final TextEditingController _nameController = TextEditingController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_nameController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return
|
return BlocListener<UpdateUserInfoBloc, UpdateUserInfoState>(
|
||||||
|
|
||||||
// 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) {
|
listener: (context, state) {
|
||||||
if (state is UploadPictureSuccess) {
|
if (state is UploadPictureSuccess) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -45,126 +33,134 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: PopAppbar(
|
appBar: PopAppbar(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
label: 'Perfil',
|
label: 'Perfil',
|
||||||
),
|
),
|
||||||
body: BlocBuilder<MyUserBloc, MyUserState>(builder: (context, state) {
|
body: BlocBuilder<MyUserBloc, MyUserState>(builder: (context, state) {
|
||||||
if (state.status == MyUserStatus.success) {
|
if (state.status == MyUserStatus.success) {
|
||||||
return Padding(
|
_nameController.text = state.user!.name;
|
||||||
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) {
|
return Padding(
|
||||||
context.read<UpdateUserInfoBloc>().add(
|
padding: const EdgeInsets.all(20.0),
|
||||||
UploadPicture(image.path, state.user!.id),
|
child: Column(
|
||||||
);
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
}
|
children: [
|
||||||
},
|
GestureDetector(
|
||||||
child: state.user!.picture == ""
|
onTap: () async {
|
||||||
? Container(
|
final ImagePicker picker = ImagePicker();
|
||||||
width: 120,
|
final XFile? image = await picker.pickImage(
|
||||||
height: 120,
|
source: ImageSource.gallery,
|
||||||
decoration: BoxDecoration(
|
maxHeight: 500,
|
||||||
color: Colors.grey.shade300,
|
maxWidth: 500,
|
||||||
shape: BoxShape.circle,
|
imageQuality: 40,
|
||||||
),
|
);
|
||||||
child: Icon(
|
|
||||||
CupertinoIcons.person,
|
if (image != null) {
|
||||||
color: Colors.grey.shade400,
|
context.read<UpdateUserInfoBloc>().add(
|
||||||
size: 40,
|
UploadPicture(image.path, state.user!.id),
|
||||||
),
|
);
|
||||||
)
|
}
|
||||||
: Container(
|
},
|
||||||
width: 120,
|
child: state.user!.picture == ""
|
||||||
height: 120,
|
? Container(
|
||||||
decoration: BoxDecoration(
|
width: 120,
|
||||||
color: Colors.grey,
|
height: 120,
|
||||||
shape: BoxShape.circle,
|
decoration: BoxDecoration(
|
||||||
image: DecorationImage(
|
color: Colors.grey.shade300,
|
||||||
image: NetworkImage(
|
shape: BoxShape.circle,
|
||||||
state.user!.picture!,
|
),
|
||||||
),
|
child: Icon(
|
||||||
fit: BoxFit.cover,
|
CupertinoIcons.person,
|
||||||
|
color: Colors.grey.shade400,
|
||||||
|
size: 40,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Container(
|
||||||
|
width: 150,
|
||||||
|
height: 150,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
image: DecorationImage(
|
||||||
|
image: NetworkImage(
|
||||||
|
context
|
||||||
|
.read<MyUserBloc>()
|
||||||
|
.state
|
||||||
|
.user!
|
||||||
|
.picture!,
|
||||||
),
|
),
|
||||||
|
fit: BoxFit.contain,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20.0),
|
),
|
||||||
TextFormField(
|
const SizedBox(height: 20.0),
|
||||||
initialValue: state.user?.name,
|
TextFormField(
|
||||||
decoration: const InputDecoration(
|
controller: _nameController,
|
||||||
labelText: 'Nombre',
|
decoration: const InputDecoration(
|
||||||
prefixIcon: Icon(Icons.person),
|
labelText: 'Nombre',
|
||||||
hintText: 'Nombre (obligatorio)',
|
prefixIcon: Icon(Icons.person),
|
||||||
border: OutlineInputBorder(
|
hintText: 'Nombre (obligatorio)',
|
||||||
borderRadius: BorderRadius.all(
|
border: OutlineInputBorder(
|
||||||
Radius.circular(25.0),
|
borderRadius: BorderRadius.all(
|
||||||
)),
|
Radius.circular(25.0),
|
||||||
errorBorder: OutlineInputBorder(
|
)),
|
||||||
borderSide: BorderSide(color: Colors.red),
|
errorBorder: OutlineInputBorder(
|
||||||
),
|
borderSide: BorderSide(color: Colors.red),
|
||||||
focusedErrorBorder: OutlineInputBorder(
|
|
||||||
borderSide: BorderSide(color: Colors.red, width: 2.0),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
validator: (value) {
|
focusedErrorBorder: OutlineInputBorder(
|
||||||
if (value == null || value.isEmpty) {
|
borderSide: BorderSide(color: Colors.red, width: 2.0),
|
||||||
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(
|
validator: (value) {
|
||||||
onPressed: () {},
|
if (value == null || value.isEmpty) {
|
||||||
child: const Text('Guardar'),
|
return 'Por favor, ingrese su nombre';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20.0),
|
||||||
|
TextFormField(
|
||||||
|
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';
|
||||||
} else {
|
}
|
||||||
return const Center(child: CircularProgressIndicator());
|
return null;
|
||||||
}
|
},
|
||||||
})),
|
),
|
||||||
// ),
|
ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
context.read<UpdateUserInfoBloc>().add(
|
||||||
|
UpdateUserInfo(state.user!.id, _nameController.text));
|
||||||
|
},
|
||||||
|
child: const Text('Guardar'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,13 +18,7 @@ class FirebaseUserRepository implements UserRepository {
|
|||||||
FirebaseUserRepository(this._firebaseAuth) {
|
FirebaseUserRepository(this._firebaseAuth) {
|
||||||
_firebaseAuth.userChanges().listen((user) async {
|
_firebaseAuth.userChanges().listen((user) async {
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
try {
|
await updateFromFirebase(user.uid);
|
||||||
final myUser = await getMyUser(user.uid);
|
|
||||||
_userStreamController.add(myUser);
|
|
||||||
} catch (e) {
|
|
||||||
log('Error en FirebaseUserRepository ${e.toString()}');
|
|
||||||
_userStreamController.add(null);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
_userStreamController.add(null);
|
_userStreamController.add(null);
|
||||||
}
|
}
|
||||||
@@ -33,6 +27,16 @@ class FirebaseUserRepository implements UserRepository {
|
|||||||
|
|
||||||
// Stream<MyUser?> get user => _userStreamController.stream;
|
// Stream<MyUser?> get user => _userStreamController.stream;
|
||||||
|
|
||||||
|
Future<void> updateFromFirebase(String userId) async {
|
||||||
|
try {
|
||||||
|
final myUser = await getMyUser(userId);
|
||||||
|
_userStreamController.add(myUser);
|
||||||
|
} catch (e) {
|
||||||
|
log('Error en FirebaseUserRepository ${e.toString()}');
|
||||||
|
_userStreamController.add(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<MyUser?> streamUser() {
|
Stream<MyUser?> streamUser() {
|
||||||
return _userStreamController.stream;
|
return _userStreamController.stream;
|
||||||
@@ -129,6 +133,8 @@ class FirebaseUserRepository implements UserRepository {
|
|||||||
Future<void> updateUserInfo(String userId, Map<String, dynamic> data) async {
|
Future<void> updateUserInfo(String userId, Map<String, dynamic> data) async {
|
||||||
try {
|
try {
|
||||||
await usersCollection.doc(userId).update(data);
|
await usersCollection.doc(userId).update(data);
|
||||||
|
|
||||||
|
await updateFromFirebase(userId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e.toString());
|
log(e.toString());
|
||||||
rethrow;
|
rethrow;
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import 'package:firebase_auth/firebase_auth.dart';
|
|
||||||
|
|
||||||
import '../user_repository.dart';
|
import '../user_repository.dart';
|
||||||
|
|
||||||
abstract class UserRepository {
|
abstract class UserRepository {
|
||||||
|
|||||||
Reference in New Issue
Block a user