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:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'dart:math';
|
|
||||||
|
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
@ -174,10 +173,17 @@ class MainPageState extends State<MainPage> {
|
||||||
type: FileType.custom,
|
type: FileType.custom,
|
||||||
allowedExtensions: ['json'],
|
allowedExtensions: ['json'],
|
||||||
allowMultiple: false);
|
allowMultiple: false);
|
||||||
if (result != null && result.files.single.path != null) {
|
if (result != null) {
|
||||||
File file = File(result.files.single.path ?? "");
|
String data = "";
|
||||||
String data = file.readAsStringSync();
|
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 {
|
try {
|
||||||
|
if (data.isEmpty) throw ErrorDescription("Empty File!");
|
||||||
Vault v = Vault.fromJson(jsonDecode(data));
|
Vault v = Vault.fromJson(jsonDecode(data));
|
||||||
setState(() {
|
setState(() {
|
||||||
_vaults.add(v);
|
_vaults.add(v);
|
||||||
|
|
Loading…
Reference in a new issue