Files
flux/lib/core/widgets/image_viewer_widget.dart
Mark M2 Macbook 1c2bcf9df7 feat-add-files-from-qr (#8)
Reviewed-on: http://catelliub.zapto.org:3000/brontomark/flux/pulls/8
Co-authored-by: Mark M2 Macbook <marco@catelli.it>
Co-committed-by: Mark M2 Macbook <marco@catelli.it>
2026-04-26 10:15:34 +02:00

55 lines
1.8 KiB
Dart

import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flux/core/utils/functions.dart';
class ImageViewerWidget extends StatelessWidget {
final String? storagePath; // ATTENZIONE: Ora contiene lo storagePath!
final Uint8List? bytes;
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!',
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.close, color: Colors.black),
onPressed: () => Navigator.pop(context),
),
),
body: InteractiveViewer(
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(storagePath!),
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();
},
),
),
),
);
}
}