From 7214524543d6ae3e48d3548e3da2b2865e318e40 Mon Sep 17 00:00:00 2001 From: zoe Date: Mon, 1 Aug 2022 15:29:45 +0200 Subject: [PATCH] read the things --- lib/main.dart | 14 +++++++++----- lib/person.dart | 33 +++++++++++++++++++++++++++++++++ lib/quiz.dart | 31 +++++++++++++++++++++++-------- 3 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 lib/person.dart diff --git a/lib/main.dart b/lib/main.dart index e139d1e..103b171 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 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 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)], ), ), ), diff --git a/lib/person.dart b/lib/person.dart new file mode 100644 index 0000000..c8ad151 --- /dev/null +++ b/lib/person.dart @@ -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 json) { + img = json['img']; + name = json['name']; + senator = json['senator']; + description = json['description']; + } +} + +Future> getPeopleList() async { + String data = await File("assets/data.json").readAsString(); + Map map = jsonDecode(data); + List people = []; + for (int i = 0; i < map.length - 1; i++) { + people.add(Person.fromJson(map[i])); + } + return people; +} diff --git a/lib/quiz.dart b/lib/quiz.dart index d6791bd..625e3a2 100644 --- a/lib/quiz.dart +++ b/lib/quiz.dart @@ -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 fullPeopleList; @override State createState() => _QuizState(); } class _QuizState extends State { + late List 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, + ), ) ], );