imagen
This commit is contained in:
@@ -1,37 +1,93 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:firebase_storage/firebase_storage.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class PhotoViewWidget extends StatelessWidget {
|
const double photoSize = 100;
|
||||||
Bytes imageData;
|
|
||||||
PhotoViewWidget({required this.imageData});
|
class ReferencePhoto extends StatelessWidget {
|
||||||
|
Reference? ref;
|
||||||
|
double size;
|
||||||
|
ReferencePhoto({super.key, required this.ref, this.size = photoSize});
|
||||||
|
|
||||||
|
Future<Widget> downloadImage() async {
|
||||||
|
try {
|
||||||
|
if (ref != null) {
|
||||||
|
final imageData = await ref!.getData();
|
||||||
|
if (imageData != null) {
|
||||||
|
return ClipOval(
|
||||||
|
child: Image.memory(
|
||||||
|
imageData,
|
||||||
|
width: size,
|
||||||
|
height: size,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ignore: empty_catches
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
return const DefaultPhoto();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return FutureBuilder<Widget>(
|
||||||
|
future: downloadImage(),
|
||||||
|
builder: (BuildContext context, AsyncSnapshot<Widget> snapshot) {
|
||||||
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
|
// mientras la llamada asíncrona está en proceso, muestra un mensaje de carga
|
||||||
|
return const SizedBox(
|
||||||
|
width: photoSize,
|
||||||
|
height: photoSize,
|
||||||
|
child: Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
));
|
||||||
|
} else if (snapshot.connectionState == ConnectionState.done &&
|
||||||
|
snapshot.hasData) {
|
||||||
|
return snapshot.data!;
|
||||||
|
} else {
|
||||||
|
return const DefaultPhoto();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DefaultPhoto extends StatelessWidget {
|
||||||
|
const DefaultPhoto({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
margin: EdgeInsets.symmetric(vertical: 50),
|
width: photoSize,
|
||||||
child: ClipOval(
|
height: photoSize,
|
||||||
child: Image.memory(
|
decoration: BoxDecoration(
|
||||||
imageData,
|
color: const Color(0xFF2BA4EC),
|
||||||
width: 60,
|
borderRadius: BorderRadius.circular(50),
|
||||||
height: 60,
|
),
|
||||||
fit: BoxFit.cover,
|
child: const Icon(
|
||||||
),
|
Icons.person,
|
||||||
|
color: Color.fromARGB(255, 255, 255, 255),
|
||||||
|
size: 55,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LocalPhoto extends StatelessWidget {
|
||||||
|
File file;
|
||||||
|
LocalPhoto({super.key, required this.file});
|
||||||
|
|
||||||
// Container(
|
@override
|
||||||
// margin: EdgeInsets.symmetric(vertical: 50),
|
Widget build(BuildContext context) {
|
||||||
// width: 100,
|
return ClipOval(
|
||||||
// height: 100,
|
child: Image.file(
|
||||||
// decoration: BoxDecoration(
|
file,
|
||||||
// color: Color(0xFF2BA4EC),
|
width: photoSize,
|
||||||
// borderRadius: BorderRadius.circular(50),
|
height: photoSize,
|
||||||
// ),
|
fit: BoxFit.cover,
|
||||||
// child: Icon(
|
),
|
||||||
// Icons.person,
|
);
|
||||||
// color: Colors.white,
|
}
|
||||||
// size: 90,
|
}
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import 'package:prosappco/src/controllers/add_name_email_city.dart';
|
|||||||
import 'package:prosappco/src/services/select_image_profile.dart';
|
import 'package:prosappco/src/services/select_image_profile.dart';
|
||||||
import 'package:prosappco/src/services/upload_image.dart';
|
import 'package:prosappco/src/services/upload_image.dart';
|
||||||
|
|
||||||
|
import '../components/photo_view.dart';
|
||||||
|
|
||||||
class ProfileScreen extends StatefulWidget {
|
class ProfileScreen extends StatefulWidget {
|
||||||
ProfileScreen({Key? key}) : super(key: key);
|
ProfileScreen({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@@ -271,6 +273,15 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget prueba() {
|
||||||
|
try {
|
||||||
|
return ReferencePhoto(ref: null);
|
||||||
|
} catch (e) {
|
||||||
|
print('errrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrror $e');
|
||||||
|
return Center();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _showChoiceDialog(BuildContext context) async {
|
Future<void> _showChoiceDialog(BuildContext context) async {
|
||||||
return showDialog(
|
return showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -343,60 +354,36 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
children: [
|
children: [
|
||||||
Column(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Builder(builder: (context) {
|
||||||
child: Builder(builder: (context) {
|
return ListTile(
|
||||||
return ListTile(
|
onTap: () {
|
||||||
onTap: () {
|
Scaffold.of(context).openEndDrawer();
|
||||||
Scaffold.of(context).openEndDrawer();
|
},
|
||||||
},
|
title: Text('${user?.displayName}',
|
||||||
title: Text('${user?.displayName}',
|
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
subtitle: Column(
|
||||||
subtitle: Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
children: [
|
||||||
children: [
|
Text(
|
||||||
Text(
|
'${user?.phoneNumber}',
|
||||||
'${user?.phoneNumber}',
|
style: TextStyle(fontSize: 12),
|
||||||
style: TextStyle(fontSize: 12),
|
),
|
||||||
),
|
Text(
|
||||||
Text(
|
'$city',
|
||||||
'$city',
|
style: TextStyle(fontSize: 12),
|
||||||
style: TextStyle(fontSize: 12),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
leading: ReferencePhoto(
|
||||||
leading: FutureBuilder<Widget>(
|
ref: storage.ref().child(_photo),
|
||||||
future:
|
size: 50,
|
||||||
downloadImage(storage.ref().child(_photo)),
|
),
|
||||||
builder: (BuildContext context,
|
trailing: Icon(Icons.keyboard_arrow_right,
|
||||||
AsyncSnapshot<Widget> snapshot) {
|
color: Colors.black),
|
||||||
if (snapshot.connectionState ==
|
contentPadding: EdgeInsets.symmetric(
|
||||||
ConnectionState.done &&
|
vertical: 20, horizontal: 16),
|
||||||
snapshot.hasData) {
|
);
|
||||||
return snapshot.data!;
|
}),
|
||||||
} else {
|
|
||||||
return Container(
|
|
||||||
width: 60,
|
|
||||||
height: 60,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Color(0xFF2BA4EC),
|
|
||||||
borderRadius: BorderRadius.circular(50),
|
|
||||||
),
|
|
||||||
child: Icon(
|
|
||||||
Icons.person,
|
|
||||||
color: Colors.white,
|
|
||||||
size: 55,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
trailing: Icon(Icons.keyboard_arrow_right,
|
|
||||||
color: Colors.black),
|
|
||||||
contentPadding: EdgeInsets.symmetric(
|
|
||||||
vertical: 20, horizontal: 16),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
], // padding: const EdgeInsets.only(top: 20, bottom: 15),
|
], // padding: const EdgeInsets.only(top: 20, bottom: 15),
|
||||||
),
|
),
|
||||||
Divider(height: 0, color: Colors.grey),
|
Divider(height: 0, color: Colors.grey),
|
||||||
@@ -555,38 +542,21 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
|||||||
body: Center(
|
body: Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
imagen_to_upload != null
|
GestureDetector(
|
||||||
? GestureDetector(
|
onTap: () {
|
||||||
onTap: () {
|
_showChoiceDialog(context);
|
||||||
_showChoiceDialog(context);
|
},
|
||||||
},
|
child: Container(
|
||||||
child: Container(
|
margin: const EdgeInsets.symmetric(vertical: 50),
|
||||||
margin: EdgeInsets.symmetric(vertical: 50),
|
child: (imagen_to_upload != null)
|
||||||
child: ClipOval(
|
? LocalPhoto(
|
||||||
child: Image.file(
|
file: imagen_to_upload!,
|
||||||
imagen_to_upload!,
|
)
|
||||||
width: 100,
|
: ReferencePhoto(ref: storage.ref().child(_photo))),
|
||||||
height: 100,
|
),
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: FutureBuilder<Widget>(
|
|
||||||
future: downloadImage(storage.ref().child(_photo)),
|
|
||||||
builder: (BuildContext context,
|
|
||||||
AsyncSnapshot<Widget> snapshot) {
|
|
||||||
if (snapshot.connectionState == ConnectionState.done &&
|
|
||||||
snapshot.hasData) {
|
|
||||||
return snapshot.data!;
|
|
||||||
} else {
|
|
||||||
return const CircularProgressIndicator();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Container(
|
Container(
|
||||||
width: 300,
|
width: 300,
|
||||||
padding: EdgeInsets.only(top: 0),
|
padding: const EdgeInsets.only(top: 0),
|
||||||
child: Form(
|
child: Form(
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:firebase_auth/firebase_auth.dart';
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
|
import 'package:firebase_storage/firebase_storage.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||||
@@ -6,6 +7,8 @@ import 'package:cloud_firestore/cloud_firestore.dart';
|
|||||||
import 'package:prosappco/src/controllers/add_name_email_city.dart';
|
import 'package:prosappco/src/controllers/add_name_email_city.dart';
|
||||||
import 'package:prosappco/src/screens/profile.dart';
|
import 'package:prosappco/src/screens/profile.dart';
|
||||||
|
|
||||||
|
import '../components/photo_view.dart';
|
||||||
|
|
||||||
class WelcomeScreen extends StatefulWidget {
|
class WelcomeScreen extends StatefulWidget {
|
||||||
const WelcomeScreen({super.key});
|
const WelcomeScreen({super.key});
|
||||||
|
|
||||||
@@ -14,14 +17,17 @@ class WelcomeScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _WelcomeScreenState extends State<WelcomeScreen> {
|
class _WelcomeScreenState extends State<WelcomeScreen> {
|
||||||
|
final FirebaseStorage storage = FirebaseStorage.instance;
|
||||||
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
final controller = Get.put(NameEmailCityController());
|
final controller = Get.put(NameEmailCityController());
|
||||||
var _ciudad = '';
|
var _ciudad = '';
|
||||||
|
var _photo = '...';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
final Reference ref = storage.ref().child(_photo);
|
||||||
|
|
||||||
if (_ciudad == '') {
|
if (_ciudad == '') {
|
||||||
AuthenticationRepository.instance
|
AuthenticationRepository.instance
|
||||||
@@ -30,6 +36,13 @@ class _WelcomeScreenState extends State<WelcomeScreen> {
|
|||||||
_ciudad = s;
|
_ciudad = s;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
if (_photo == '...') {
|
||||||
|
AuthenticationRepository.instance
|
||||||
|
.getPhoto(uid.toString())
|
||||||
|
.then((String s) => setState(() {
|
||||||
|
_photo = s;
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -69,18 +82,9 @@ class _WelcomeScreenState extends State<WelcomeScreen> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
leading: Container(
|
leading: ReferencePhoto(
|
||||||
width: 60,
|
ref: storage.ref().child(_photo),
|
||||||
height: 60,
|
size: 50,
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Color(0xFF2BA4EC),
|
|
||||||
borderRadius: BorderRadius.circular(50),
|
|
||||||
),
|
|
||||||
child: Icon(
|
|
||||||
Icons.person,
|
|
||||||
color: Colors.white,
|
|
||||||
size: 55,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
trailing: Icon(Icons.keyboard_arrow_right,
|
trailing: Icon(Icons.keyboard_arrow_right,
|
||||||
color: Colors.black),
|
color: Colors.black),
|
||||||
|
|||||||
Reference in New Issue
Block a user