web compatibility

This commit is contained in:
jusax23 2023-06-02 13:34:54 +02:00
parent ee25bba5b8
commit 87abe69716
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41

View file

@ -1,6 +1,5 @@
import 'dart:convert';
import 'dart:io';
import 'dart:math';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
@ -174,10 +173,17 @@ class MainPageState extends State<MainPage> {
type: FileType.custom,
allowedExtensions: ['json'],
allowMultiple: false);
if (result != null && result.files.single.path != null) {
File file = File(result.files.single.path ?? "");
String data = file.readAsStringSync();
if (result != null) {
String data = "";
if (!kIsWeb && result.files.single.path != null) {
File file = File(result.files.single.path ?? "");
data = file.readAsStringSync();
} else {
PlatformFile pfile = result.files.first;
data = String.fromCharCodes(pfile.bytes?.map((e) => e) ?? []);
}
try {
if (data.isEmpty) throw ErrorDescription("Empty File!");
Vault v = Vault.fromJson(jsonDecode(data));
setState(() {
_vaults.add(v);