From e241a79289370b9d8e2891c55283d56b6431b017 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 17 Jul 2024 23:39:51 +0200 Subject: [PATCH] add modal description --- .../lib/classes/descriptionImage.dart | 29 +++++++++++++++ .../lib/pages/DisplayPictureScreen.dart | 9 +++-- covas_mobile/pubspec.lock | 36 +++++++++---------- 3 files changed, 53 insertions(+), 21 deletions(-) create mode 100644 covas_mobile/lib/classes/descriptionImage.dart diff --git a/covas_mobile/lib/classes/descriptionImage.dart b/covas_mobile/lib/classes/descriptionImage.dart new file mode 100644 index 0000000..fdd6710 --- /dev/null +++ b/covas_mobile/lib/classes/descriptionImage.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; + +mixin ShowDescImageAdd on State { + 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; + }); + } +} diff --git a/covas_mobile/lib/pages/DisplayPictureScreen.dart b/covas_mobile/lib/pages/DisplayPictureScreen.dart index adc9c6e..f98c71b 100644 --- a/covas_mobile/lib/pages/DisplayPictureScreen.dart +++ b/covas_mobile/lib/pages/DisplayPictureScreen.dart @@ -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 { +class DisplayPictureScreenState extends State + with ShowDescImageAdd, ShowErrorDialog { @override void initState() { super.initState(); @@ -63,7 +65,8 @@ class DisplayPictureScreenState extends State { 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}")); } diff --git a/covas_mobile/pubspec.lock b/covas_mobile/pubspec.lock index 5c8ffbb..77ce0c0 100644 --- a/covas_mobile/pubspec.lock +++ b/covas_mobile/pubspec.lock @@ -85,10 +85,10 @@ packages: dependency: transitive description: name: cross_file - sha256: "2f9d2cbccb76127ba28528cb3ae2c2326a122446a83de5a056aaa3880d3882c5" + sha256: "55d7b444feb71301ef6b8838dbc1ae02e63dd48c8773f3810ff53bb1e2945b32" url: "https://pub.dev" source: hosted - version: "0.3.3+7" + version: "0.3.4+1" cupertino_icons: dependency: "direct main" description: @@ -196,10 +196,10 @@ packages: dependency: "direct main" description: name: http - sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010 + sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938" url: "https://pub.dev" source: hosted - version: "1.2.2" + version: "1.2.1" http_parser: dependency: transitive description: @@ -216,14 +216,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.19.0" - js: - dependency: transitive - description: - name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 - url: "https://pub.dev" - source: hosted - version: "0.6.7" json_annotation: dependency: transitive description: @@ -348,10 +340,10 @@ packages: dependency: transitive description: name: path_provider_windows - sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7 + sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170" url: "https://pub.dev" source: hosted - version: "2.3.0" + version: "2.2.1" platform: dependency: transitive description: @@ -412,10 +404,10 @@ packages: dependency: transitive description: name: shared_preferences_web - sha256: d762709c2bbe80626ecc819143013cc820fa49ca5e363620ee20a8b15a3e3daf + sha256: "9aee1089b36bd2aafe06582b7d7817fd317ef05fc30e6ba14bff247d0933042a" url: "https://pub.dev" source: hosted - version: "2.2.1" + version: "2.3.0" shared_preferences_windows: dependency: transitive description: @@ -513,10 +505,18 @@ packages: dependency: transitive description: name: web - sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062 + sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" url: "https://pub.dev" source: hosted - version: "1.0.0" + version: "0.5.1" + win32: + dependency: transitive + description: + name: win32 + sha256: a79dbe579cb51ecd6d30b17e0cae4e0ea15e2c0e66f69ad4198f22a6789e94f4 + url: "https://pub.dev" + source: hosted + version: "5.5.1" xdg_directories: dependency: transitive description: