-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotter_reader.dart
31 lines (26 loc) · 898 Bytes
/
otter_reader.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
import 'otter.dart';
import 'package:http/http.dart' as http;
class OtterReader {
Future<List<Otter>> read(String fileName) async {
final String content = await rootBundle.loadString(fileName);
return parse(content);
}
// json array to list
List<Otter> parse(String s) {
List res = json.decode(s);
return res.map(parseOtter).toList();
}
// take some json properties and return an otter object from it
Otter parseOtter(properties) {
String name = properties["name"];
String common = properties["common"];
String desc = properties["desc"];
String link = properties["link"];
String detail = properties["detail"];
String imageUrl = properties["imgs"][0];
return Otter(name, common, desc, link, imageUrl, detail);
}
}