diff --git a/lib/Alert.dart b/lib/Alert.dart index 26eab4d..9ddd317 100644 --- a/lib/Alert.dart +++ b/lib/Alert.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; class Alert extends StatelessWidget { - String title; - String body; - Function()? dismissAction; + final String title; + final String body; + final Function()? dismissAction; - Alert( + const Alert( {required this.title, required this.body, super.key, this.dismissAction}); @override diff --git a/lib/Constants.dart b/lib/Constants.dart index 65048c5..4924c1b 100644 --- a/lib/Constants.dart +++ b/lib/Constants.dart @@ -2,5 +2,19 @@ import 'package:flutter/material.dart'; class LibACFlutterConstants { static const Color TITLEBAR_COLOR = Color.fromARGB(255, 99, 0, 0); - static const VERSION = "1.0.031525+0222"; + static const VERSION = "1.0.052525+0051"; +} + +/// A simple helper for obtaining the theme, and allowing toggle of the dark mode state +class LibACFlutterTheme { + /// Default is true + static bool isDarkMode = true; + + static ThemeData GetTheme() { + if (isDarkMode) { + return ThemeData.dark(); + } else { + return ThemeData.light(); + } + } } diff --git a/lib/TextFields.dart b/lib/TextFields.dart index 5e41d84..65dfdec 100644 --- a/lib/TextFields.dart +++ b/lib/TextFields.dart @@ -41,7 +41,8 @@ class HighlightTextfield extends StatelessWidget { Color selected; Color inactive; HighlightTextfield( - {super.key, required this.controller, + {super.key, + required this.controller, required this.inputStyle, required this.selected, required this.inactive}); diff --git a/lib/nbt/nbtHelpers.dart b/lib/nbt/nbtHelpers.dart new file mode 100644 index 0000000..455339a --- /dev/null +++ b/lib/nbt/nbtHelpers.dart @@ -0,0 +1,36 @@ +import 'package:libac_dart/nbt/SnbtIo.dart'; +import 'package:libac_dart/nbt/impl/CompoundTag.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + +class NBTHelper { + /// Commits NBT Data to Shared Preferences, performing all the secret magic that makes it happen + /// + /// [data] - The data to be encoded and saved + /// [name] - The name to give the entry. + static Future CommitNBT( + {required CompoundTag data, required String name}) async { + String encoded = SnbtIo.writeToString(data); + + SharedPreferences prefs = await SharedPreferences.getInstance(); + await prefs.setString(name, encoded); + } + + /// This function retrieves the NBT Data and turns it back into a CompoundTag + /// + /// [name] - The name of the entry to retrieve + static Future GetNBT({required String name}) async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + String data = prefs.getString(name) ?? ""; + if (data.isEmpty) { + return CompoundTag(); + } else { + return await SnbtIo.readFromString(data) as CompoundTag; + } + } + + /// Resets and clears the persistent storage. + static Future ResetPersistentNBTStore() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + await prefs.clear(); + } +} diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index cccf817..724bb2a 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,6 +5,8 @@ import FlutterMacOS import Foundation +import shared_preferences_foundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) } diff --git a/pubspec.yaml b/pubspec.yaml index 0498ae6..e600748 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: libacflutter -description: "A new Flutter package project." -version: 1.0.031525+0222 +description: "LibAC flutter helper utilities." +version: 1.0.052525+0051 homepage: https://zontreck.com publish_to: https://git.zontreck.com/api/packages/Packages/pub @@ -13,7 +13,8 @@ dependencies: sdk: flutter libac_dart: hosted: https://git.zontreck.com/api/packages/Packages/pub/ - version: 1.4.020325+1215 + version: 1.4.052525+0002 + shared_preferences: ^2.5.3 dev_dependencies: flutter_test: