Closed KaanBN closed 1 year ago
if anyone have the same problem as me this was my solution:
void _readFile() async
//I was able to extract Uint8List by doing like this.
final ByteData data = await rootBundle.load('assets/files/dd.schem');
//normally NbtReader.fromfile() already implemented but in my case reading bytes was not an option
final nbtReader = NbtReader(data.buffer.asUint8List());
// after that I was able to read file
await nbtReader.read();
NbtCompound<NbtTag>? rootNode = nbtReader.root;
List<NbtTag>? block_types = rootNode?.getChildrenByName("Palette");
print(block_types);
}
Flutter does files a bit different depending on the platform, which is why packages like path_provider
exist. NbtReader.fromFile
internally just does File(path).readAsBytesSync()
, which is relative to the app's working directory, which is not where the assets
are stored by default afaik, though I haven't used Flutter with assets for a while. Though glad you fixed it using a different solution.
I have the file in my folders but every time I try to read the nbt file I get error (E/flutter ( 5298): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PathNotFoundException: Cannot open file, path = 'assets/gifs/deneme1.nbt' (OS Error: No such file or directory, errno = 2))