36 lines
791 B
Dart
36 lines
791 B
Dart
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
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) {
|
|
img = json['image'];
|
|
name = json['name'];
|
|
senator = json['senator'] == true.toString();
|
|
description = json['description'];
|
|
}
|
|
}
|
|
|
|
Future<List<Person>> getPeopleList() async {
|
|
String data = await rootBundle.loadString('assets/data.json');
|
|
List<dynamic> map = jsonDecode(data)["people"];
|
|
List<Person> people = [];
|
|
for (int i = 0; i < map.length - 1; i++) {
|
|
people.add(Person.fromJson(map[i]));
|
|
}
|
|
return people;
|
|
}
|