-
-
Notifications
You must be signed in to change notification settings - Fork 984
Closed
Labels
Description
Current bug behavior
Reading a JSON file using AssetCache.readJson
results in an error if the JSON file root element is an array.
An example JSON file that meets this criteria is
[
"The root of this JSON file is an array",
"Which is perfectly legal JSON"
]
The error is
_TypeError (type 'List<dynamic>' is not a subtype of type 'Map<String, dynamic>' in type cast)
This is because it attempts to cast the result to a Map<String, dynamic>
, however, a JSON file can also be a List<dynamic>
.
Expected behavior
AssetCache.readJson
should return a Future<dynamic>
(It uses jsonDecode
under the hood, which returns dynamic
).
Steps to reproduce
- Include the JSON file above in the assets (and your pubspec)
- ensure you
import 'package:flame/cache.dart';
- call
AssetsCache().readJson('test.json')
More environment information
- Flame version latest
- Affects all platforms
More information
I can provide the fix. It's very simple and I think it will be backwards compatible in most cases?