senatorialkillers/lib/person.dart

36 lines
791 B
Dart
Raw Permalink Normal View History

2022-08-01 13:29:45 +00:00
import 'dart:convert';
import 'dart:io';
2022-08-01 15:24:29 +00:00
import 'package:flutter/services.dart';
2022-08-01 13:29:45 +00:00
class Person {
late String img;
late String name;
late bool senator;
late String? description;
Person({
required this.img,
required this.name,
required this.senator,
this.description,
});
Person.fromJson(Map<String, dynamic> json) {
2022-08-01 14:59:57 +00:00
img = json['image'];
2022-08-01 13:29:45 +00:00
name = json['name'];
2022-08-01 14:59:57 +00:00
senator = json['senator'] == true.toString();
2022-08-01 13:29:45 +00:00
description = json['description'];
}
}
Future<List<Person>> getPeopleList() async {
2022-08-01 15:24:29 +00:00
String data = await rootBundle.loadString('assets/data.json');
2022-08-01 14:59:57 +00:00
List<dynamic> map = jsonDecode(data)["people"];
2022-08-01 13:29:45 +00:00
List<Person> people = [];
for (int i = 0; i < map.length - 1; i++) {
people.add(Person.fromJson(map[i]));
}
return people;
}