Skip to content

Commit

Permalink
fix: permission handle
Browse files Browse the repository at this point in the history
  • Loading branch information
MurilonND committed Aug 7, 2023
1 parent 0f86007 commit 6c4d4a0
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 54 deletions.
121 changes: 67 additions & 54 deletions lib/src/features/drawer/presentation/pages/drawer_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';
import 'dart:typed_data';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:liquid_art_ai/src/features/apikey_repository/presentation/apikey_repository_page.dart';
Expand Down Expand Up @@ -77,31 +78,36 @@ class _DrawerPageState extends State<DrawerPage> {
setState(() {
isSaving = true;
});
// var res = await Permission.storage.request();
// if (res.isGranted) {
const folder = "LiquidArtAI";
final path = await getApplicationDocumentsDirectory();
final imgPath = Directory('${path.path}/$folder');
final plugin = DeviceInfoPlugin();
final android = await plugin.androidInfo;

final fileName = "${_imagePromptController?.text}.jpg";
var res = android.version.sdkInt < 33
? await Permission.storage.request()
: PermissionStatus.granted;
if (res.isGranted) {
const folder = "LiquidArtAI";
final path = await getApplicationDocumentsDirectory();
final imgPath = Directory('${path.path}/$folder');

if (await path.exists()) {
await screenshotController.captureAndSave(imgPath.path,
delay: const Duration(milliseconds: 100),
fileName: fileName,
pixelRatio: 1.0);
} else {
await imgPath.create();
await screenshotController.captureAndSave(imgPath.path,
delay: const Duration(milliseconds: 100),
fileName: fileName,
pixelRatio: 1.0);
}
final fileName = "${_imagePromptController?.text}.jpg";

setState(() {
isSaving = false;
});
// }
if (await path.exists()) {
await screenshotController.captureAndSave(imgPath.path,
delay: const Duration(milliseconds: 100),
fileName: fileName,
pixelRatio: 1.0);
} else {
await imgPath.create();
await screenshotController.captureAndSave(imgPath.path,
delay: const Duration(milliseconds: 100),
fileName: fileName,
pixelRatio: 1.0);
}

setState(() {
isSaving = false;
});
}
}

TextEditingController? _imagePromptController;
Expand Down Expand Up @@ -213,40 +219,47 @@ class _DrawerPageState extends State<DrawerPage> {
},
),
),
const SizedBox(width: 10,),
GestureDetector(
onTapDown: (details) async{
if(!isListening){
var available = await speechToText.initialize();
if(available) {
setState(() {
isListening = true;
speechToText.listen(
onResult: (result) {
setState(() {
_imagePromptController = TextEditingController(text: result.recognizedWords);
});
}
);
const SizedBox(
width: 10,
),
GestureDetector(
onTapDown: (details) async {
if (!isListening) {
var available =
await speechToText.initialize();
if (available) {
setState(() {
isListening = true;
speechToText.listen(onResult: (result) {
setState(() {
_imagePromptController =
TextEditingController(
text:
result.recognizedWords);
});
});
}
});
}
},
onTapUp: (details){
setState(() {
isListening = false;
});
speechToText.stop();
},
child: CircleAvatar(
radius: 30,
backgroundColor:isListening ? Colors.white : const Color(0xFF4C7BBF),
child: Icon(
Icons.mic,
color: isListening ? const Color(0xFF4C7BBF) : Colors.white,
),
)
),
}
},
onTapUp: (details) {
setState(() {
isListening = false;
});
speechToText.stop();
},
child: CircleAvatar(
radius: 30,
backgroundColor: isListening
? Colors.white
: const Color(0xFF4C7BBF),
child: Icon(
Icons.mic,
color: isListening
? const Color(0xFF4C7BBF)
: Colors.white,
),
)),
],
),
const SizedBox(
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import FlutterMacOS
import Foundation

import device_info_plus
import network_info_plus
import path_provider_foundation
import share_plus
import shared_preferences_foundation
import speech_to_text_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
NetworkInfoPlusPlugin.register(with: registry.registrar(forPlugin: "NetworkInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
Expand Down
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.8"
device_info_plus:
dependency: "direct main"
description:
name: device_info_plus
sha256: f52ab3b76b36ede4d135aab80194df8925b553686f0fa12226b4e2d658e45903
url: "https://pub.dev"
source: hosted
version: "8.2.2"
device_info_plus_platform_interface:
dependency: transitive
description:
name: device_info_plus_platform_interface
sha256: d3b01d5868b50ae571cd1dc6e502fc94d956b665756180f7b16ead09e836fd64
url: "https://pub.dev"
source: hosted
version: "7.0.0"
equatable:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies:
screenshot: ^1.3.0
shelf_router: ^1.1.4
speech_to_text: ^6.1.1
device_info_plus: ^8.2.2

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 6c4d4a0

Please sign in to comment.