This commit is contained in:
Felipe
2024-02-16 20:43:51 -05:00
parent 159ffedc6e
commit 9e6f76e309
12 changed files with 391 additions and 263 deletions
+9 -106
View File
@@ -2,9 +2,8 @@ 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/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';
import 'package:prosappco/components/general_drawer.dart';
class HomeScreen extends StatefulWidget {
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,
drawer: 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: [
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',
),
)
],
),
)
],
),
),
),
drawer: const GeneralDrawer(),
appBar: AppBar(),
body: Center(
child: Text(
context.read<MyUserBloc>().state.user?.name ?? 'null',
),
)),
body: const Center(
child: Text('Bienvenido'),
),
),
),
);
}
}
+129 -133
View File
@@ -2,7 +2,6 @@ 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';
@@ -15,28 +14,17 @@ class ProfileScreen extends StatefulWidget {
}
class _ProfileScreenState extends State<ProfileScreen> {
final TextEditingController _nameController = TextEditingController();
@override
void dispose() {
_nameController.dispose();
super.dispose();
}
@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>(
return BlocListener<UpdateUserInfoBloc, UpdateUserInfoState>(
listener: (context, state) {
if (state is UploadPictureSuccess) {
setState(() {
@@ -45,126 +33,134 @@ class _ProfileScreenState extends State<ProfileScreen> {
}
},
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,
);
appBar: PopAppbar(
onPressed: () {
Navigator.pop(context);
},
label: 'Perfil',
),
body: BlocBuilder<MyUserBloc, MyUserState>(builder: (context, state) {
if (state.status == MyUserStatus.success) {
_nameController.text = state.user!.name;
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,
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: 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(
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),
),
),
),
const SizedBox(height: 20.0),
TextFormField(
controller: _nameController,
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),
),
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),
),
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'),
validator: (value) {
if (value == null || value.isEmpty) {
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),
),
),
],
),
);
} else {
return const Center(child: CircularProgressIndicator());
}
})),
// ),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Por favor, ingrese su nombre';
}
return null;
},
),
ElevatedButton(
onPressed: () {
context.read<UpdateUserInfoBloc>().add(
UpdateUserInfo(state.user!.id, _nameController.text));
},
child: const Text('Guardar'),
),
],
),
);
} else {
return const Center(child: CircularProgressIndicator());
}
}),
),
);
}
}