web compatibility
This commit is contained in:
parent
ee25bba5b8
commit
87abe69716
1 changed files with 10 additions and 4 deletions
|
@ -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) {
|
||||
if (result != null) {
|
||||
String data = "";
|
||||
if (!kIsWeb && result.files.single.path != null) {
|
||||
File file = File(result.files.single.path ?? "");
|
||||
String data = file.readAsStringSync();
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue