read the things
This commit is contained in:
parent
39786e9272
commit
7214524543
|
@ -1,14 +1,18 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import './quiz.dart';
|
import './quiz.dart';
|
||||||
import './heading.dart';
|
import './heading.dart';
|
||||||
|
import './person.dart';
|
||||||
|
|
||||||
void main() {
|
void main() async {
|
||||||
runApp(const Senatorialkillers());
|
List<Person> people = await getPeopleList();
|
||||||
|
runApp(Senatorialkillers(
|
||||||
|
people: people,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
class Senatorialkillers extends StatelessWidget {
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
|
@ -18,7 +22,7 @@ class Senatorialkillers extends StatelessWidget {
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: const [Heading(), Quiz()],
|
children: [const Heading(), Quiz(fullPeopleList: people)],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -1,21 +1,23 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/src/foundation/key.dart';
|
import './person.dart';
|
||||||
import 'package:flutter/src/widgets/framework.dart';
|
|
||||||
|
|
||||||
class Quiz extends StatefulWidget {
|
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
|
@override
|
||||||
State<Quiz> createState() => _QuizState();
|
State<Quiz> createState() => _QuizState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _QuizState extends State<Quiz> {
|
class _QuizState extends State<Quiz> {
|
||||||
|
late List<Person> people;
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
people = widget.fullPeopleList;
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Image.network(
|
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(),
|
const AnswerButtons(),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
@ -28,16 +30,29 @@ class AnswerButtons extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Row(
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: [
|
children: [
|
||||||
TextButton.icon(
|
TextButton.icon(
|
||||||
onPressed: null,
|
onPressed: null,
|
||||||
icon: const Icon(Icons.how_to_vote),
|
icon: const Icon(
|
||||||
label: const Text("Senator"),
|
Icons.how_to_vote,
|
||||||
|
size: 64,
|
||||||
|
),
|
||||||
|
label: Text(
|
||||||
|
"US Senator",
|
||||||
|
style: Theme.of(context).textTheme.displaySmall,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
TextButton.icon(
|
TextButton.icon(
|
||||||
onPressed: null,
|
onPressed: null,
|
||||||
icon: const Icon(Icons.gavel),
|
icon: const Icon(
|
||||||
label: const Text("Serial Killer"),
|
Icons.gavel,
|
||||||
|
size: 64,
|
||||||
|
),
|
||||||
|
label: Text(
|
||||||
|
"Serial Killer",
|
||||||
|
style: Theme.of(context).textTheme.displaySmall,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue