|
- // lib/presentation/screens/image_preview/image_preview_screen.dart
-
- import 'dart:convert';
- import 'package:flutter/material.dart';
-
- // --- CORRECTION 1 : IMPORTER SEULEMENT CE QUI EST NÉCESSAIRE ---
- import '../../../repositories/ai_repository.dart';
- import '../../../routes/app_routes.dart';
- // L'import de 'ollama_service.dart' est supprimé.
-
- // --- CORRECTION 2 : SIMPLIFIER LE CONSTRUCTEUR ---
- // Cet écran n'a plus besoin de recevoir un service, car l'écran suivant
- // instanciera lui-même le AiRepository dont il a besoin.
- final class ImagePreviewScreen extends StatelessWidget {
- final String imageBase64;
-
- const ImagePreviewScreen({super.key, required this.imageBase64});
-
- @override
- Widget build(BuildContext context) {
- // Le AiRepository est instancié ici, uniquement si on en a besoin pour la navigation.
- // Dans ce cas, on le passe à l'écran suivant.
- final AiRepository aiRepository = AiRepository();
-
- try {
- final imageBytes = base64Decode(imageBase64);
-
- return Scaffold(
- appBar: AppBar(
- title: const Text("Aperçu de l'image"),
- backgroundColor: Colors.black,
- elevation: 0,
- ),
- backgroundColor: Colors.black,
- body: SafeArea(
- child: Center(
- child: InteractiveViewer(
- panEnabled: true,
- minScale: 0.5,
- maxScale: 4.0,
- child: Image.memory(
- imageBytes,
- fit: BoxFit.contain,
- ),
- ),
- ),
- ),
- floatingActionButton: FloatingActionButton.extended(
- // --- CORRECTION 3 : SIMPLIFIER LA LOGIQUE DE NAVIGATION ---
- onPressed: () {
- // On navigue vers l'écran suivant en lui passant les arguments nécessaires.
- // L'écran 'TextGeneration' aura besoin de l'image et du repository pour travailler.
- Navigator.pushNamed(
- context,
- AppRoutes.textGeneration, // La route vers l'écran de génération de texte
- arguments: {
- 'imageBase64': imageBase64,
- 'aiRepository': aiRepository,
- },
- );
- },
- label: const Text('Utiliser cette image'),
- icon: const Icon(Icons.check),
- ),
- );
- } catch (e) {
- // Le bloc catch reste inchangé, il est correct.
- return Scaffold(
- appBar: AppBar(title: const Text('Erreur')),
- body: const Center(
- child: Text(
- 'Erreur : aucune image à afficher. Les données sont peut-être corrompues.',
- textAlign: TextAlign.center,
- ),
- ),
- );
- }
- }
- }
|