Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2d6bf23

Browse files
Added function getJsonAsMap
1 parent ea161bb commit 2d6bf23

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

‎lib/jsonloader.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
library jsonloader;
22

3+
import 'dart:convert';
4+
35
import 'package:flutter/services.dart';
46

57
class JSONLoader {
@@ -10,4 +12,13 @@ class JSONLoader {
1012
var jsonString = rootBundle.loadString(filename);
1113
return jsonString;
1214
}
15+
16+
/// Retrieve a map from the JSON file.
17+
///
18+
/// Throws an exception if the file is not found.
19+
Future<Map<String, dynamic>> getJsonAsMap(String filename) async {
20+
var jsonString = await rootBundle.loadString(filename);
21+
Map<String, dynamic> jsonMap = json.decode(jsonString);
22+
return jsonMap;
23+
}
1324
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /