Start trying to fix permission errors on Android

This commit is contained in:
zontreck 2024-07-24 07:07:34 -07:00
parent e62fc5cf91
commit 9055c8cb0a
8 changed files with 94 additions and 7 deletions

View file

@ -1 +1 @@
const VERSION = "1.0722.24+1506"; const VERSION = "1.0724.24+0706";

View file

@ -1,3 +1,4 @@
import 'dart:io';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -12,6 +13,7 @@ import 'package:nbteditor/Consts2.dart';
import 'package:nbteditor/SessionData.dart'; import 'package:nbteditor/SessionData.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';
import 'package:permission_handler/permission_handler.dart';
class Editor extends StatefulWidget { class Editor extends StatefulWidget {
const Editor({super.key}); const Editor({super.key});
@ -127,7 +129,7 @@ class EditorState extends State<Editor> {
title: const Text("S A V E N B T"), title: const Text("S A V E N B T"),
subtitle: const Text("Save to NBT"), subtitle: const Text("Save to NBT"),
leading: const Image( leading: const Image(
image: AssetImage("Icons/PNG/nbteditor.png"), image: AssetImage("Icons/PNG/Compound.png"),
), ),
onTap: () async { onTap: () async {
var result = await showDialog( var result = await showDialog(
@ -161,8 +163,7 @@ class EditorState extends State<Editor> {
} }
// 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 params = SaveFileDialogParams(data: u8l); var filePath = await FlutterFileDialog.saveFile();
var filePath = await FlutterFileDialog.saveFile(params: params);
if (filePath == null) { if (filePath == null) {
print("No file selected"); print("No file selected");

View file

@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:nbteditor/Editor.dart'; import 'package:nbteditor/Editor.dart';
import 'package:nbteditor/pages/AddPage.dart'; import 'package:nbteditor/pages/AddPage.dart';
import 'package:nbteditor/pages/SNBTEditor.dart'; import 'package:nbteditor/pages/SNBTEditor.dart';
import 'package:nbteditor/pages/permsrequired.dart';
import 'package:permission_handler/permission_handler.dart';
void main() { void main() {
runApp(const MainApp()); runApp(const MainApp());
@ -15,10 +17,45 @@ class MainApp extends StatelessWidget {
return MaterialApp( return MaterialApp(
theme: ThemeData.dark(), theme: ThemeData.dark(),
routes: { routes: {
"/": (context) => const Editor(), "/": (context) => StartPage(),
"/edit": (context) => const Editor(),
"/add": (context) => const AddPage(), "/add": (context) => const AddPage(),
"/snbt": (context) => const SnbtEdit(), "/snbt": (context) => const SnbtEdit(),
"/perms": (context) => PermissionsRequiredPage()
}, },
); );
} }
} }
class StartPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return StartPageState();
}
}
class StartPageState extends State<StartPage> {
@override
void didChangeDependencies() {
checkPermissions();
}
Future<void> checkPermissions() async {
if (await Permission.manageExternalStorage.isDenied) {
await Future.delayed(Duration(seconds: 5), () {
Navigator.pushReplacementNamed(context, "/perms");
});
} else {
Navigator.pushReplacementNamed(context, "/edit");
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [Image(image: AssetImage("Icons/PNG/nbteditor.png"))],
),
);
}
}

View file

@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
import 'package:nbteditor/Constants.dart';
import 'package:permission_handler/permission_handler.dart';
class PermissionsRequiredPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("NBT Editor - Permissions Denied"),
backgroundColor: Constants.TITLEBAR_COLOR,
),
body: Padding(
padding: EdgeInsets.all(8),
child: SingleChildScrollView(
child: Column(
children: [
ListTile(
title: Text(
"We require only one permission, it is being denied by your device. Please grant file permissions to be able to open or save files."),
),
ElevatedButton(
onPressed: () async {
if (await Permission.manageExternalStorage.isDenied) {
var stat =
await Permission.manageExternalStorage.request();
if (stat.isPermanentlyDenied) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"The storage permission is reporting it is permanently denied. Please open settings and allow that permission.")));
} else if (stat.isGranted) {
Future.delayed(Duration(seconds: 5), () {
Navigator.pushReplacementNamed(context, "/edit");
});
}
}
},
child: Text("GRANT"))
],
),
),
));
}
}

View file

@ -1,7 +1,7 @@
name: nbteditor name: nbteditor
description: A Minecraft NBT Editor written in Flutter description: A Minecraft NBT Editor written in Flutter
publish_to: 'none' publish_to: 'none'
version: 1.0722.24+1907 version: 1.0724.24+0706
environment: environment:
@ -17,6 +17,7 @@ dependencies:
libac_dart: libac_dart:
hosted: https://git.zontreck.com/api/packages/AriasCreations/pub/ hosted: https://git.zontreck.com/api/packages/AriasCreations/pub/
version: 1.2.072224+1906 version: 1.2.072224+1906
permission_handler: ^11.3.1
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

View file

@ -6,9 +6,12 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h> #include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
UrlLauncherWindowsRegisterWithRegistrar( UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows")); registry->GetRegistrarForPlugin("UrlLauncherWindows"));
} }

View file

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
permission_handler_windows
url_launcher_windows url_launcher_windows
) )

View file

@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "NBT Editor" #define MyAppName "NBT Editor"
#define MyAppVersion "1.0722.24.1506" #define MyAppVersion "1.0724.24+0706"
#define MyAppPublisher "Piccari Creations" #define MyAppPublisher "Piccari Creations"
#define MyAppURL "https://zontreck.com" #define MyAppURL "https://zontreck.com"
#define MyAppExeName "nbteditor.exe" #define MyAppExeName "nbteditor.exe"