Unhandled Exception: FileSystemException: Cannot retrieve length of file - flutter

When I try to rename a File it throws a FileSystemException Exception
this is the exception:
E/flutter (12252): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FileSystemException: Cannot retrieve length of file, path = '' (OS Error: No such file or directory, errno = 2)
this is the code:
for (String path in _files.paths)
{
for (File file in _pickedFiles)
{
if(file.path == path)
{
await _pickedFiles.last.rename(_path.withoutExtension(file.path) + '()' + _path.extension(file.path));
}
}
}
Please help me
Thank you.

Related

How to unzip files to device memory in flutter

I was able to download file in zip format from remote server, but when unzip the file containing videos, I got error like this
E/flutter (11680): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: FileSystemException: Creation failed, path = 'out' (OS Error: Read-only file system, errno = 30)
E/flutter (11680): #0 _Directory.createSync (dart:io/directory_impl.dart:133:7)
E/flutter (11680): #1 extractArchiveToDisk
package:archive/…/io/extract_archive_to_disk.dart:21
E/flutter (11680): #2 ZipService.unzipSigns
package:gsl_distionary/services/zip_service.dart:13
E/flutter (11680): <asynchronous suspension>
Below is my code to unzip file using archive package:
static Future unzipSigns(String fileName) async {
final dir = await getApplicationSupportDirectory();
final bool isZippedFile = await File("${dir.path}/$fileName").exists();
if (isZippedFile) {
final inputStream = InputFileStream("${dir.path}/$fileName");
final archive = ZipDecoder().decodeBuffer(inputStream);
extractArchiveToDisk(archive, 'out');
}
}
What did I miss?

why i get this error when i try to run mu sign in function in flutter?

E/flutter ( 8448): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FormatException: Unexpected character (at character 1)
E/flutter ( 8448):
E/flutter ( 8448): ^
enter image description here
Encode the body data when post method is used
var res = await http.post(Uri.parse(url), body: jsonEncode(data));

Unable to play .m3u8 file with flutter package better player

I have a .m3u8 file that contains information about a video but I am unable to play it using the BetterPlayer Flutter package.
This is my sample code
var dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.file,
"/var/mobile/Containers/Data/Application/B0391873-25D4-471A-AB13-05D5FF8701F9/Documents/content.publicId/test.m3u8",
subtitles: null,
headers: {"cookie":"COOKIE_FOR_AWS_CLOUDFRONT_ACCESS"},
liveStream: true
);
But I keep getting this error:
GetDataFromUrl failed: Invalid argument(s): No host specified in URI /var/mobile/Containers/Data/Application/FE19C886-73B8-49C0-A770-6BAEAD354947/Documents/content.publicId/test.m3u8
Failed to load video: Error Domain=CoreMediaErrorDomain Code=-12865
"(null)" [VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception:
PlatformException(VideoError, Failed to load video: The operation
couldn’t be completed. (CoreMediaErrorDomain error -12865.), null,
null)
These are the contents of the .m3u8 file:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:37
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-KEY:METHOD=AES-128, URI="https://PATH_TO_ENCRYPTION_KEY",IV=0x413873f3924c752d99c7083c0c99931c
#EXTINF:36.440000, https://example.com/test_480p_0000.ts
#EXTINF:28.040000, https://example.com/test_480p_0001.ts
#EXTINF:28.360000, https://example.com/test_480p_0002.ts
#EXTINF:29.920000, https://example.com/test_480p_0003.ts
#EXTINF:36.920000, https://example.com/test_480p_0004.ts
#EXTINF:21.040000, https://example.com/test_480p_0005.ts
#EXT-X-ENDLIST

How to connect to Localhost?

I'm here new, I'm learning flutter and I need login with this:
POST http://localhost:3000/api/users/session
But I still can't login :( I'm waiting 5 minutes and still there is a loading screen with no effects.
I have try
So I have have made a this api_service with this tutorial made https://www.youtube.com/watch?v=_Kw4BfNX1-4
here is my api_service.dart
import 'package:http/http.dart' as http;
import 'dart:convert';
import '../model/login_model.dart';
class APIService {
Future<LoginResponseModel>
login(LoginRequestModel requestModel) async {
String url = "http://localhost:3000/api/users/session";
final response = await http.post(url, body: requestModel.toJson());
if (response.statusCode == 200 || response.statusCode == 400) {
return LoginResponseModel.fromJson(
json.decode(response.body),
);
} else {
throw Exception('Failed to load data!');
}
}
}
Here is debug console:
E/flutter (10967): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)]
Unhandled Exception: SocketException: OS Error: Connection refused,
errno = 111, address = localhost, port = 58856 E/flutter (10967):
I'm try with this page:
https://medium.com/#podcoder/connecting-flutter-application-to-localhost-a1022df63130
I change String url = "http://localhost:3000/api/users/session"; to
String url = "http://10.0.2.2:3000/api/users/session";
in my debug console i have completely different messages, but stilll
don't work :(
E/flutter (10967):
[ERROR:flutter/lib/ui/ui_dart_state.cc(186)]
Unhandled Exception: Bad state: Insecure HTTP is not allowed by
platform: http://10.0.2.2:3000/api/users/session
E/flutter (10967): #0 _HttpClient._openUrl
(dart:_http/http_impl.dart:2434:7)
E/flutter (10967): #1 _HttpClient.openUrl
(dart:_http/http_impl.dart:2341:7)
E/flutter (10967): #2 IOClient.send
package:http/src/io_client.dart:31
(...) to #28 and the last ist E/flutter (10967):
Fix for the Error Unhandled Exception: Bad state: Insecure HTTP is not allowed by platform
Flutter terms http as an insecure source Therefore you should either use https or set android:usesCleartextTraffic to true in AndroidManifest
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="io.flutter.app.FlutterApplication"
android:label="receipt"
android:usesCleartextTraffic="true" // Add this line
android:icon="#mipmap/ic_launcher">

OleDbException was unhandled

I'm using Access as database, but it seems the OleDbDataReader reader = cmd.ExecuteReader(); throws the error:
OleDbException was unhandled