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);