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';
|
||||
|
||||
class PhotoViewWidget extends StatelessWidget {
|
||||
Bytes imageData;
|
||||
PhotoViewWidget({required this.imageData});
|
||||
const double photoSize = 100;
|
||||
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(vertical: 50),
|
||||
child: ClipOval(
|
||||
child: Image.memory(
|
||||
imageData,
|
||||
width: 60,
|
||||
height: 60,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
width: photoSize,
|
||||
height: photoSize,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF2BA4EC),
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
),
|
||||
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(
|
||||
// margin: EdgeInsets.symmetric(vertical: 50),
|
||||
// width: 100,
|
||||
// height: 100,
|
||||
// decoration: BoxDecoration(
|
||||
// color: Color(0xFF2BA4EC),
|
||||
// borderRadius: BorderRadius.circular(50),
|
||||
// ),
|
||||
// child: Icon(
|
||||
// Icons.person,
|
||||
// color: Colors.white,
|
||||
// size: 90,
|
||||
// ),
|
||||
// );
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ClipOval(
|
||||
child: Image.file(
|
||||
file,
|
||||
width: photoSize,
|
||||
height: photoSize,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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/upload_image.dart';
|
||||
|
||||
import '../components/photo_view.dart';
|
||||
|
||||
class ProfileScreen extends StatefulWidget {
|
||||
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 {
|
||||
return showDialog(
|
||||
context: context,
|
||||
@@ -343,60 +354,36 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
Container(
|
||||
child: Builder(builder: (context) {
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
Scaffold.of(context).openEndDrawer();
|
||||
},
|
||||
title: Text('${user?.displayName}',
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${user?.phoneNumber}',
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
Text(
|
||||
'$city',
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
leading: 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 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),
|
||||
);
|
||||
}),
|
||||
),
|
||||
Builder(builder: (context) {
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
Scaffold.of(context).openEndDrawer();
|
||||
},
|
||||
title: Text('${user?.displayName}',
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${user?.phoneNumber}',
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
Text(
|
||||
'$city',
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
leading: ReferencePhoto(
|
||||
ref: storage.ref().child(_photo),
|
||||
size: 50,
|
||||
),
|
||||
trailing: Icon(Icons.keyboard_arrow_right,
|
||||
color: Colors.black),
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
vertical: 20, horizontal: 16),
|
||||
);
|
||||
}),
|
||||
], // padding: const EdgeInsets.only(top: 20, bottom: 15),
|
||||
),
|
||||
Divider(height: 0, color: Colors.grey),
|
||||
@@ -555,38 +542,21 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
body: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
imagen_to_upload != null
|
||||
? GestureDetector(
|
||||
onTap: () {
|
||||
_showChoiceDialog(context);
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsets.symmetric(vertical: 50),
|
||||
child: ClipOval(
|
||||
child: Image.file(
|
||||
imagen_to_upload!,
|
||||
width: 100,
|
||||
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();
|
||||
}
|
||||
},
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
_showChoiceDialog(context);
|
||||
},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 50),
|
||||
child: (imagen_to_upload != null)
|
||||
? LocalPhoto(
|
||||
file: imagen_to_upload!,
|
||||
)
|
||||
: ReferencePhoto(ref: storage.ref().child(_photo))),
|
||||
),
|
||||
Container(
|
||||
width: 300,
|
||||
padding: EdgeInsets.only(top: 0),
|
||||
padding: const EdgeInsets.only(top: 0),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:firebase_storage/firebase_storage.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.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/screens/profile.dart';
|
||||
|
||||
import '../components/photo_view.dart';
|
||||
|
||||
class WelcomeScreen extends StatefulWidget {
|
||||
const WelcomeScreen({super.key});
|
||||
|
||||
@@ -14,14 +17,17 @@ class WelcomeScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _WelcomeScreenState extends State<WelcomeScreen> {
|
||||
final FirebaseStorage storage = FirebaseStorage.instance;
|
||||
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final controller = Get.put(NameEmailCityController());
|
||||
var _ciudad = '';
|
||||
var _photo = '...';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final Reference ref = storage.ref().child(_photo);
|
||||
|
||||
if (_ciudad == '') {
|
||||
AuthenticationRepository.instance
|
||||
@@ -30,6 +36,13 @@ class _WelcomeScreenState extends State<WelcomeScreen> {
|
||||
_ciudad = s;
|
||||
}));
|
||||
}
|
||||
if (_photo == '...') {
|
||||
AuthenticationRepository.instance
|
||||
.getPhoto(uid.toString())
|
||||
.then((String s) => setState(() {
|
||||
_photo = s;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -69,18 +82,9 @@ class _WelcomeScreenState extends State<WelcomeScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
leading: Container(
|
||||
width: 60,
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xFF2BA4EC),
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.person,
|
||||
color: Colors.white,
|
||||
size: 55,
|
||||
),
|
||||
leading: ReferencePhoto(
|
||||
ref: storage.ref().child(_photo),
|
||||
size: 50,
|
||||
),
|
||||
trailing: Icon(Icons.keyboard_arrow_right,
|
||||
color: Colors.black),
|
||||
|
||||
Reference in New Issue
Block a user