mirror of
https://github.com/zontreck/NBTEditor
synced 2024-11-21 13:48:56 -07:00
Restructure to make more sense
This commit is contained in:
parent
6172338a00
commit
72d6c2ce34
3 changed files with 34 additions and 6 deletions
|
@ -10,6 +10,7 @@ import 'package:libac_dart/nbt/impl/CompoundTag.dart';
|
||||||
import 'package:nbteditor/Constants.dart';
|
import 'package:nbteditor/Constants.dart';
|
||||||
import 'package:nbteditor/Consts2.dart';
|
import 'package:nbteditor/Consts2.dart';
|
||||||
import 'package:nbteditor/SessionData.dart';
|
import 'package:nbteditor/SessionData.dart';
|
||||||
|
import 'package:nbteditor/main.dart';
|
||||||
import 'package:nbteditor/tags/CompoundTag.dart';
|
import 'package:nbteditor/tags/CompoundTag.dart';
|
||||||
import 'package:nbteditor/tags/Tag.dart';
|
import 'package:nbteditor/tags/Tag.dart';
|
||||||
|
|
||||||
|
@ -89,6 +90,10 @@ 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 {
|
||||||
|
if (await needsPermissionsPage()) {
|
||||||
|
Navigator.pushNamed(context, "/perms");
|
||||||
|
return;
|
||||||
|
}
|
||||||
String? filePath;
|
String? filePath;
|
||||||
var result = await FilePicker.platform.pickFiles();
|
var result = await FilePicker.platform.pickFiles();
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
@ -131,6 +136,10 @@ class EditorState extends State<Editor> {
|
||||||
image: AssetImage("Icons/PNG/Compound.png"),
|
image: AssetImage("Icons/PNG/Compound.png"),
|
||||||
),
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
if (await needsPermissionsPage()) {
|
||||||
|
Navigator.pushNamed(context, "/perms");
|
||||||
|
return;
|
||||||
|
}
|
||||||
var result = await showDialog(
|
var result = await showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (builder) {
|
builder: (builder) {
|
||||||
|
@ -181,6 +190,10 @@ class EditorState extends State<Editor> {
|
||||||
image: AssetImage("Icons/PNG/String.png"),
|
image: AssetImage("Icons/PNG/String.png"),
|
||||||
),
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
if (await needsPermissionsPage()) {
|
||||||
|
Navigator.pushNamed(context, "/perms");
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 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 FSL = await FilePicker.platform.saveFile(bytes: Uint8List(0));
|
var FSL = await FilePicker.platform.saveFile(bytes: Uint8List(0));
|
||||||
|
|
|
@ -7,20 +7,21 @@ import 'package:nbteditor/pages/SNBTEditor.dart';
|
||||||
import 'package:nbteditor/pages/permsrequired.dart';
|
import 'package:nbteditor/pages/permsrequired.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
||||||
void main() {
|
void main() async {
|
||||||
runApp(const MainApp());
|
runApp(MainApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
class MainApp extends StatelessWidget {
|
class MainApp extends StatelessWidget {
|
||||||
const MainApp({super.key});
|
MainApp({
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
theme: ThemeData.dark(),
|
theme: ThemeData.dark(),
|
||||||
routes: {
|
routes: {
|
||||||
"/": (context) => const StartPage(),
|
"/": (context) => const Editor(),
|
||||||
"/edit": (context) => const Editor(),
|
|
||||||
"/add": (context) => const AddPage(),
|
"/add": (context) => const AddPage(),
|
||||||
"/snbt": (context) => const SnbtEdit(),
|
"/snbt": (context) => const SnbtEdit(),
|
||||||
"/perms": (context) => const PermissionsRequiredPage()
|
"/perms": (context) => const PermissionsRequiredPage()
|
||||||
|
@ -29,6 +30,20 @@ class MainApp extends StatelessWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool needsPermissions() {
|
||||||
|
return Platform.isIOS || Platform.isMacOS || Platform.isAndroid;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> needsPermissionsPage() async {
|
||||||
|
if (needsPermissions()) {
|
||||||
|
if (await Permission.manageExternalStorage.isDenied) {
|
||||||
|
return true;
|
||||||
|
} else
|
||||||
|
return false;
|
||||||
|
} else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
class StartPage extends StatefulWidget {
|
class StartPage extends StatefulWidget {
|
||||||
const StartPage({super.key});
|
const StartPage({super.key});
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ class PermissionsRequiredPage extends StatelessWidget {
|
||||||
"The storage permission is reporting it is permanently denied. Please open settings and allow that permission.")));
|
"The storage permission is reporting it is permanently denied. Please open settings and allow that permission.")));
|
||||||
} else if (stat.isGranted) {
|
} else if (stat.isGranted) {
|
||||||
Future.delayed(const Duration(seconds: 5), () {
|
Future.delayed(const Duration(seconds: 5), () {
|
||||||
Navigator.pushReplacementNamed(context, "/edit");
|
Navigator.pop(context);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue