App crash on image click in release build using image_picker flutter - flutter

My app got crashed on image click but working fine in debug mode.
I got the following error in terminal
E/AndroidRuntime(18185): java.lang.NoClassDefFoundError: Failed resolution of: Lj$/util/DesugarTimeZone;
E/AndroidRuntime(18185): at androidx.exifinterface.media.ExifInterface.(ExifInterface.java:3862)
E/AndroidRuntime(18185): at io.flutter.plugins.imagepicker.ExifDataCopier.copyExif(ExifDataCopier.java:15)
E/AndroidRuntime(18185): at io.flutter.plugins.imagepicker.ImageResizer.copyExif(ImageResizer.java:120)
E/AndroidRuntime(18185): at io.flutter.plugins.imagepicker.ImageResizer.resizeImageIfNeeded(ImageResizer.java:49)
E/AndroidRuntime(18185): at io.flutter.plugins.imagepicker.ImagePickerDelegate.getResizedImagePath(ImagePickerDelegate.java:603)
E/AndroidRuntime(18185): at io.flutter.plugins.imagepicker.ImagePickerDelegate.handleImageResult(ImagePickerDelegate.java:587)
E/AndroidRuntime(18185): at io.flutter.plugins.imagepicker.ImagePickerDelegate.access$000(ImagePickerDelegate.java:75)
E/AndroidRuntime(18185): at io.flutter.plugins.imagepicker.ImagePickerDelegate$3.onPathReady(ImagePickerDelegate.java:535)
E/AndroidRuntime(18185): at io.flutter.plugins.imagepicker.ImagePickerDelegate$2$1.onScanCompleted(ImagePickerDelegate.java:163)
E/AndroidRuntime(18185): at android.media.MediaScannerConnection.runCallBack(MediaScannerConnection.java:211)
E/AndroidRuntime(18185): at android.media.MediaScannerConnection.lambda$scanFile$1(MediaScannerConnection.java:188)
E/AndroidRuntime(18185): at android.media.MediaScannerConnection$$ExternalSyntheticLambda0.run(Unknown Source:6)
E/AndroidRuntime(18185): at android.os.Handler.handleCallback(Handler.java:938)
E/AndroidRuntime(18185): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(18185): at android.os.Looper.loopOnce(Looper.java:233)
E/AndroidRuntime(18185): at android.os.Looper.loop(Looper.java:344)
E/AndroidRuntime(18185): at android.os.HandlerThread.run(HandlerThread.java:67)
E/AndroidRuntime(18185): Caused by: java.lang.ClassNotFoundException: j$.util.DesugarTimeZone
E/AndroidRuntime(18185): ... 17 more
My code of image picker is given below
Future pickFromCamera() async {
var pickedFile = await ImagePicker().pickImage(
source: ImageSource.camera,
preferredCameraDevice: CameraDevice.front,
imageQuality: 40,
maxHeight: 1200,
maxWidth: 1080,
);
var tempImage = pickedFile == null ? null : File(pickedFile.path);
if (tempImage != null) {
imageEdit.value = null;
image.value = File(tempImage.path);
File rotatedImage = await FlutterExifRotation.rotateImage(path: image.value!.path);
base64Image.value = await convertToBase64(rotatedImage);
update();
}
}
my image compressor and base64 converter code.
Future convertToBase64(File? img) async {
File? result = await CompressImagesFlutter().compressImage(img!.path, quality: 20);
File rotatedImage = await FlutterExifRotation.rotateImage(path: result!.path);
return base64Encode(rotatedImage.readAsBytesSync());
}

Related

Flutter - The argument type 'File' can't be assigned to the parameter type 'File?'

I am building a Flutter app and currently I am trying to implement a method that can pick an image file but I am getting an error that says The argument type 'File' can't be assigned to the parameter type 'File?'. Does anyone have an idea on how I can solve this?
getImageDialogue(ImageSource source) async {
final ImagePicker _pickedFile = ImagePicker();
final XFile? image = await _pickedFile.pickImage(source: source);
if (image != null) {
media.add(EventMediaModel(
//This is the line where I am getting the error on File(image.path)
image: File(image.path), video: null, isVideo: false));
setState(() {});
Navigator.pop(context);
}
}
It might help to create a non-nullable "image" variable in your EventMediaModel.
Future<void> getImageDialogue(ImageSource source) async {
final ImagePicker _pickedFile = ImagePicker();
final XFile? image = await _pickedFile.pickImage(source: source);
if (image != null && image.path != '') {
File file = File(image.path);
media.add(EventMediaModel(image: file, video: null, isVideo: false));
setState(() {});
Navigator.pop(context);
}
}

FilePicker Unhandled Exception: FileSystemException: Cannot copy file to 'Directory:

` onPressed: () async {
FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result != null) {
File file = File(result.files.single.path.toString());
} else {
// User canceled the picker
}
if (result != null) {
PlatformFile file = result.files.first;
print('222222222222222222222222221');
print(file.name);
print("5555555555555555555555555555555");
print(file.bytes);
print(file.size);
print(file.extension);
print("6666666666666666666666666");
print(file.path);
final newFile = await saveFilePermanently(file);
} else {
// User canceled the picker
}
}, `
` Future<File> saveFilePermanently(PlatformFile file) async{
final appStorage = await getApplicationDocumentsDirectory();
final newFile = File('${appStorage}/${file.name}');
return File(file.path!).copy(newFile.path);
} `
i got this error
E/flutter ( 833): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FileSystemException: Cannot copy file to 'Directory: '/data/user/0/com.sangvaleap.online_course/app_flutter'/X2Download.com - Imagine Dragons x J.I.D - Enemy (from the series Arcane League of Legends) (128 kbps).mp3', path = '/data/user/0/com.sangvaleap.online_course/cache/file_picker/X2Download.com - Imagine Dragons x J.I.D - Enemy (from the series Arcane League of Legends) (128 kbps).mp3' (OS Error: No such file or directory, errno = 2)

Flutter Secure Storage Platform Exception

I'm using flutter secure storage (^5.0.2) to save tokens but I'm getting the following error when storage.write() is called on an emulator (I'm using Pixel 5 API 30) whereas when I use it on my physical device (Honor 8x) it's working well :
PlatformException (PlatformException(Exception encountered, write, java.lang.NullPointerException: Attempt to invoke interface method 'byte[] com.it_nomads.fluttersecurestorage.ciphers.StorageCipher.encrypt(byte[])' on a null object reference
at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.write(FlutterSecureStoragePlugin.java:202)
at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.access$300(FlutterSecureStoragePlugin.java:37)
at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin$MethodRunner.run(FlutterSecureStoragePlugin.java:289)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.os.HandlerThread.run(HandlerThread.java:67)
, null))
Here is the output of the debug :
W/KeyStore( 2975): KeyStore exception
W/KeyStore( 2975): android.os.ServiceSpecificException: (code 7)
W/KeyStore( 2975): at android.os.Parcel.createExceptionOrNull(Parcel.java:2387)
W/KeyStore( 2975): at android.os.Parcel.createException(Parcel.java:2357)
W/KeyStore( 2975): at android.os.Parcel.readException(Parcel.java:2340)
W/KeyStore( 2975): at android.os.Parcel.readException(Parcel.java:2282)
W/KeyStore( 2975): at android.security.keystore.IKeystoreService$Stub$Proxy.get(IKeystoreService.java:988)
W/KeyStore( 2975): at android.security.KeyStore.get(KeyStore.java:233)
W/KeyStore( 2975): at android.security.KeyStore.get(KeyStore.java:222)
W/KeyStore( 2975): at android.security.keystore.AndroidKeyStoreSpi.engineGetCertificate(AndroidKeyStoreSpi.java:165)
W/KeyStore( 2975): at java.security.KeyStore.getCertificate(KeyStore.java:1120)
W/KeyStore( 2975): at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.getPublicKey(RSACipher18Implementation.java:90)
W/KeyStore( 2975): at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.wrap(RSACipher18Implementation.java:39)
W/KeyStore( 2975): at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.<init>(StorageCipher18Implementation.java:52)
W/KeyStore( 2975): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.ensureInitialized(FlutterSecureStoragePlugin.java:95)
W/KeyStore( 2975): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.access$100(FlutterSecureStoragePlugin.java:37)
W/KeyStore( 2975): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin$MethodRunner.run(FlutterSecureStoragePlugin.java:284)
W/KeyStore( 2975): at android.os.Handler.handleCallback(Handler.java:938)
W/KeyStore( 2975): at android.os.Handler.dispatchMessage(Handler.java:99)
W/KeyStore( 2975): at android.os.Looper.loop(Looper.java:223)
W/KeyStore( 2975): at android.os.HandlerThread.run(HandlerThread.java:67)
E/FlutterSecureStoragePl( 2975): StorageCipher initialization failed
E/FlutterSecureStoragePl( 2975): java.lang.Exception: No certificate found under alias: com.example.applielikya.FlutterSecureStoragePluginKey
E/FlutterSecureStoragePl( 2975): at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.getPublicKey(RSACipher18Implementation.java:92)
E/FlutterSecureStoragePl( 2975): at com.it_nomads.fluttersecurestorage.ciphers.RSACipher18Implementation.wrap(RSACipher18Implementation.java:39)
E/FlutterSecureStoragePl( 2975): at com.it_nomads.fluttersecurestorage.ciphers.StorageCipher18Implementation.<init>(StorageCipher18Implementation.java:52)
E/FlutterSecureStoragePl( 2975): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.ensureInitialized(FlutterSecureStoragePlugin.java:95)
E/FlutterSecureStoragePl( 2975): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin.access$100(FlutterSecureStoragePlugin.java:37)
E/FlutterSecureStoragePl( 2975): at com.it_nomads.fluttersecurestorage.FlutterSecureStoragePlugin$MethodRunner.run(FlutterSecureStoragePlugin.java:284)
E/FlutterSecureStoragePl( 2975): at android.os.Handler.handleCallback(Handler.java:938)
E/FlutterSecureStoragePl( 2975): at android.os.Handler.dispatchMessage(Handler.java:99)
E/FlutterSecureStoragePl( 2975): at android.os.Looper.loop(Looper.java:223)
E/FlutterSecureStoragePl( 2975): at android.os.HandlerThread.run(HandlerThread.java:67)
I don't know if it could be related, but I have min Sdk 19 in my code, due to some packages needing this version.
I need this to start both my physical device and an emulator on Vscode with two different accounts in my app (an admin and an user) to check the transmission of notifications from one to another, if another way to achieve that exists I'd also be up to know.
This is the code :
import 'package:applielikya/models/login_response.dart';
import 'package:applielikya/models/user.dart';
import 'package:applielikya/services/auth/login.dart';
import 'package:applielikya/views/homepage.dart';
import 'package:applielikya/widgets/createRoute.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter/material.dart';
class LoginPage extends StatefulWidget {
const LoginPage({Key? key}) : super(key: key);
#override
State<LoginPage> createState() => LoginPageState();
}
enum ButtonState { init, loading, done }
class LoginPageState extends State<LoginPage> {
final Future<SharedPreferences> _prefs = SharedPreferences.getInstance();
final FlutterSecureStorage storage = const FlutterSecureStorage();
ButtonState _state = ButtonState.init;
bool _passwordVisible = false;
final TextEditingController _usernameController = TextEditingController(text: "kentay");
final TextEditingController _passwordController = TextEditingController(text: "kentay");
bool _isAuth = false;
String _responseMessage = "";
void saveToken(SuccessResponse response) async {
await storage.write(key: "accessToken", value: response.accessToken);
await storage.write(key: "refreshToken", value: response.refreshToken);
}
void saveUser(UserResponse user) async {
final SharedPreferences prefs = await _prefs;
prefs.setString('username', user.username as String);
prefs.setInt('id', user.id as int);
prefs.setString('role', user.role as String);
if (user.role == "prof") {
prefs.setString("firstname", user.firstname!);
prefs.setString("lastname", user.lastname!);
prefs.setString("email", user.email!);
}
}
submitLogin() async {
setState(() => _state = ButtonState.loading);
final response = await login(
UserRequest(username : _usernameController.text, password: _passwordController.text)
);
setState(() {
_isAuth = response.auth;
_state = ButtonState.done;
});
if (response is SuccessResponse) {
saveToken(response);
saveUser(response.user);
setState(() => _state = ButtonState.init);
Navigator.of(context).push(
createRoute(
const MyHomePage(),
const Offset(0.0, 1.0),
Offset.zero,
Curves.easeInCirc
)
);
} else {
if (response is ErrorResponse) {
setState(() => _responseMessage = response.message);
}
}
}
In case it helps someone, I fixed it by clearing datas and cache of the app on my emulator in the parameters of the device.
i think the isseus was form arecent update.
just add the option below for android.
final FlutterSecureStorage storage = const FlutterSecureStorage(
aOptions: AndroidOptions(
encryptedSharedPreferences: true,
),
);

Unhandled Exception: MissingPluginException(No implementation found for method file on channel video_thumbnail)

When i use ImagePicker.pickVideo(source: ImageSource.camera) it's work perfectly but if i use ImagePicker.pickVideo(source: ImageSource.gallery) i receive this error
Unhandled Exception: MissingPluginException(No implementation found for method file on channel video_thumbnail)
getVideo() async {
final pickedFile = await ImagePicker.pickVideo(source: ImageSource.gallery);
if(pickedFile != null){
videoAddress = pickedFile.path;
final thumbnailPath = await VideoThumbnail.thumbnailFile(
video: videoAddress,
imageFormat: ImageFormat.JPEG,
quality: 75);
videoPosterAddress = thumbnailPath;
setState(() { videoPoster = File(thumbnailPath); });
}
}
videoPoster contain thumbnail file.

SignelR Flutter Invalid argument(s): Response Content-Type not supported: [application/json; charset=UTF-8]

I get this exception when trying to use signalr_client library:
Unhandled Exception: Invalid argument(s): Response Content-Type not supported: [application/json; charset=UTF-8]
It looks like I can connect to server but not successful in getting response
my Code:
Future<void> openChatConnection() async {
if (_hubConnection == null) {
_hubConnection = HubConnectionBuilder().withUrl(_serverUrl).build();
_hubConnection.on("RecieveNotification", null);
}
if (_hubConnection.state != HubConnectionState.Connected) {
await _hubConnection.start();
}
}
Future<void> sendChatMessage(String chatMessage) async {
if( chatMessage == null ||chatMessage.length == 0){
return;
}
await openChatConnection();
_hubConnection.invoke("SendNotifications");
}
void _handleIncommingChatMessage(List<Object> args){
....
}
Appreciate any help
Thanks in advance
For those who have response type problem you can just provide an id to the query parameter of your server url just like this:
HubConnectionBuilder()
.withUrl('https://serverUrl.com?id=1')
.build();