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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user