From 87abe69716b536283042d23fd5b554fc6b18c4b3 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Fri, 2 Jun 2023 13:34:54 +0200 Subject: [PATCH] web compatibility --- lib/main.dart | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 0463ec5..f49104c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 { 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);