Bonjour,
Actuellement j’ai un onglet qui permet de générer l’image avec de l’ajout de texte et un onglet où on voit l’affichage de l’image modifier. J’aimerais bien sauvegardé cette image modifié dans ma galerie sauf que des règles de Dart m’en empêche, auriez-vous une idée de comment résoudre ceci ou trouver une autre méthode sauvegardé des images modifié?
J’utilise Image Provider avec la variable target qui va être mon image modifié et Image Painter State pour exporté l’image vers ma galerie
Voici la fonction en question:
class _CEEState extends State<CEE> {
ImageProvider? target;
String Certificat = 'assets/cee.png';
GlobalKey globalKey = GlobalKey();
@override
Widget build(BuildContext context) {
final _imageKey = GlobalKey<ImagePainterState>();
final _key = GlobalKey<ScaffoldState>();
void saveImage() async {
final target = await _imageKey.currentState?.exportImage();
final directory = (await getApplicationDocumentsDirectory()).path;
await Directory('$directory/sample').create(recursive: true);
final fullPath =
'$directory/sample/${DateTime.now().millisecondsSinceEpoch}.png';
final imgFile = File.fromRawPath(target!);
imgFile.writeAsBytesSync(target);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Colors.orangeAccent[700],
padding: const EdgeInsets.only(left: 10),
content: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed: () => OpenFile.open("$fullPath"),
child: const Text(
"Le document modifié a bien été téléchargé",
style: TextStyle(
color: Colors.white,
),
),
)
],
),
),
Voici le header et le body de l’onglet :
return Scaffold(
appBar: AppBar(
title: const Text(''),
titleTextStyle:
const TextStyle(fontSize: 17.5, fontWeight: FontWeight.bold),
centerTitle: true,
actions: [
IconButton(
icon: Icon(Icons.save_alt),
color: Colors.white,
onPressed: saveImage)
],
),
` body: Container(`
alignment: Alignment.center,
width: double.infinity,
height: double.infinity,
child: SingleChildScrollView(
child: InteractiveViewer(
child: Column(children: <Widget>[
AspectRatio(
aspectRatio: 0.7 / 1,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
AspectRatio(
aspectRatio: 0.7,
child: Image(image: target!, fit: BoxFit.fitHeight)),
],
),
),
])))));
}
}