read the things

This commit is contained in:
zoe 2022-08-01 15:29:45 +02:00
parent 39786e9272
commit 7214524543
3 changed files with 65 additions and 13 deletions

View File

@ -1,14 +1,18 @@
import 'package:flutter/material.dart';
import './quiz.dart';
import './heading.dart';
import './person.dart';
void main() {
runApp(const Senatorialkillers());
void main() async {
List<Person> people = await getPeopleList();
runApp(Senatorialkillers(
people: people,
));
}
class Senatorialkillers extends StatelessWidget {
const Senatorialkillers({Key? key}) : super(key: key);
const Senatorialkillers({required this.people, Key? key}) : super(key: key);
final List<Person> people;
@override
Widget build(BuildContext context) {
return MaterialApp(
@ -18,7 +22,7 @@ class Senatorialkillers extends StatelessWidget {
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: const [Heading(), Quiz()],
children: [const Heading(), Quiz(fullPeopleList: people)],
),
),
),

33
lib/person.dart Normal file
View File

@ -0,0 +1,33 @@
import 'dart:convert';
import 'dart:io';
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['img'];
name = json['name'];
senator = json['senator'];
description = json['description'];
}
}
Future<List<Person>> getPeopleList() async {
String data = await File("assets/data.json").readAsString();
Map<String, dynamic> map = jsonDecode(data);
List<Person> people = [];
for (int i = 0; i < map.length - 1; i++) {
people.add(Person.fromJson(map[i]));
}
return people;
}

View File

@ -1,21 +1,23 @@
import 'package:flutter/material.dart';
import 'package:flutter/src/foundation/key.dart';
import 'package:flutter/src/widgets/framework.dart';
import './person.dart';
class Quiz extends StatefulWidget {
const Quiz({Key? key}) : super(key: key);
const Quiz({required this.fullPeopleList, Key? key}) : super(key: key);
final List<Person> fullPeopleList;
@override
State<Quiz> createState() => _QuizState();
}
class _QuizState extends State<Quiz> {
late List<Person> people;
@override
Widget build(BuildContext context) {
people = widget.fullPeopleList;
return Column(
children: [
Image.network(
"https://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Variegated_golden_frog_%28Mantella_baroni%29_Ranomafana.jpg/640px-Variegated_golden_frog_%28Mantella_baroni%29_Ranomafana.jpg?download"),
"https://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Variegated_golden_frog_%28Mantella_baroni%29_Ranomafana.jpg/800px-Variegated_golden_frog_%28Mantella_baroni%29_Ranomafana.jpg"),
const AnswerButtons(),
],
);
@ -28,16 +30,29 @@ class AnswerButtons extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton.icon(
onPressed: null,
icon: const Icon(Icons.how_to_vote),
label: const Text("Senator"),
icon: const Icon(
Icons.how_to_vote,
size: 64,
),
label: Text(
"US Senator",
style: Theme.of(context).textTheme.displaySmall,
),
),
TextButton.icon(
onPressed: null,
icon: const Icon(Icons.gavel),
label: const Text("Serial Killer"),
icon: const Icon(
Icons.gavel,
size: 64,
),
label: Text(
"Serial Killer",
style: Theme.of(context).textTheme.displaySmall,
),
)
],
);