mirror of
https://github.com/zontreck/NBTEditor
synced 2024-11-21 13:48:56 -07:00
Fix file saving on Android
This commit is contained in:
parent
098d8479c8
commit
3ced797407
6 changed files with 39 additions and 21 deletions
|
@ -4,5 +4,7 @@
|
||||||
to allow setting breakpoints, to provide hot reload, etc.
|
to allow setting breakpoints, to provide hot reload, etc.
|
||||||
-->
|
-->
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:label="NBT Editor"
|
android:label="NBT Editor"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
|
|
|
@ -4,5 +4,7 @@
|
||||||
to allow setting breakpoints, to provide hot reload, etc.
|
to allow setting breakpoints, to provide hot reload, etc.
|
||||||
-->
|
-->
|
||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_file_dialog/flutter_file_dialog.dart';
|
|
||||||
import 'package:flutter_treeview/flutter_treeview.dart';
|
import 'package:flutter_treeview/flutter_treeview.dart';
|
||||||
import 'package:libac_dart/nbt/NbtIo.dart';
|
import 'package:libac_dart/nbt/NbtIo.dart';
|
||||||
import 'package:libac_dart/nbt/SnbtIo.dart';
|
import 'package:libac_dart/nbt/SnbtIo.dart';
|
||||||
|
@ -89,11 +89,12 @@ class EditorState extends State<Editor> {
|
||||||
leading: const Icon(Icons.folder),
|
leading: const Icon(Icons.folder),
|
||||||
subtitle: const Text("Open an existing NBT Document for editing"),
|
subtitle: const Text("Open an existing NBT Document for editing"),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
String? filePath = await FlutterFileDialog.pickFile(
|
String? filePath;
|
||||||
params: const OpenFileDialogParams());
|
var result = await FilePicker.platform.pickFiles();
|
||||||
if (filePath != null) {
|
if (result != null) {
|
||||||
// Do something with the selected file path
|
// Do something with the selected file path
|
||||||
print('Selected file path: $filePath');
|
print('Selected file path: $filePath');
|
||||||
|
filePath = result!.files.first.path;
|
||||||
} else {
|
} else {
|
||||||
// User canceled the picker
|
// User canceled the picker
|
||||||
print('File selection canceled.');
|
print('File selection canceled.');
|
||||||
|
@ -150,24 +151,27 @@ class EditorState extends State<Editor> {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
Uint8List u8l = Uint8List(0);
|
|
||||||
if (result == null) {
|
|
||||||
// Save uncompressed
|
|
||||||
u8l = await NbtIo.writeToStream(
|
|
||||||
controller.children[0].data as CompoundTag);
|
|
||||||
} else {
|
|
||||||
u8l = await NbtIo.writeToStreamCompressed(
|
|
||||||
controller.children[0].data as CompoundTag);
|
|
||||||
}
|
|
||||||
// Prompt for where to save
|
// Prompt for where to save
|
||||||
print("Begin picking file to save to");
|
print("Begin picking file to save to");
|
||||||
var filePath = await FlutterFileDialog.saveFile();
|
var FSL = await FilePicker.platform.saveFile(bytes: Uint8List(0));
|
||||||
|
String? filePath;
|
||||||
|
|
||||||
|
if (FSL != null) {
|
||||||
|
filePath = FSL;
|
||||||
|
}
|
||||||
|
|
||||||
if (filePath == null) {
|
if (filePath == null) {
|
||||||
print("No file selected");
|
print("No file selected");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
print(filePath);
|
print(filePath);
|
||||||
|
CompoundTag tag = controller.children[0].data as CompoundTag;
|
||||||
|
if (result == null) {
|
||||||
|
// Save uncompressed
|
||||||
|
NbtIo.write(filePath, tag);
|
||||||
|
} else {
|
||||||
|
NbtIo.writeCompressed(filePath, tag);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
|
@ -179,8 +183,13 @@ class EditorState extends State<Editor> {
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
// Prompt for where to save
|
// Prompt for where to save
|
||||||
print("Begin picking file to save to");
|
print("Begin picking file to save to");
|
||||||
String? filePath = await FlutterFileDialog.saveFile(
|
var FSL = await FilePicker.platform.saveFile(bytes: Uint8List(0));
|
||||||
params: SaveFileDialogParams());
|
String? filePath;
|
||||||
|
|
||||||
|
if (FSL != null) {
|
||||||
|
filePath = FSL;
|
||||||
|
}
|
||||||
|
|
||||||
if (filePath == null) {
|
if (filePath == null) {
|
||||||
print("No file selected");
|
print("No file selected");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -53,7 +53,9 @@ class StartPageState extends State<StartPage> {
|
||||||
Navigator.pushReplacementNamed(context, "/perms");
|
Navigator.pushReplacementNamed(context, "/perms");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Navigator.pushReplacementNamed(context, "/edit");
|
await Future.delayed(Duration(seconds: 2), () {
|
||||||
|
Navigator.pushReplacementNamed(context, "/edit");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,10 @@ environment:
|
||||||
sdk: '>=3.1.5 <4.0.0'
|
sdk: '>=3.1.5 <4.0.0'
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
|
file_picker: ^8.0.0+1
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flutter_code_editor: ^0.3.2
|
flutter_code_editor: ^0.3.2
|
||||||
flutter_file_dialog: ^3.0.2
|
|
||||||
flutter_highlight: ^0.7.0
|
flutter_highlight: ^0.7.0
|
||||||
flutter_treeview: ^1.0.7+1
|
flutter_treeview: ^1.0.7+1
|
||||||
libac_dart:
|
libac_dart:
|
||||||
|
|
Loading…
Reference in a new issue