Restructure to make more sense

This commit is contained in:
zontreck 2024-07-24 17:33:55 -07:00
parent 6172338a00
commit 72d6c2ce34
3 changed files with 34 additions and 6 deletions

View file

@ -10,6 +10,7 @@ import 'package:libac_dart/nbt/impl/CompoundTag.dart';
import 'package:nbteditor/Constants.dart';
import 'package:nbteditor/Consts2.dart';
import 'package:nbteditor/SessionData.dart';
import 'package:nbteditor/main.dart';
import 'package:nbteditor/tags/CompoundTag.dart';
import 'package:nbteditor/tags/Tag.dart';
@ -89,6 +90,10 @@ class EditorState extends State<Editor> {
leading: const Icon(Icons.folder),
subtitle: const Text("Open an existing NBT Document for editing"),
onTap: () async {
if (await needsPermissionsPage()) {
Navigator.pushNamed(context, "/perms");
return;
}
String? filePath;
var result = await FilePicker.platform.pickFiles();
if (result != null) {
@ -131,6 +136,10 @@ class EditorState extends State<Editor> {
image: AssetImage("Icons/PNG/Compound.png"),
),
onTap: () async {
if (await needsPermissionsPage()) {
Navigator.pushNamed(context, "/perms");
return;
}
var result = await showDialog(
context: context,
builder: (builder) {
@ -181,6 +190,10 @@ class EditorState extends State<Editor> {
image: AssetImage("Icons/PNG/String.png"),
),
onTap: () async {
if (await needsPermissionsPage()) {
Navigator.pushNamed(context, "/perms");
return;
}
// Prompt for where to save
print("Begin picking file to save to");
var FSL = await FilePicker.platform.saveFile(bytes: Uint8List(0));

View file

@ -7,20 +7,21 @@ import 'package:nbteditor/pages/SNBTEditor.dart';
import 'package:nbteditor/pages/permsrequired.dart';
import 'package:permission_handler/permission_handler.dart';
void main() {
runApp(const MainApp());
void main() async {
runApp(MainApp());
}
class MainApp extends StatelessWidget {
const MainApp({super.key});
MainApp({
super.key,
});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(),
routes: {
"/": (context) => const StartPage(),
"/edit": (context) => const Editor(),
"/": (context) => const Editor(),
"/add": (context) => const AddPage(),
"/snbt": (context) => const SnbtEdit(),
"/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 {
const StartPage({super.key});

View file

@ -32,7 +32,7 @@ class PermissionsRequiredPage extends StatelessWidget {
"The storage permission is reporting it is permanently denied. Please open settings and allow that permission.")));
} else if (stat.isGranted) {
Future.delayed(const Duration(seconds: 5), () {
Navigator.pushReplacementNamed(context, "/edit");
Navigator.pop(context);
});
}
}