Add some helpers and wrappers, bump libac-dart dep
This commit is contained in:
parent
edca96f33f
commit
61a9ecd382
6 changed files with 63 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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});
|
||||
|
|
36
lib/nbt/nbtHelpers.dart
Normal file
36
lib/nbt/nbtHelpers.dart
Normal file
|
@ -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<void> 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<CompoundTag> 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<void> ResetPersistentNBTStore() async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
await prefs.clear();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue