fix supabase storage
This commit is contained in:
@@ -1,22 +1,60 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:supabase_flutter/supabase_flutter.dart'; // <--- AGGIUNGI QUESTO
|
||||
|
||||
class ImageViewerWidget extends StatelessWidget {
|
||||
final String url;
|
||||
final String? storagePath; // ATTENZIONE: Ora contiene lo storagePath!
|
||||
final Uint8List? bytes;
|
||||
|
||||
const ImageViewerWidget({super.key, required this.url});
|
||||
const ImageViewerWidget({super.key, this.storagePath, this.bytes})
|
||||
: assert(
|
||||
(storagePath != null && storagePath != '') || bytes != null,
|
||||
'Errore: Devi fornire un Path valido o i bytes del file!',
|
||||
);
|
||||
|
||||
// Funzione che chiede le chiavi a Supabase
|
||||
Future<String> _getSignedUrl() async {
|
||||
return await Supabase.instance.client.storage
|
||||
.from('documents')
|
||||
.createSignedUrl(storagePath!, 60); // Link che si autodistrugge in 60s
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
icon: const Icon(Icons.close, color: Colors.black),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
),
|
||||
body: InteractiveViewer(
|
||||
// InteractiveViewer dà lo zoom gratis alle immagini!
|
||||
child: Center(child: Image.network(url)),
|
||||
maxScale: 5.0,
|
||||
child: Center(
|
||||
// Se abbiamo i byte, mostriamo subito. Altrimenti usiamo il FutureBuilder!
|
||||
child: bytes != null
|
||||
? Image.memory(bytes!)
|
||||
: FutureBuilder<String>(
|
||||
future: _getSignedUrl(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
if (snapshot.hasError) {
|
||||
return const Text(
|
||||
"Errore caricamento immagine (Permessi negati?)",
|
||||
style: TextStyle(color: Colors.red),
|
||||
);
|
||||
}
|
||||
if (snapshot.hasData) {
|
||||
return Image.network(snapshot.data!);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user