add modal description

This commit is contained in:
2024-07-17 23:39:51 +02:00
parent a5ee85ee97
commit e241a79289
3 changed files with 53 additions and 21 deletions

View File

@@ -0,0 +1,29 @@
import 'package:flutter/material.dart';
mixin ShowDescImageAdd<T extends StatefulWidget> on State<T> {
void showDescImageAddDialog(BuildContext context, String text) {
// Create AlertDialog
AlertDialog dialog = AlertDialog(
title: Text("Description image"),
content: Text(text),
actions: [
ElevatedButton(
child: Text("OK"),
style: ElevatedButton.styleFrom(
padding: EdgeInsets.symmetric(horizontal: 50, vertical: 20),
textStyle:
TextStyle(fontSize: 15, fontWeight: FontWeight.normal)),
onPressed: () {
Navigator.of(context).pop("Yes, Of course!"); // Return value
}),
],
);
// Call showDialog function to show dialog.
Future futureValue = showDialog(
context: context,
builder: (BuildContext context) {
return dialog;
});
}
}

View File

@@ -1,7 +1,8 @@
import 'package:flutter/material.dart';
import 'dart:io';
import '../classes/descriptionImage.dart';
import '../classes/alert.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_gemini/flutter_gemini.dart';
void main() {
@@ -44,7 +45,8 @@ class DisplayPictureScreen extends StatefulWidget {
}
// A widget that displays the picture taken by the user.
class DisplayPictureScreenState extends State<DisplayPictureScreen> {
class DisplayPictureScreenState extends State<DisplayPictureScreen>
with ShowDescImageAdd, ShowErrorDialog {
@override
void initState() {
super.initState();
@@ -63,7 +65,8 @@ class DisplayPictureScreenState extends State<DisplayPictureScreen> {
gemini
.textAndImage(
text: "What is this picture ?", images: [file.readAsBytesSync()])
.then((value) => print(value?.content?.parts?.last.text ?? ''))
.then((value) => showDescImageAddDialog(
context, value?.content?.parts?.last.text ?? ''))
.catchError((e) => print("problem gemini : ${e}"));
}