Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

80 lines
2.6KB

  1. // lib/presentation/screens/image_preview/image_preview_screen.dart
  2. import 'dart:convert';
  3. import 'package:flutter/material.dart';
  4. // --- CORRECTION 1 : IMPORTER SEULEMENT CE QUI EST NÉCESSAIRE ---
  5. import '../../../repositories/ai_repository.dart';
  6. import '../../../routes/app_routes.dart';
  7. // L'import de 'ollama_service.dart' est supprimé.
  8. // --- CORRECTION 2 : SIMPLIFIER LE CONSTRUCTEUR ---
  9. // Cet écran n'a plus besoin de recevoir un service, car l'écran suivant
  10. // instanciera lui-même le AiRepository dont il a besoin.
  11. final class ImagePreviewScreen extends StatelessWidget {
  12. const ImagePreviewScreen({required this.imageBase64, super.key});
  13. final String imageBase64;
  14. @override
  15. Widget build(BuildContext context) {
  16. // Le AiRepository est instancié ici, uniquement si on en a besoin pour la navigation.
  17. // Dans ce cas, on le passe à l'écran suivant.
  18. final aiRepository = AiRepository();
  19. try {
  20. final imageBytes = base64Decode(imageBase64);
  21. return Scaffold(
  22. appBar: AppBar(
  23. title: const Text("Aperçu de l'image"),
  24. backgroundColor: Colors.black,
  25. elevation: 0,
  26. ),
  27. backgroundColor: Colors.black,
  28. body: SafeArea(
  29. child: Center(
  30. child: InteractiveViewer(
  31. panEnabled: true,
  32. minScale: 0.5,
  33. maxScale: 4,
  34. child: Image.memory(
  35. imageBytes,
  36. fit: BoxFit.contain,
  37. ),
  38. ),
  39. ),
  40. ),
  41. floatingActionButton: FloatingActionButton.extended(
  42. // --- CORRECTION 3 : SIMPLIFIER LA LOGIQUE DE NAVIGATION ---
  43. onPressed: () {
  44. // On navigue vers l'écran suivant en lui passant les arguments nécessaires.
  45. // L'écran 'TextGeneration' aura besoin de l'image et du repository pour travailler.
  46. Navigator.pushNamed(
  47. context,
  48. AppRoutes.textGeneration, // La route vers l'écran de génération de texte
  49. arguments: {
  50. 'imageBase64': imageBase64,
  51. 'aiRepository': aiRepository,
  52. },
  53. );
  54. },
  55. label: const Text('Utiliser cette image'),
  56. icon: const Icon(Icons.check),
  57. ),
  58. );
  59. } catch (e) {
  60. // Le bloc catch reste inchangé, il est correct.
  61. return Scaffold(
  62. appBar: AppBar(title: const Text('Erreur')),
  63. body: const Center(
  64. child: Text(
  65. 'Erreur : aucune image à afficher. Les données sont peut-être corrompues.',
  66. textAlign: TextAlign.center,
  67. ),
  68. ),
  69. );
  70. }
  71. }
  72. }