mirror of
https://github.com/zontreck/NBTEditor
synced 2024-11-21 13:48:56 -07:00
Apply dart autofixes
This commit is contained in:
parent
6fdcbb05c4
commit
c15f0e7986
16 changed files with 92 additions and 89 deletions
|
@ -7,7 +7,7 @@ import 'package:nbteditor/tags/NbtIo.dart';
|
|||
import 'package:nbteditor/tags/Tag.dart';
|
||||
|
||||
class Editor extends StatefulWidget {
|
||||
Editor({super.key});
|
||||
const Editor({super.key});
|
||||
|
||||
@override
|
||||
EditorState createState() => EditorState();
|
||||
|
@ -22,8 +22,9 @@ class EditorState extends State<Editor> {
|
|||
String appendCompressed() {
|
||||
if (compressed) {
|
||||
return " - Compressed";
|
||||
} else
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -38,7 +39,7 @@ class EditorState extends State<Editor> {
|
|||
drawer: Drawer(
|
||||
backgroundColor: Constants.DRAWER_COLOR,
|
||||
child: Column(children: [
|
||||
DrawerHeader(
|
||||
const DrawerHeader(
|
||||
child: Column(
|
||||
children: [
|
||||
Text("Named Binary Tag Editor"),
|
||||
|
@ -46,9 +47,9 @@ class EditorState extends State<Editor> {
|
|||
],
|
||||
)),
|
||||
ListTile(
|
||||
title: Text("N E W"),
|
||||
subtitle: Text("Create a new NBT Document"),
|
||||
leading: Icon(Icons.add),
|
||||
title: const Text("N E W"),
|
||||
subtitle: const Text("Create a new NBT Document"),
|
||||
leading: const Icon(Icons.add),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
nodes.clear();
|
||||
|
@ -60,9 +61,9 @@ class EditorState extends State<Editor> {
|
|||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text("O P E N"),
|
||||
leading: Icon(Icons.folder),
|
||||
subtitle: Text("Open an existing NBT Document for editing"),
|
||||
title: const Text("O P E N"),
|
||||
leading: const Icon(Icons.folder),
|
||||
subtitle: const Text("Open an existing NBT Document for editing"),
|
||||
onTap: () async {
|
||||
FilePickerResult? result = await FilePicker.platform.pickFiles();
|
||||
String? filePath;
|
||||
|
@ -103,6 +104,8 @@ class EditorState extends State<Editor> {
|
|||
}
|
||||
|
||||
class FileSelectionScreen extends StatelessWidget {
|
||||
const FileSelectionScreen({super.key});
|
||||
|
||||
Future<void> openFilePicker(BuildContext context) async {
|
||||
try {} catch (e) {
|
||||
// Handle errors
|
||||
|
@ -116,12 +119,12 @@ class FileSelectionScreen extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('File Selection'),
|
||||
title: const Text('File Selection'),
|
||||
),
|
||||
body: Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: () => openFilePicker(context),
|
||||
child: Text('Select File'),
|
||||
child: const Text('Select File'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -13,8 +13,8 @@ class MainApp extends StatelessWidget {
|
|||
return MaterialApp(
|
||||
theme: ThemeData.dark(),
|
||||
routes: {
|
||||
"/": (context) => Editor(),
|
||||
"/select_file": (context) => FileSelectionScreen()
|
||||
"/": (context) => const Editor(),
|
||||
"/select_file": (context) => const FileSelectionScreen()
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:flutter_treeview/src/models/node.dart';
|
||||
import 'package:nbteditor/tags/NbtIo.dart';
|
||||
import 'package:nbteditor/tags/Tag.dart';
|
||||
import 'package:nbteditor/tags/TagType.dart';
|
||||
|
||||
class ByteArrayTag extends Tag {
|
||||
List<int> _value = [];
|
||||
final List<int> _value = [];
|
||||
|
||||
@override
|
||||
Node getNode(String path) {
|
||||
List<Node> entries = [];
|
||||
int count = 0;
|
||||
for (var element in _value) {
|
||||
entries.add(Node(key: "$path/${count}", label: "${element}"));
|
||||
entries.add(Node(key: "$path/$count", label: "$element"));
|
||||
count++;
|
||||
}
|
||||
|
||||
|
@ -36,7 +35,7 @@ class ByteArrayTag extends Tag {
|
|||
@override
|
||||
Widget render() {
|
||||
return ListTile(
|
||||
title: Text("TAG_ByteArray (${Name})"),
|
||||
title: Text("TAG_ByteArray ($Name)"),
|
||||
subtitle: Text("${_value.length} entries"),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:flutter_treeview/src/models/node.dart';
|
||||
import 'package:nbteditor/tags/NbtIo.dart';
|
||||
import 'package:nbteditor/tags/Tag.dart';
|
||||
|
@ -10,7 +9,7 @@ class ByteTag extends Tag {
|
|||
|
||||
@override
|
||||
Node getNode(String path) {
|
||||
return Node(key: path, label: "TAG_Byte ${Name}", data: this);
|
||||
return Node(key: path, label: "TAG_Byte $Name", data: this);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -20,14 +19,14 @@ class ByteTag extends Tag {
|
|||
|
||||
@override
|
||||
void readValue(ByteLayer layer) {
|
||||
this._value = layer.readByte();
|
||||
_value = layer.readByte();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget render() {
|
||||
return ListTile(
|
||||
title: Text("TAG_Byte (${Name})"),
|
||||
subtitle: Text("${_value}"),
|
||||
title: Text("TAG_Byte ($Name)"),
|
||||
subtitle: Text("$_value"),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -43,7 +42,7 @@ class ByteTag extends Tag {
|
|||
|
||||
@override
|
||||
void writeValue(ByteLayer layer) {
|
||||
layer.writeByte(this._value);
|
||||
layer.writeByte(_value);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -6,8 +6,8 @@ import 'package:nbteditor/tags/TagType.dart';
|
|||
import 'package:uuid/v4.dart';
|
||||
|
||||
class CompoundTag extends Tag {
|
||||
UuidV4 v4 = UuidV4();
|
||||
Map<String, Tag> _children = {};
|
||||
UuidV4 v4 = const UuidV4();
|
||||
final Map<String, Tag> _children = {};
|
||||
|
||||
CompoundTag() {
|
||||
setKey(v4.generate());
|
||||
|
@ -18,7 +18,7 @@ class CompoundTag extends Tag {
|
|||
@override
|
||||
Widget render() {
|
||||
return ListTile(
|
||||
title: Text("TAG_Compound (${Name})"),
|
||||
title: Text("TAG_Compound ($Name)"),
|
||||
subtitle:
|
||||
Text("${_children.length} tag${_children.length > 1 ? "s" : ""}"),
|
||||
);
|
||||
|
@ -29,7 +29,7 @@ class CompoundTag extends Tag {
|
|||
List<Node> childTags = [];
|
||||
|
||||
for (var element in _children.entries) {
|
||||
childTags.add(element.value.getNode(path + "/${element.key}"));
|
||||
childTags.add(element.value.getNode("$path/${element.key}"));
|
||||
}
|
||||
Node me = Node(key: path, label: Name, data: this, children: childTags);
|
||||
return me;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:flutter_treeview/src/models/node.dart';
|
||||
import 'package:nbteditor/tags/NbtIo.dart';
|
||||
import 'package:nbteditor/tags/Tag.dart';
|
||||
|
@ -26,8 +25,8 @@ class DoubleTag extends Tag {
|
|||
@override
|
||||
Widget render() {
|
||||
return ListTile(
|
||||
title: Text("TAG_Double (${Name})"),
|
||||
subtitle: Text("${_value}"),
|
||||
title: Text("TAG_Double ($Name)"),
|
||||
subtitle: Text("$_value"),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:flutter_treeview/src/models/node.dart';
|
||||
import 'package:nbteditor/tags/NbtIo.dart';
|
||||
import 'package:nbteditor/tags/Tag.dart';
|
||||
|
@ -26,8 +25,8 @@ class FloatTag extends Tag {
|
|||
@override
|
||||
Widget render() {
|
||||
return ListTile(
|
||||
title: Text("TAG_Float (${Name})"),
|
||||
subtitle: Text("${_value}"),
|
||||
title: Text("TAG_Float ($Name)"),
|
||||
subtitle: Text("$_value"),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:flutter_treeview/src/models/node.dart';
|
||||
import 'package:nbteditor/tags/NbtIo.dart';
|
||||
import 'package:nbteditor/tags/Tag.dart';
|
||||
import 'package:nbteditor/tags/TagType.dart';
|
||||
|
||||
class IntArrayTag extends Tag {
|
||||
List<int> _value = [];
|
||||
final List<int> _value = [];
|
||||
|
||||
@override
|
||||
Node getNode(String path) {
|
||||
List<Node> entries = [];
|
||||
int count = 0;
|
||||
for (var element in _value) {
|
||||
entries.add(Node(key: "$path/${count}", label: "${element}"));
|
||||
entries.add(Node(key: "$path/$count", label: "$element"));
|
||||
count++;
|
||||
}
|
||||
|
||||
|
@ -36,7 +35,7 @@ class IntArrayTag extends Tag {
|
|||
@override
|
||||
Widget render() {
|
||||
return ListTile(
|
||||
title: Text("TAG_IntArray (${Name})"),
|
||||
title: Text("TAG_IntArray ($Name)"),
|
||||
subtitle: Text("${_value.length} entries"),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:flutter_treeview/src/models/node.dart';
|
||||
import 'package:nbteditor/tags/NbtIo.dart';
|
||||
import 'package:nbteditor/tags/Tag.dart';
|
||||
|
@ -25,8 +24,8 @@ class IntTag extends Tag {
|
|||
@override
|
||||
Widget render() {
|
||||
return ListTile(
|
||||
title: Text("TAG_Int (${Name})"),
|
||||
subtitle: Text("${_value}"),
|
||||
title: Text("TAG_Int ($Name)"),
|
||||
subtitle: Text("$_value"),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:flutter_treeview/src/models/node.dart';
|
||||
import 'package:nbteditor/tags/NbtIo.dart';
|
||||
import 'package:nbteditor/tags/Tag.dart';
|
||||
import 'package:nbteditor/tags/TagType.dart';
|
||||
|
||||
class ListTag extends Tag {
|
||||
List<Tag> _value = [];
|
||||
final List<Tag> _value = [];
|
||||
|
||||
@override
|
||||
Node getNode(String path) {
|
||||
|
@ -27,7 +26,7 @@ class ListTag extends Tag {
|
|||
}
|
||||
|
||||
bool add(Tag tag) {
|
||||
if (_value.length > 0) {
|
||||
if (_value.isNotEmpty) {
|
||||
if (tag.getTagType() == _value[0].getTagType()) {
|
||||
_value.add(tag);
|
||||
|
||||
|
@ -56,7 +55,7 @@ class ListTag extends Tag {
|
|||
@override
|
||||
Widget render() {
|
||||
return ListTile(
|
||||
title: Text("TAG_List (${Name}) (${getListTagType()})"),
|
||||
title: Text("TAG_List ($Name) (${getListTagType()})"),
|
||||
subtitle: Text("${_value.length} entries"),
|
||||
);
|
||||
}
|
||||
|
@ -72,15 +71,16 @@ class ListTag extends Tag {
|
|||
}
|
||||
|
||||
TagType getListTagType() {
|
||||
if (_value.length > 0) {
|
||||
if (_value.isNotEmpty) {
|
||||
return TagType.End;
|
||||
} else
|
||||
} else {
|
||||
return _value[0].getTagType();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void writeValue(ByteLayer layer) {
|
||||
if (_value.length > 0) {
|
||||
if (_value.isNotEmpty) {
|
||||
_value[0].writeTagType(layer);
|
||||
} else {
|
||||
layer.writeByte(TagType.End.toByte());
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:flutter_treeview/src/models/node.dart';
|
||||
import 'package:nbteditor/tags/NbtIo.dart';
|
||||
import 'package:nbteditor/tags/Tag.dart';
|
||||
import 'package:nbteditor/tags/TagType.dart';
|
||||
|
||||
class LongArrayTag extends Tag {
|
||||
List<int> _value = [];
|
||||
final List<int> _value = [];
|
||||
|
||||
@override
|
||||
Node getNode(String path) {
|
||||
List<Node> entries = [];
|
||||
int count = 0;
|
||||
for (var element in _value) {
|
||||
entries.add(Node(key: "$path/${count}", label: "${element}"));
|
||||
entries.add(Node(key: "$path/$count", label: "$element"));
|
||||
count++;
|
||||
}
|
||||
|
||||
|
@ -36,7 +35,7 @@ class LongArrayTag extends Tag {
|
|||
@override
|
||||
Widget render() {
|
||||
return ListTile(
|
||||
title: Text("TAG_LongArray (${Name})"),
|
||||
title: Text("TAG_LongArray ($Name)"),
|
||||
subtitle: Text("${_value.length} entries"),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:flutter_treeview/src/models/node.dart';
|
||||
import 'package:nbteditor/tags/NbtIo.dart';
|
||||
import 'package:nbteditor/tags/Tag.dart';
|
||||
|
@ -26,8 +25,8 @@ class LongTag extends Tag {
|
|||
@override
|
||||
Widget render() {
|
||||
return ListTile(
|
||||
title: Text("TAG_Long (${Name})"),
|
||||
subtitle: Text("${_value}"),
|
||||
title: Text("TAG_Long ($Name)"),
|
||||
subtitle: Text("$_value"),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:flutter_treeview/src/models/node.dart';
|
||||
import 'package:nbteditor/tags/NbtIo.dart';
|
||||
import 'package:nbteditor/tags/Tag.dart';
|
||||
|
@ -26,8 +25,8 @@ class ShortTag extends Tag {
|
|||
@override
|
||||
Widget render() {
|
||||
return ListTile(
|
||||
title: Text("TAG_Short (${Name})"),
|
||||
subtitle: Text("${_value}"),
|
||||
title: Text("TAG_Short ($Name)"),
|
||||
subtitle: Text("$_value"),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:flutter_treeview/src/models/node.dart';
|
||||
import 'package:nbteditor/tags/NbtIo.dart';
|
||||
import 'package:nbteditor/tags/Tag.dart';
|
||||
|
@ -9,7 +8,7 @@ class StringTag extends Tag {
|
|||
String _value = "";
|
||||
@override
|
||||
Node getNode(String path) {
|
||||
return Node(key: path, label: "$_value", data: this);
|
||||
return Node(key: path, label: _value, data: this);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -25,8 +24,8 @@ class StringTag extends Tag {
|
|||
@override
|
||||
Widget render() {
|
||||
return ListTile(
|
||||
title: Text("TAG_String (${Name})"),
|
||||
subtitle: Text("${_value}"),
|
||||
title: Text("TAG_String ($Name)"),
|
||||
subtitle: Text(_value),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import 'dart:ffi';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_treeview/flutter_treeview.dart';
|
||||
|
@ -32,87 +31,99 @@ abstract class Tag {
|
|||
Node getNode(String path);
|
||||
|
||||
ByteTag asByte() {
|
||||
if (this is ByteTag)
|
||||
if (this is ByteTag) {
|
||||
return this as ByteTag;
|
||||
else
|
||||
} else {
|
||||
return ByteTag();
|
||||
}
|
||||
}
|
||||
|
||||
ShortTag asShort() {
|
||||
if (this is ShortTag)
|
||||
if (this is ShortTag) {
|
||||
return this as ShortTag;
|
||||
else
|
||||
} else {
|
||||
return ShortTag();
|
||||
}
|
||||
}
|
||||
|
||||
IntTag asInt() {
|
||||
if (this is IntTag)
|
||||
if (this is IntTag) {
|
||||
return this as IntTag;
|
||||
else
|
||||
} else {
|
||||
return IntTag();
|
||||
}
|
||||
}
|
||||
|
||||
LongTag asLong() {
|
||||
if (this is LongTag)
|
||||
if (this is LongTag) {
|
||||
return this as LongTag;
|
||||
else
|
||||
} else {
|
||||
return LongTag();
|
||||
}
|
||||
}
|
||||
|
||||
FloatTag asFloat() {
|
||||
if (this is FloatTag)
|
||||
if (this is FloatTag) {
|
||||
return this as FloatTag;
|
||||
else
|
||||
} else {
|
||||
return FloatTag();
|
||||
}
|
||||
}
|
||||
|
||||
DoubleTag asDouble() {
|
||||
if (this is DoubleTag)
|
||||
if (this is DoubleTag) {
|
||||
return this as DoubleTag;
|
||||
else
|
||||
} else {
|
||||
return DoubleTag();
|
||||
}
|
||||
}
|
||||
|
||||
ByteArrayTag asByteArray() {
|
||||
if (this is ByteArrayTag)
|
||||
if (this is ByteArrayTag) {
|
||||
return this as ByteArrayTag;
|
||||
else
|
||||
} else {
|
||||
return ByteArrayTag();
|
||||
}
|
||||
}
|
||||
|
||||
StringTag asString() {
|
||||
if (this is StringTag)
|
||||
if (this is StringTag) {
|
||||
return this as StringTag;
|
||||
else
|
||||
} else {
|
||||
return StringTag();
|
||||
}
|
||||
}
|
||||
|
||||
ListTag asListTag() {
|
||||
if (this is ListTag)
|
||||
if (this is ListTag) {
|
||||
return this as ListTag;
|
||||
else
|
||||
} else {
|
||||
return ListTag();
|
||||
}
|
||||
}
|
||||
|
||||
CompoundTag asCompoundTag() {
|
||||
if (this is CompoundTag)
|
||||
if (this is CompoundTag) {
|
||||
return this as CompoundTag;
|
||||
else
|
||||
} else {
|
||||
return CompoundTag();
|
||||
}
|
||||
}
|
||||
|
||||
IntArrayTag asIntArrayTag() {
|
||||
if (this is IntArrayTag)
|
||||
if (this is IntArrayTag) {
|
||||
return this as IntArrayTag;
|
||||
else
|
||||
} else {
|
||||
return IntArrayTag();
|
||||
}
|
||||
}
|
||||
|
||||
LongArrayTag asLongArrayTag() {
|
||||
if (this is LongArrayTag)
|
||||
if (this is LongArrayTag) {
|
||||
return this as LongArrayTag;
|
||||
else
|
||||
} else {
|
||||
return LongArrayTag();
|
||||
}
|
||||
}
|
||||
|
||||
Tag withNick(String name) {
|
||||
|
@ -195,13 +206,13 @@ abstract class Tag {
|
|||
default:
|
||||
{
|
||||
print(
|
||||
"Unknown tag: ${tagType}, aborting read at ${layer.currentPosition - 1} bytes");
|
||||
"Unknown tag: $tagType, aborting read at ${layer.currentPosition - 1} bytes");
|
||||
|
||||
throw Exception("Unknown tag, could not deserialize");
|
||||
}
|
||||
}
|
||||
|
||||
print("Read ${tagType}");
|
||||
print("Read $tagType");
|
||||
|
||||
if (!isList) tag.readHeader(layer);
|
||||
|
||||
|
|
Loading…
Reference in a new issue