From f9d51367f688d653e5cb461f97ff3ea966419935 Mon Sep 17 00:00:00 2001 From: Tim Honisett <40595819@live.napier.ac.uk> Date: Sun, 14 Apr 2024 01:44:44 +0100 Subject: [PATCH 1/8] Fixed merged issues with remote dev branch --- lib/question_screens/question10.dart | 119 +++------------------- lib/question_screens/question15.dart | 6 +- lib/question_screens/questions_utils.dart | 23 ++--- pubspec.lock | 24 ++--- 4 files changed, 38 insertions(+), 134 deletions(-) diff --git a/lib/question_screens/question10.dart b/lib/question_screens/question10.dart index 38c0270..3ae01c7 100644 --- a/lib/question_screens/question10.dart +++ b/lib/question_screens/question10.dart @@ -12,9 +12,7 @@ class QuestionAnswer10Page extends StatefulWidget { const QuestionAnswer10Page({ Key? key, required this.name, - required this.image, - required this.habitat, - required this.onHabitatSelected, + required this.image, required this.habitat, required this.onHabitatSelected, }) : super(key: key); @@ -27,20 +25,9 @@ class _QuestionAnswerPage10State extends State { List answers = []; String questionText = ''; String habitat=''; + String answer=''; final ScrollController _controller = ScrollController(); -class QuestionAnswerPage extends StatefulWidget { - const QuestionAnswerPage({super.key}); - - @override - _QuestionAnswerPageState createState() => _QuestionAnswerPageState(); -} - -class _QuestionAnswerPageState extends State { - List selectedAnswer = []; - List answers = []; - String questionText = ''; - @override void initState() { @@ -53,20 +40,26 @@ class _QuestionAnswerPageState extends State { String jsonString = await DefaultAssetBundle.of(context) .loadString('assets/raw_eng/questions2Modified.json'); - // Parse the JSON string into a list of objects List jsonData = jsonDecode(jsonString); // Extract data from the first question (question number 9) Map firstQuestionData = jsonData[9]; + if(widget.name=="Ucides cordatus") { + answer='answers_0'; + } + else { + answer='answers_1'; + } + // Set question text and answers list setState(() { questionText = firstQuestionData['description']; // Extract answers from the answers map - List answerList = firstQuestionData['answers_0']; + List answerList = firstQuestionData[answer]; // Cast answers to List answers = answerList.map((answer) => answer.toString()).toList(); @@ -126,108 +119,19 @@ class _QuestionAnswerPageState extends State { Widget buildAnswerButton(String answer) { bool isSelected = answer == selectedArea; -======= - // Parse the JSON string into a list of objects - List jsonData = jsonDecode(jsonString); - // Extract data from the question with questionNumber 10 - Map? question10Data = jsonData.firstWhere( - (question) => question['questionNumber'] == 10, - orElse: () => null); - - if (question10Data != null) { - // Extract question and answers - String? question = question10Data['question_10']; - List? answersList = question10Data['answers_10']; - - if (question != null && answersList != null) { - setState(() { - questionText = question; - answers = answersList.cast(); // Cast answers to String list - }); - } - } - } - - @override - Widget build(BuildContext context) { - return Scaffold( - body: ListView( - padding: const EdgeInsets.all(16.0), - children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - flex: 1, - child: Image.asset( - 'assets/images/raster_q0_0.png', - height: 200, - width: 200, - ), - ), - const SizedBox(width: 20.0), - const Expanded( - flex: 2, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "Monitoring Ucides cordatus", - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 20.0, - ), - ), - SizedBox(height: 10.0), - ], - ), - ), - ], - ), - const SizedBox(height: 20.0), - Text( - questionText, - style: const TextStyle( - fontSize: 16.0, - ), - ), - const SizedBox(height: 20.0), - for (var answer in answers) buildAnswerButton(answer), - ], - ), - ); - } - - Widget buildAnswerButton(String answer) { - bool isSelected = selectedAnswer.contains(answer); - return GestureDetector( onTap: () { setState(() { - selectedArea = answer; - habitat = answer; + habitat = answer; widget.onHabitatSelected(habitat); - - if (isSelected) { - selectedAnswer.remove(answer); - } else { - selectedAnswer.clear(); - selectedAnswer.add(answer); - } - }); }, child: Container( color: isSelected ? Colors.green : null, - padding: const EdgeInsets.all(1.0), margin: const EdgeInsets.symmetric(vertical: 1.0), - - padding: const EdgeInsets.all(12.0), - margin: const EdgeInsets.symmetric(vertical: 8.0), - child: Text( answer, style: TextStyle( @@ -238,4 +142,5 @@ class _QuestionAnswerPageState extends State { ), ); } +} diff --git a/lib/question_screens/question15.dart b/lib/question_screens/question15.dart index 88b0529..8ed6359 100644 --- a/lib/question_screens/question15.dart +++ b/lib/question_screens/question15.dart @@ -6,13 +6,13 @@ class QuestionAnswer15Page extends StatefulWidget { final String name; final String image; final String additionalInfo; - final Function(String) onAdditionalInfo; + final Function(String) onAdditionalInfoSelected; const QuestionAnswer15Page({ Key? key, required this.name, required this.image, - required this.onAdditionalInfo, required this.additionalInfo + required this.onAdditionalInfoSelected, required this.additionalInfo, }) : super(key: key); @override @@ -123,7 +123,7 @@ class _QuestionAnswerPage15State extends State { setState(() { selectedAnswer = answer; additionalInfo = answer; - widget.onAdditionalInfo(additionalInfo); + widget.onAdditionalInfoSelected(additionalInfo); }); }, child: Container( diff --git a/lib/question_screens/questions_utils.dart b/lib/question_screens/questions_utils.dart index 92e1cf8..6609b9c 100644 --- a/lib/question_screens/questions_utils.dart +++ b/lib/question_screens/questions_utils.dart @@ -1,4 +1,5 @@ import 'package:flutter/cupertino.dart'; +import 'package:flutter/cupertino.dart'; import 'package:remar_flutter_app/question_screens/question3.dart'; import 'package:remar_flutter_app/question_screens/question4.dart'; @@ -19,8 +20,8 @@ import 'package:remar_flutter_app/question_screens/question16.dart'; // list of answers -const String crabSpecies = 'Ucides cordatus'; -const String crabImage = 'assets/images/raster_q0_0.png'; +const String crabSpecies = 'Cardisoma guanhumi'; +const String crabImage = 'assets/images/raster_q1_0.png'; // Define initial values for various properties String year = ''; @@ -30,7 +31,6 @@ String county = ''; String intensity =''; String berried=''; String whenObserved=''; - String habitat = ''; String additionalInfo=''; @@ -57,13 +57,6 @@ void onWhenObserved(String selectedWhenObserved) { -void onWhenObserved(String selectedWhenObserved) { - whenObserved = selectedWhenObserved; - print(whenObserved); -} - - - void onStateSelected(String selectedState) { state = selectedState; } @@ -79,7 +72,6 @@ void onBerriedSelected(String selectedBerried) { void onHabitatSelected(String selectedHabit) { habitat = selectedHabit; - print(habitat); } @@ -149,7 +141,14 @@ Widget question12 = QuestionAnswer12Page( onCountySelected: onCountySelected, county: county, ); -v + +Widget question15 = QuestionAnswer15Page( + image: crabImage, + name: crabSpecies, + onAdditionalInfoSelected: onAdditionalInfoSelected, + additionalInfo: additionalInfo, +); + Widget question16 = const QuestionAnswer16Page( ); diff --git a/pubspec.lock b/pubspec.lock index 357eaf4..d8585a2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -228,18 +228,18 @@ packages: dependency: transitive description: name: path_provider - sha256: b27217933eeeba8ff24845c34003b003b2b22151de3c908d0e679e8fe1aa078b + sha256: c9e7d3a4cd1410877472158bee69963a4579f78b68c65a2b7d40d1a7a88bb161 url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.3" path_provider_android: dependency: transitive description: name: path_provider_android - sha256: "477184d672607c0a3bf68fbbf601805f92ef79c82b64b4d6eb318cbca4c48668" + sha256: a248d8146ee5983446bf03ed5ea8f6533129a12b11f12057ad1b4a67a2b3b41d url: "https://pub.dev" source: hosted - version: "2.2.2" + version: "2.2.4" path_provider_foundation: dependency: transitive description: @@ -300,18 +300,18 @@ packages: dependency: "direct main" description: name: shared_preferences - sha256: "81429e4481e1ccfb51ede496e916348668fd0921627779233bd24cc3ff6abd02" + sha256: d3bbe5553a986e83980916ded2f0b435ef2e1893dfaa29d5a7a790d0eca12180 url: "https://pub.dev" source: hosted - version: "2.2.2" + version: "2.2.3" shared_preferences_android: dependency: transitive description: name: shared_preferences_android - sha256: "8568a389334b6e83415b6aae55378e158fbc2314e074983362d20c562780fb06" + sha256: "1ee8bf911094a1b592de7ab29add6f826a7331fb854273d55918693d5364a1f2" url: "https://pub.dev" source: hosted - version: "2.2.1" + version: "2.2.2" shared_preferences_foundation: dependency: transitive description: @@ -417,18 +417,18 @@ packages: dependency: "direct main" description: name: url_launcher - sha256: "0ecc004c62fd3ed36a2ffcbe0dd9700aee63bd7532d0b642a488b1ec310f492e" + sha256: "6ce1e04375be4eed30548f10a315826fd933c1e493206eab82eed01f438c8d2e" url: "https://pub.dev" source: hosted - version: "6.2.5" + version: "6.2.6" url_launcher_android: dependency: transitive description: name: url_launcher_android - sha256: d4ed0711849dd8e33eb2dd69c25db0d0d3fdc37e0a62e629fe32f57a22db2745 + sha256: "360a6ed2027f18b73c8d98e159dda67a61b7f2e0f6ec26e86c3ada33b0621775" url: "https://pub.dev" source: hosted - version: "6.3.0" + version: "6.3.1" url_launcher_ios: dependency: transitive description: From c75edc7e8e20c76770fc7e1d5ce8c1026f056b87 Mon Sep 17 00:00:00 2001 From: Tim Honisett <40595819@live.napier.ac.uk> Date: Sun, 14 Apr 2024 19:44:38 +0100 Subject: [PATCH 2/8] Global variable added and added to question3.dart --- lib/question_screens/global.dart | 2 ++ lib/question_screens/question3.dart | 7 ++++++- lib/question_screens/questions_utils.dart | 1 + lib/widgets/bottom_navigation_bar.dart | 3 +++ 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 lib/question_screens/global.dart diff --git a/lib/question_screens/global.dart b/lib/question_screens/global.dart new file mode 100644 index 0000000..7becdad --- /dev/null +++ b/lib/question_screens/global.dart @@ -0,0 +1,2 @@ + +bool enableForwardNavigation = false; diff --git a/lib/question_screens/question3.dart b/lib/question_screens/question3.dart index 88f5950..9f76cce 100644 --- a/lib/question_screens/question3.dart +++ b/lib/question_screens/question3.dart @@ -1,9 +1,10 @@ import 'dart:convert'; +import 'dart:core'; import 'package:flutter/material.dart'; +import 'global.dart'; List yearList = []; // Declaration of yearList - class QuestionAnswer3Page extends StatefulWidget { final String name; @@ -37,6 +38,9 @@ class _QuestionAnswerPage3State extends State { } void loadQuestions() async { + + enableForwardNavigation = false; + // Load the JSON data from the file String jsonString = await DefaultAssetBundle.of(context) .loadString('assets/raw_eng/questions2Modified.json'); @@ -113,6 +117,7 @@ class _QuestionAnswerPage3State extends State { selectedArea = answer; year = answer; widget.onYearSelected(year); + enableForwardNavigation = true; }); }, child: Container( diff --git a/lib/question_screens/questions_utils.dart b/lib/question_screens/questions_utils.dart index 1061c04..6831e7a 100644 --- a/lib/question_screens/questions_utils.dart +++ b/lib/question_screens/questions_utils.dart @@ -16,6 +16,7 @@ import 'package:remar_flutter_app/question_screens/question13.dart'; // import 'package:remar_flutter_app/question_screens/question14.dart'; import 'package:remar_flutter_app/question_screens/question15.dart'; import 'package:remar_flutter_app/question_screens/question16.dart'; +import 'global.dart'; // list of answers diff --git a/lib/widgets/bottom_navigation_bar.dart b/lib/widgets/bottom_navigation_bar.dart index 633b9ca..9040dcc 100644 --- a/lib/widgets/bottom_navigation_bar.dart +++ b/lib/widgets/bottom_navigation_bar.dart @@ -4,6 +4,7 @@ import 'package:remar_flutter_app/utils/color_res.dart'; import 'package:provider/provider.dart'; import '../Screens/providers/bottom_state_provider.dart'; +import '../question_screens/global.dart'; class CustomBottomNavigationBar extends StatelessWidget { final int currentPageIndex; @@ -86,8 +87,10 @@ class CustomBottomNavigationBar extends StatelessWidget { ), ), ), + GestureDetector( onTap: () { + print(enableForwardNavigation); pageController.nextPage( duration: const Duration(milliseconds: 200), curve: Curves.easeInOutCubic); From 047b48b2bd7e7d9add366f03b99d2e41048f70ad Mon Sep 17 00:00:00 2001 From: Tim Honisett <40595819@live.napier.ac.uk> Date: Sun, 14 Apr 2024 19:49:03 +0100 Subject: [PATCH 3/8] Press on proceed does not work if a year is not selected on questionpage3 --- lib/widgets/bottom_navigation_bar.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/widgets/bottom_navigation_bar.dart b/lib/widgets/bottom_navigation_bar.dart index 9040dcc..5e1be68 100644 --- a/lib/widgets/bottom_navigation_bar.dart +++ b/lib/widgets/bottom_navigation_bar.dart @@ -60,6 +60,7 @@ class CustomBottomNavigationBar extends StatelessWidget { size: 30, ), ), + const SizedBox( width: 10, ), @@ -90,10 +91,11 @@ class CustomBottomNavigationBar extends StatelessWidget { GestureDetector( onTap: () { - print(enableForwardNavigation); - pageController.nextPage( + if(enableForwardNavigation == true) { + pageController.nextPage( duration: const Duration(milliseconds: 200), curve: Curves.easeInOutCubic); + } }, child: MouseRegion( cursor: SystemMouseCursors.click, From ca95cc902fa6c7450f0ef8653767cb90093b7537 Mon Sep 17 00:00:00 2001 From: Tim Honisett <40595819@live.napier.ac.uk> Date: Sun, 14 Apr 2024 22:09:57 +0100 Subject: [PATCH 4/8] Reverted back to preventing press to proceed if year not selected in question3 --- lib/widgets/bottom_navigation_bar.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/widgets/bottom_navigation_bar.dart b/lib/widgets/bottom_navigation_bar.dart index 5e1be68..f13e00b 100644 --- a/lib/widgets/bottom_navigation_bar.dart +++ b/lib/widgets/bottom_navigation_bar.dart @@ -89,6 +89,7 @@ class CustomBottomNavigationBar extends StatelessWidget { ), ), + GestureDetector( onTap: () { if(enableForwardNavigation == true) { From 9b2957310e99a869db0eacb70fc7e4c76d2d75db Mon Sep 17 00:00:00 2001 From: Tim Honisett <40595819@live.napier.ac.uk> Date: Sun, 14 Apr 2024 23:23:55 +0100 Subject: [PATCH 5/8] Now cannot select future month. However, is still selected as green --- lib/question_screens/question4.dart | 89 ++++++++++++++++++++++++++--- 1 file changed, 80 insertions(+), 9 deletions(-) diff --git a/lib/question_screens/question4.dart b/lib/question_screens/question4.dart index 5186873..484c3f5 100644 --- a/lib/question_screens/question4.dart +++ b/lib/question_screens/question4.dart @@ -1,6 +1,9 @@ import 'dart:convert'; +import 'dart:core'; import 'package:flutter/material.dart'; +import 'package:remar_flutter_app/question_screens/global.dart'; +bool isMonthValid = false; class QuestionAnswer4Page extends StatefulWidget { @@ -9,6 +12,7 @@ class QuestionAnswer4Page extends StatefulWidget { final String month; final Function(String) onMonthSelected; + const QuestionAnswer4Page({ Key? key, required this.name, @@ -24,7 +28,8 @@ class _QuestionAnswerPage4State extends State { String selectedArea = ''; List answers = []; String questionText = ''; - String month=''; + String month = ''; + final ScrollController _controller = ScrollController(); @@ -35,6 +40,7 @@ class _QuestionAnswerPage4State extends State { } void loadQuestions() async { + enableForwardNavigation = false; // Load the JSON data from the file String jsonString = await DefaultAssetBundle.of(context) .loadString('assets/raw_eng/questions2Modified.json'); @@ -81,15 +87,27 @@ class _QuestionAnswerPage4State extends State { ], ), SizedBox( - width: MediaQuery.of(context).size.width * 0.8, - height: MediaQuery.of(context).size.height * 0.15, + width: MediaQuery + .of(context) + .size + .width * 0.8, + height: MediaQuery + .of(context) + .size + .height * 0.15, child: Text(questionText, style: const TextStyle(fontSize: 16), ), ), SizedBox( - height: MediaQuery.of(context).size.height *0.4, - width: MediaQuery.of(context).size.width * 0.6, + height: MediaQuery + .of(context) + .size + .height * 0.4, + width: MediaQuery + .of(context) + .size + .width * 0.6, child: Scrollbar( controller: _controller, child: ListView.separated( @@ -117,11 +135,31 @@ class _QuestionAnswerPage4State extends State { setState(() { selectedArea = answer; month = answer; - widget.onMonthSelected(month); + validateMonth(month); + if(isMonthValid == true) { + widget.onMonthSelected(month); + enableForwardNavigation = true; + } + + Container( + color: isSelected ? Colors.white : null, + padding: const EdgeInsets.all(1.0), + margin: const EdgeInsets.symmetric(vertical: 1.0), + child: Text( + answer, + style: TextStyle( + color: isSelected ? Colors.white : Colors.black, + fontWeight: FontWeight.bold, + ), + ), + ); + if(isMonthValid == true); }); + }, - child: Container( - color: isSelected ? Colors.green : null, + + child: Container( + color: isSelected ? Colors.green : null, padding: const EdgeInsets.all(1.0), margin: const EdgeInsets.symmetric(vertical: 1.0), child: Text( @@ -134,4 +172,37 @@ class _QuestionAnswerPage4State extends State { ), ); } -} \ No newline at end of file +} + +void validateMonth(String month) { + var currentDate = DateTime.now(); + var currentMonth = currentDate.month; + var selectedMonth =0; + + switch (month) { + case "January" : (selectedMonth=1); + case "February" : (selectedMonth=2); + case "March" : (selectedMonth=3); + case "April" : (selectedMonth=4); + case "May" : (selectedMonth=5); + case "June" : (selectedMonth=6); + case "July" : (selectedMonth=7); + case "August" : (selectedMonth=8); + case "September" : (selectedMonth=9); + case "October" : (selectedMonth=10); + case "November" : (selectedMonth=11); + case "December" : (selectedMonth=12); + } + + + + if(selectedMonth > currentMonth) { + isMonthValid = false; + } + else { + isMonthValid = true; + } + +} + + From 6232093085b8ed70009eb1a5a162fa5821ae009c Mon Sep 17 00:00:00 2001 From: Tim Honisett <40595819@live.napier.ac.uk> Date: Mon, 15 Apr 2024 09:48:36 +0100 Subject: [PATCH 6/8] Question13.dart now showing protected areas for selected state from page 10 --- lib/question_screens/question13.dart | 70 +++++++++++++++++------ lib/question_screens/question3.dart | 3 + lib/question_screens/questions_utils.dart | 25 ++++++-- 3 files changed, 75 insertions(+), 23 deletions(-) diff --git a/lib/question_screens/question13.dart b/lib/question_screens/question13.dart index cda3d89..4381b24 100644 --- a/lib/question_screens/question13.dart +++ b/lib/question_screens/question13.dart @@ -1,12 +1,28 @@ import 'dart:convert'; import 'package:flutter/material.dart'; +import 'package:remar_flutter_app/question_screens/questions_utils.dart'; class QuestionAnswer13Page extends StatefulWidget { - const QuestionAnswer13Page({super.key}); + + final String image; + final String name; + final String state; + final String protectedArea; + final Function(String) onProtectedAreaSelected; + + const QuestionAnswer13Page({ + Key? key, + required this.image, + required this.name, + required this.state, + required this.protectedArea, + required this.onProtectedAreaSelected +}) : super(key:key); @override _QuestionAnswerPage13State createState() => _QuestionAnswerPage13State(); -} + } + class _QuestionAnswerPage13State extends State { String selectedAnswer = ''; @@ -16,6 +32,7 @@ class _QuestionAnswerPage13State extends State { String questionText = ''; String extraDetailText = ''; bool isExpanded = false; + bool displayAnswers = false; // Flag to control displaying answers @override void initState() { @@ -33,6 +50,7 @@ class _QuestionAnswerPage13State extends State { Map firstQuestionData = jsonData[12]; // Set question text and answers list setState(() { + questionText = firstQuestionData['question']; extraDetailText = firstQuestionData['extraDetailText']; // Extract areas from the answers map @@ -41,7 +59,16 @@ class _QuestionAnswerPage13State extends State { .expand((areaList) => areaList as List) .toList(); // Cast areas to List - areas = areasList.map((area) => area.toString()).toList(); + Map answerMap = firstQuestionData['answers']; + List stateList = answerMap[state]; + + + // Cast answers to List + answers = stateList.map((answer) => answer.toString()).toList(); + areas = stateList.map((area) => area.toString()).toList(); + print(state); + print(areas); + }); } @@ -51,35 +78,38 @@ class _QuestionAnswerPage13State extends State { return Scaffold( body: ListView( - padding: const EdgeInsets.all(16.0), + padding: EdgeInsets.all(16.0), children: [ Text( questionText, - style: const TextStyle( + style: TextStyle( fontWeight: FontWeight.bold, fontSize: 20.0, ), ), - const SizedBox(height: 10.0), + SizedBox(height: 10.0), Row( children: [ buildCheckbox("Yes", selectedAnswer == "Yes"), - const SizedBox(width: 10.0), + SizedBox(width: 10.0), buildCheckbox("No", selectedAnswer == "No"), - const SizedBox(width: 10.0), + SizedBox(width: 10.0), buildCheckbox("I don't know", selectedAnswer == "I don't know"), ], ), - const SizedBox(height: 20.0), + SizedBox(height: 20.0), Text( extraDetailText, - style: const TextStyle( + style: TextStyle( fontSize: 16.0, ), ), - const SizedBox(height: 20.0), - for (var area in displayedAreas) buildAnswerButton(area), - if (!isExpanded) + SizedBox(height: 20.0), + // Display answers only if "Yes" is selected + if (displayAnswers) + for (var area in displayedAreas) buildAnswerButton(area), + if (!isExpanded && + displayAnswers) // Hide "Name not in list" until "Yes" is selected GestureDetector( onTap: () { setState(() { @@ -88,9 +118,9 @@ class _QuestionAnswerPage13State extends State { }, child: Container( color: Colors.green, - padding: const EdgeInsets.all(12.0), - margin: const EdgeInsets.symmetric(vertical: 8.0), - child: const Text( + padding: EdgeInsets.all(12.0), + margin: EdgeInsets.symmetric(vertical: 8.0), + child: Text( "Name not in list", style: TextStyle( color: Colors.white, @@ -109,6 +139,8 @@ class _QuestionAnswerPage13State extends State { onTap: () { setState(() { selectedAnswer = title; + // Update the flag based on the selected answer + displayAnswers = selectedAnswer == "Yes"; }); }, child: Row( @@ -116,7 +148,7 @@ class _QuestionAnswerPage13State extends State { Container( width: 24.0, height: 24.0, - margin: const EdgeInsets.only(right: 8.0), + margin: EdgeInsets.only(right: 8.0), decoration: BoxDecoration( border: Border.all(color: Colors.black), color: selected ? Colors.green : Colors.transparent, @@ -144,8 +176,8 @@ class _QuestionAnswerPage13State extends State { }, child: Container( color: isSelected ? Colors.green : null, - padding: const EdgeInsets.all(12.0), - margin: const EdgeInsets.symmetric(vertical: 8.0), + padding: EdgeInsets.all(12.0), + margin: EdgeInsets.symmetric(vertical: 8.0), child: Text( answer, style: TextStyle( diff --git a/lib/question_screens/question3.dart b/lib/question_screens/question3.dart index 9f76cce..0a84e5c 100644 --- a/lib/question_screens/question3.dart +++ b/lib/question_screens/question3.dart @@ -30,6 +30,9 @@ class _QuestionAnswerPage3State extends State { String questionText = ''; String year=''; + final ScrollController _controller = ScrollController(); + + @override void initState() { super.initState(); diff --git a/lib/question_screens/questions_utils.dart b/lib/question_screens/questions_utils.dart index 6831e7a..35514c4 100644 --- a/lib/question_screens/questions_utils.dart +++ b/lib/question_screens/questions_utils.dart @@ -1,6 +1,6 @@ -import 'package:flutter/cupertino.dart'; -import 'package:flutter/cupertino.dart'; + +import 'package:flutter/cupertino.dart'; import 'package:remar_flutter_app/question_screens/question3.dart'; import 'package:remar_flutter_app/question_screens/question4.dart'; import 'package:remar_flutter_app/question_screens/question5.dart'; @@ -33,6 +33,8 @@ String intensity =''; String berried=''; String whenObserved=''; String habitat = ''; +bool isProtectedArea = false; +String protectedArea = ''; String additionalInfo=''; @@ -56,8 +58,6 @@ void onWhenObserved(String selectedWhenObserved) { whenObserved = selectedWhenObserved; } - - void onStateSelected(String selectedState) { state = selectedState; } @@ -75,6 +75,14 @@ void onHabitatSelected(String selectedHabit) { habitat = selectedHabit; } +void onIsProtectedAreaSelected(bool selectedIsProtected) { + isProtectedArea = selectedIsProtected; +} + +void onProtectedAreaSelected(String selectedProtectedArea) { + protectedArea = selectedProtectedArea; +} + void onAdditionalInfoSelected(String selectedAdditionalInfo) { additionalInfo = selectedAdditionalInfo; @@ -143,6 +151,14 @@ Widget question12 = QuestionAnswer12Page( county: county, ); +Widget question13 = QuestionAnswer13Page( + image: crabImage, + name: crabSpecies, + state: state, + onProtectedAreaSelected: onProtectedAreaSelected, + protectedArea: protectedArea, +); + Widget question15 = QuestionAnswer15Page( image: crabImage, name: crabSpecies, @@ -165,6 +181,7 @@ List questionsPagesList = [ question10, question11, question12, + question13, question15, question16 //const QuestionAnswer13Page(), From a91c1b42de54bfdae1c5c7cfc366a17d30cafead Mon Sep 17 00:00:00 2001 From: Tim Honisett <40595819@live.napier.ac.uk> Date: Mon, 15 Apr 2024 10:26:47 +0100 Subject: [PATCH 7/8] Question page 14 re-added --- lib/question_screens/question13.dart | 4 +- lib/question_screens/question14.dart | 173 ++++++++++++++++++++++ lib/question_screens/questions_utils.dart | 18 ++- 3 files changed, 188 insertions(+), 7 deletions(-) create mode 100644 lib/question_screens/question14.dart diff --git a/lib/question_screens/question13.dart b/lib/question_screens/question13.dart index 4381b24..b20d7bd 100644 --- a/lib/question_screens/question13.dart +++ b/lib/question_screens/question13.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:remar_flutter_app/question_screens/questions_utils.dart'; + class QuestionAnswer13Page extends StatefulWidget { final String image; @@ -66,8 +67,7 @@ class _QuestionAnswerPage13State extends State { // Cast answers to List answers = stateList.map((answer) => answer.toString()).toList(); areas = stateList.map((area) => area.toString()).toList(); - print(state); - print(areas); + }); } diff --git a/lib/question_screens/question14.dart b/lib/question_screens/question14.dart new file mode 100644 index 0000000..7c25742 --- /dev/null +++ b/lib/question_screens/question14.dart @@ -0,0 +1,173 @@ +import 'dart:convert'; +import 'dart:core'; +import 'package:flutter/material.dart'; +import 'package:remar_flutter_app/question_screens/global.dart'; + +bool isMonthValid = false; + +class QuestionAnswer14Page extends StatefulWidget { + + final String name; + final String image; + final String occupation; + final Function(String) onOccupationSelected; + + + const QuestionAnswer14Page({ + Key? key, + required this.name, + required this.image, required this.occupation, required this.onOccupationSelected, + }) : super(key: key); + + + @override + _QuestionAnswerPage14State createState() => _QuestionAnswerPage14State(); +} + +class _QuestionAnswerPage14State extends State { + String selectedArea = ''; + List answers = []; + String questionText = ''; + String occupation = ''; + + + final ScrollController _controller = ScrollController(); + + @override + void initState() { + super.initState(); + loadQuestions(); + } + + void loadQuestions() async { + enableForwardNavigation = false; + // Load the JSON data from the file + String jsonString = await DefaultAssetBundle.of(context) + .loadString('assets/raw_eng/questions2Modified.json'); + + // Parse the JSON string into a list of objects + List jsonData = jsonDecode(jsonString); + + // Extract data from the first question (question number 9) + Map firstQuestionData = jsonData[13]; + + + // Set question text and answers list + setState(() { + questionText = firstQuestionData['question_10']; + + // Extract answers from the answers map + List answerList = firstQuestionData['answers_10']; + + // Cast answers to List + answers = answerList.map((answer) => answer.toString()).toList(); + }); + } + + + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + body: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Image.asset( + widget.image, + width: 100, + height: 125, + ), + Text( + widget.name, + style: const TextStyle(fontSize: 24), + ), + ], + ), + SizedBox( + width: MediaQuery + .of(context) + .size + .width * 0.8, + height: MediaQuery + .of(context) + .size + .height * 0.15, + child: Text(questionText, + style: const TextStyle(fontSize: 16), + ), + ), + SizedBox( + height: MediaQuery + .of(context) + .size + .height * 0.4, + width: MediaQuery + .of(context) + .size + .width * 0.6, + child: Scrollbar( + controller: _controller, + child: ListView.separated( + controller: _controller, + itemCount: answers.length, + itemBuilder: (BuildContext context, int index) { + return buildAnswerButton(answers[index]); + }, separatorBuilder: (BuildContext context, int index) { + return const Divider(); + }, + ), + ), + ), + ], // Column children + ), // Column + ), // Scaffold + ); // MaterialApp + } + + Widget buildAnswerButton(String answer) { + bool isSelected = answer == selectedArea; + + return GestureDetector( + onTap: () { + setState(() { + selectedArea = answer; + occupation = answer; + widget.onOccupationSelected(occupation); + enableForwardNavigation = true; + + + Container( + color: isSelected ? Colors.white : null, + padding: const EdgeInsets.all(1.0), + margin: const EdgeInsets.symmetric(vertical: 1.0), + child: Text( + answer, + style: TextStyle( + color: isSelected ? Colors.white : Colors.black, + fontWeight: FontWeight.bold, + ), + ), + ); + if(isMonthValid == true); + }); + + }, + + child: Container( + color: isSelected ? Colors.green : null, + padding: const EdgeInsets.all(1.0), + margin: const EdgeInsets.symmetric(vertical: 1.0), + child: Text( + answer, + style: TextStyle( + color: isSelected ? Colors.white : Colors.black, + fontWeight: FontWeight.bold, + ), + ), + ), + ); + } +} \ No newline at end of file diff --git a/lib/question_screens/questions_utils.dart b/lib/question_screens/questions_utils.dart index 35514c4..f8d2b3c 100644 --- a/lib/question_screens/questions_utils.dart +++ b/lib/question_screens/questions_utils.dart @@ -13,7 +13,7 @@ import 'package:remar_flutter_app/question_screens/question10.dart'; import 'package:remar_flutter_app/question_screens/question11.dart'; import 'package:remar_flutter_app/question_screens/question12.dart'; import 'package:remar_flutter_app/question_screens/question13.dart'; -// import 'package:remar_flutter_app/question_screens/question14.dart'; +import 'package:remar_flutter_app/question_screens/question14.dart'; import 'package:remar_flutter_app/question_screens/question15.dart'; import 'package:remar_flutter_app/question_screens/question16.dart'; import 'global.dart'; @@ -33,7 +33,7 @@ String intensity =''; String berried=''; String whenObserved=''; String habitat = ''; -bool isProtectedArea = false; +String occupation =''; String protectedArea = ''; String additionalInfo=''; @@ -75,14 +75,14 @@ void onHabitatSelected(String selectedHabit) { habitat = selectedHabit; } -void onIsProtectedAreaSelected(bool selectedIsProtected) { - isProtectedArea = selectedIsProtected; -} void onProtectedAreaSelected(String selectedProtectedArea) { protectedArea = selectedProtectedArea; } +void onOccupationSelected(String selectOccuption) { + +} void onAdditionalInfoSelected(String selectedAdditionalInfo) { additionalInfo = selectedAdditionalInfo; @@ -159,6 +159,13 @@ Widget question13 = QuestionAnswer13Page( protectedArea: protectedArea, ); +Widget question14 = QuestionAnswer14Page( + image: crabImage, + name: crabSpecies, + onOccupationSelected: onOccupationSelected, + occupation: occupation, +); + Widget question15 = QuestionAnswer15Page( image: crabImage, name: crabSpecies, @@ -182,6 +189,7 @@ List questionsPagesList = [ question11, question12, question13, + question14, question15, question16 //const QuestionAnswer13Page(), From cc1e2b2e49f44203767a6de773d304f3fdd31607 Mon Sep 17 00:00:00 2001 From: Tim Honisett <40595819@live.napier.ac.uk> Date: Mon, 15 Apr 2024 11:23:00 +0100 Subject: [PATCH 8/8] Disable forward navigation on null input for questions 3, 4, 7, 9, 10, 11, 12, 13, 14 --- lib/question_screens/global.dart | 1 - lib/question_screens/question10.dart | 5 + lib/question_screens/question11.dart | 5 + lib/question_screens/question12.dart | 3 + lib/question_screens/question13.dart | 32 +++-- lib/question_screens/question14.dart | 1 - lib/question_screens/question15.dart | 5 + lib/question_screens/question16.dart | 6 +- lib/question_screens/question3.dart | 3 +- lib/question_screens/question4.dart | 80 ++++++------ lib/question_screens/question7.dart | 5 +- lib/question_screens/question8.dart | 7 +- lib/question_screens/question9.dart | 176 ++++++++++++++++----------- 13 files changed, 194 insertions(+), 135 deletions(-) diff --git a/lib/question_screens/global.dart b/lib/question_screens/global.dart index 7becdad..704d13d 100644 --- a/lib/question_screens/global.dart +++ b/lib/question_screens/global.dart @@ -1,2 +1 @@ - bool enableForwardNavigation = false; diff --git a/lib/question_screens/question10.dart b/lib/question_screens/question10.dart index 3ae01c7..8c827fc 100644 --- a/lib/question_screens/question10.dart +++ b/lib/question_screens/question10.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'package:flutter/material.dart'; +import 'package:remar_flutter_app/question_screens/global.dart'; class QuestionAnswer10Page extends StatefulWidget { @@ -36,6 +37,9 @@ class _QuestionAnswerPage10State extends State { } void loadQuestions() async { + + enableForwardNavigation = false; + // Load the JSON data from the file String jsonString = await DefaultAssetBundle.of(context) .loadString('assets/raw_eng/questions2Modified.json'); @@ -126,6 +130,7 @@ class _QuestionAnswerPage10State extends State { selectedArea = answer; habitat = answer; widget.onHabitatSelected(habitat); + enableForwardNavigation = true; }); }, child: Container( diff --git a/lib/question_screens/question11.dart b/lib/question_screens/question11.dart index 61c8a50..a1654ed 100644 --- a/lib/question_screens/question11.dart +++ b/lib/question_screens/question11.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'package:flutter/material.dart'; +import 'package:remar_flutter_app/question_screens/global.dart'; class QuestionAnswer11Page extends StatefulWidget { @@ -34,6 +35,9 @@ class _QuestionAnswerPage11State extends State { } void loadQuestions() async { + + enableForwardNavigation = false; + // Load the JSON data from the file String jsonString = await DefaultAssetBundle.of(context) .loadString('assets/raw_eng/questions2Modified.json'); @@ -116,6 +120,7 @@ class _QuestionAnswerPage11State extends State { selectedArea = answer; state = answer; widget.onStateSelected(state); + enableForwardNavigation = true; }); }, child: Container( diff --git a/lib/question_screens/question12.dart b/lib/question_screens/question12.dart index 0920f2b..fa2b776 100644 --- a/lib/question_screens/question12.dart +++ b/lib/question_screens/question12.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'package:flutter/material.dart'; +import 'package:remar_flutter_app/question_screens/global.dart'; import 'package:remar_flutter_app/question_screens/questions_utils.dart'; class QuestionAnswer12Page extends StatefulWidget { @@ -40,6 +41,7 @@ class _QuestionAnswerPage12State extends State { void loadQuestions() async { + enableForwardNavigation = false; // Load the JSON data from the file String jsonString = await DefaultAssetBundle.of(context) @@ -122,6 +124,7 @@ class _QuestionAnswerPage12State extends State { selectedArea = answer; county = answer; widget.onCountySelected(county); + enableForwardNavigation = true; }); }, child: Container( diff --git a/lib/question_screens/question13.dart b/lib/question_screens/question13.dart index b20d7bd..23784e6 100644 --- a/lib/question_screens/question13.dart +++ b/lib/question_screens/question13.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'package:flutter/material.dart'; +import 'package:remar_flutter_app/question_screens/global.dart'; import 'package:remar_flutter_app/question_screens/questions_utils.dart'; @@ -42,6 +43,9 @@ class _QuestionAnswerPage13State extends State { } void loadQuestions() async { + + enableForwardNavigation = false; + // Load the JSON data from the file String jsonString = await DefaultAssetBundle.of(context) .loadString('assets/raw_eng/questions2Modified.json'); @@ -78,49 +82,52 @@ class _QuestionAnswerPage13State extends State { return Scaffold( body: ListView( - padding: EdgeInsets.all(16.0), + padding: const EdgeInsets.all(16.0), children: [ Text( questionText, - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 20.0, ), ), - SizedBox(height: 10.0), + const SizedBox(height: 10.0), Row( children: [ buildCheckbox("Yes", selectedAnswer == "Yes"), - SizedBox(width: 10.0), + const SizedBox(width: 10.0), buildCheckbox("No", selectedAnswer == "No"), - SizedBox(width: 10.0), + const SizedBox(width: 10.0), buildCheckbox("I don't know", selectedAnswer == "I don't know"), ], ), - SizedBox(height: 20.0), + const SizedBox(height: 20.0), Text( extraDetailText, - style: TextStyle( + style: const TextStyle( fontSize: 16.0, ), ), SizedBox(height: 20.0), // Display answers only if "Yes" is selected if (displayAnswers) + for (var area in displayedAreas) buildAnswerButton(area), if (!isExpanded && - displayAnswers) // Hide "Name not in list" until "Yes" is selected + displayAnswers) + // Hide "Name not in list" until "Yes" is selected GestureDetector( onTap: () { setState(() { isExpanded = true; + enableForwardNavigation = false; }); }, child: Container( color: Colors.green, - padding: EdgeInsets.all(12.0), + padding: const EdgeInsets.all(12.0), margin: EdgeInsets.symmetric(vertical: 8.0), - child: Text( + child: const Text( "Name not in list", style: TextStyle( color: Colors.white, @@ -141,6 +148,7 @@ class _QuestionAnswerPage13State extends State { selectedAnswer = title; // Update the flag based on the selected answer displayAnswers = selectedAnswer == "Yes"; + enableForwardNavigation = true; }); }, child: Row( @@ -176,8 +184,8 @@ class _QuestionAnswerPage13State extends State { }, child: Container( color: isSelected ? Colors.green : null, - padding: EdgeInsets.all(12.0), - margin: EdgeInsets.symmetric(vertical: 8.0), + padding: const EdgeInsets.all(12.0), + margin: const EdgeInsets.symmetric(vertical: 8.0), child: Text( answer, style: TextStyle( diff --git a/lib/question_screens/question14.dart b/lib/question_screens/question14.dart index 7c25742..f448f91 100644 --- a/lib/question_screens/question14.dart +++ b/lib/question_screens/question14.dart @@ -151,7 +151,6 @@ class _QuestionAnswerPage14State extends State { ), ), ); - if(isMonthValid == true); }); }, diff --git a/lib/question_screens/question15.dart b/lib/question_screens/question15.dart index b2a6433..4a55933 100644 --- a/lib/question_screens/question15.dart +++ b/lib/question_screens/question15.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; +import 'package:remar_flutter_app/question_screens/global.dart'; class QuestionAnswer15Page extends StatefulWidget { final String name; @@ -34,6 +35,9 @@ class _QuestionAnswerPage15State extends State { } void loadQuestions() async { + + // enableForwardNavigation = false; + // Load the JSON data from the file String jsonString = await DefaultAssetBundle.of(context) .loadString('assets/raw_eng/questions2Modified.json'); @@ -124,6 +128,7 @@ class _QuestionAnswerPage15State extends State { selectedAnswer = answer; additionalInfo = answer; widget.onAdditionalInfoSelected(additionalInfo); + // enableForwardNavigation = true; }); }, child: Container( diff --git a/lib/question_screens/question16.dart b/lib/question_screens/question16.dart index 1e96633..bed9a54 100644 --- a/lib/question_screens/question16.dart +++ b/lib/question_screens/question16.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; +import 'package:remar_flutter_app/question_screens/global.dart'; import 'package:url_launcher/url_launcher.dart'; class QuestionAnswer16Page extends StatefulWidget { @@ -29,6 +30,9 @@ class _QuestionAnswer16Page extends State { } void loadQuestionData() async { + + enableForwardNavigation = false; + // Load JSON data from asset file String jsonString = await DefaultAssetBundle.of(context) .loadString('assets/raw_eng/questions2Modified.json'); @@ -43,10 +47,10 @@ class _QuestionAnswer16Page extends State { // Assign values to variables setState(() { description = questionData['description']; - choiceOneText = questionData['choiceOneText']; choiceTwoText = questionData['choiceTwoText']; choiceThreeText = questionData['choiceThreeText']; + // enableForwardNavigation = true; }); } diff --git a/lib/question_screens/question3.dart b/lib/question_screens/question3.dart index 0a84e5c..eb75fdd 100644 --- a/lib/question_screens/question3.dart +++ b/lib/question_screens/question3.dart @@ -5,6 +5,7 @@ import 'global.dart'; List yearList = []; // Declaration of yearList + class QuestionAnswer3Page extends StatefulWidget { final String name; @@ -30,8 +31,6 @@ class _QuestionAnswerPage3State extends State { String questionText = ''; String year=''; - final ScrollController _controller = ScrollController(); - @override void initState() { diff --git a/lib/question_screens/question4.dart b/lib/question_screens/question4.dart index 484c3f5..4b2c8d5 100644 --- a/lib/question_screens/question4.dart +++ b/lib/question_screens/question4.dart @@ -142,24 +142,24 @@ class _QuestionAnswerPage4State extends State { } Container( - color: isSelected ? Colors.white : null, - padding: const EdgeInsets.all(1.0), - margin: const EdgeInsets.symmetric(vertical: 1.0), - child: Text( - answer, - style: TextStyle( - color: isSelected ? Colors.white : Colors.black, - fontWeight: FontWeight.bold, - ), + color: isSelected ? Colors.white : null, + padding: const EdgeInsets.all(1.0), + margin: const EdgeInsets.symmetric(vertical: 1.0), + child: Text( + answer, + style: TextStyle( + color: isSelected ? Colors.white : Colors.black, + fontWeight: FontWeight.bold, ), - ); - if(isMonthValid == true); + ), + ); + }); }, - child: Container( - color: isSelected ? Colors.green : null, + child: Container( + color: isSelected ? Colors.green : null, padding: const EdgeInsets.all(1.0), margin: const EdgeInsets.symmetric(vertical: 1.0), child: Text( @@ -175,34 +175,32 @@ class _QuestionAnswerPage4State extends State { } void validateMonth(String month) { - var currentDate = DateTime.now(); - var currentMonth = currentDate.month; - var selectedMonth =0; - - switch (month) { - case "January" : (selectedMonth=1); - case "February" : (selectedMonth=2); - case "March" : (selectedMonth=3); - case "April" : (selectedMonth=4); - case "May" : (selectedMonth=5); - case "June" : (selectedMonth=6); - case "July" : (selectedMonth=7); - case "August" : (selectedMonth=8); - case "September" : (selectedMonth=9); - case "October" : (selectedMonth=10); - case "November" : (selectedMonth=11); - case "December" : (selectedMonth=12); - } - - - - if(selectedMonth > currentMonth) { - isMonthValid = false; - } - else { - isMonthValid = true; - } + var currentDate = DateTime.now(); + var currentMonth = currentDate.month; + var selectedMonth =0; + + switch (month) { + case "January" : (selectedMonth=1); + case "February" : (selectedMonth=2); + case "March" : (selectedMonth=3); + case "April" : (selectedMonth=4); + case "May" : (selectedMonth=5); + case "June" : (selectedMonth=6); + case "July" : (selectedMonth=7); + case "August" : (selectedMonth=8); + case "September" : (selectedMonth=9); + case "October" : (selectedMonth=10); + case "November" : (selectedMonth=11); + case "December" : (selectedMonth=12); + } -} + if(selectedMonth > currentMonth) { + isMonthValid = false; + } + else { + isMonthValid = true; + } + +} diff --git a/lib/question_screens/question7.dart b/lib/question_screens/question7.dart index 0a2bf0a..08571d5 100644 --- a/lib/question_screens/question7.dart +++ b/lib/question_screens/question7.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'package:flutter/material.dart'; +import 'package:remar_flutter_app/question_screens/global.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -34,6 +35,8 @@ class _QuestionAnswerPage7State extends State { } void loadQuestions() async { + + enableForwardNavigation = false; // Load the JSON data from the file String jsonString = await DefaultAssetBundle.of(context) .loadString('assets/raw_eng/questions2Modified.json'); @@ -114,7 +117,7 @@ class _QuestionAnswerPage7State extends State { selectedArea = answer; intensity = answer; widget.onIntensitySelected(intensity); - + enableForwardNavigation = true; }); }, child: Container( diff --git a/lib/question_screens/question8.dart b/lib/question_screens/question8.dart index 88a6ac6..b3f3144 100644 --- a/lib/question_screens/question8.dart +++ b/lib/question_screens/question8.dart @@ -1,7 +1,6 @@ import 'dart:convert'; import 'package:flutter/material.dart'; -import 'package:shared_preferences/shared_preferences.dart'; - +import 'package:remar_flutter_app/question_screens/global.dart'; class QuestionAnswer8Page extends StatefulWidget { @@ -34,6 +33,9 @@ class _QuestionAnswerPage8State extends State { } void loadQuestions() async { + + // enableForwardNavigation = false; + // Load the JSON data from the file String jsonString = await DefaultAssetBundle.of(context) .loadString('assets/raw_eng/questions2Modified.json'); @@ -115,6 +117,7 @@ class _QuestionAnswerPage8State extends State { selectedArea = answer; whenObserved = answer; widget.onWhenObserved(whenObserved); + // enableForwardNavigation = false; }); }, child: Container( diff --git a/lib/question_screens/question9.dart b/lib/question_screens/question9.dart index 45b7bca..2fd5f69 100644 --- a/lib/question_screens/question9.dart +++ b/lib/question_screens/question9.dart @@ -1,21 +1,23 @@ import 'dart:convert'; +import 'dart:core'; import 'package:flutter/material.dart'; +import 'package:remar_flutter_app/question_screens/global.dart'; +import 'package:remar_flutter_app/question_screens/questions_utils.dart'; -List yearList = []; // Declaration of yearList - +bool isMonthValid = false; class QuestionAnswer9Page extends StatefulWidget { final String name; final String image; + final String berried; final Function(String) onBerriedSelected; const QuestionAnswer9Page({ Key? key, required this.name, - required this.image, - required this.onBerriedSelected, required String berried, + required this.image, required this.berried, required this.onBerriedSelected, }) : super(key: key); @@ -24,10 +26,13 @@ class QuestionAnswer9Page extends StatefulWidget { } class _QuestionAnswerPage9State extends State { - List selectedAnswer = []; + String selectedArea = ''; List answers = []; String questionText = ''; - String berried=''; + String berried = ''; + + + final ScrollController _controller = ScrollController(); @override void initState() { @@ -36,102 +41,125 @@ class _QuestionAnswerPage9State extends State { } void loadQuestions() async { + enableForwardNavigation = false; // Load the JSON data from the file String jsonString = await DefaultAssetBundle.of(context) .loadString('assets/raw_eng/questions2Modified.json'); + // Parse the JSON string into a list of objects List jsonData = jsonDecode(jsonString); - // Extract data from the question with questionNumber 10 - Map? question10Data = jsonData.firstWhere( - (question) => question['questionNumber'] == 10, - orElse: () => null); - if (question10Data != null) { - // Extract question and answers - String? question = question10Data['question_10']; - List? answersList = question10Data['answers_10']; + // Extract data from the first question (question number 9) + Map firstQuestionData = jsonData[8]; - if (question != null && answersList != null) { - setState(() { - questionText = question; - answers = answersList.cast(); // Cast answers to String list - }); - } - } + + // Set question text and answers list + setState(() { + questionText = firstQuestionData['description']; + + // Extract answers from the answers map + List answerList = firstQuestionData['answers']; + + // Cast answers to List + answers = answerList.map((answer) => answer.toString()).toList(); + }); } + @override Widget build(BuildContext context) { - return Scaffold( - body: ListView( - padding: const EdgeInsets.all(16.0), - children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - flex: 1, - child: Image.asset( - 'assets/images/raster_q0_0.png', - height: 200, - width: 200, + return MaterialApp( + home: Scaffold( + body: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Image.asset( + widget.image, + width: 100, + height: 125, + ), + Text( + widget.name, + style: const TextStyle(fontSize: 24), ), + ], + ), + SizedBox( + width: MediaQuery + .of(context) + .size + .width * 0.8, + height: MediaQuery + .of(context) + .size + .height * 0.15, + child: Text(questionText, + style: const TextStyle(fontSize: 16), ), - const SizedBox(width: 20.0), - const Expanded( - flex: 2, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "Monitoring Ucides cordatus", - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 20.0, - ), - ), - SizedBox(height: 10.0), - ], + ), + SizedBox( + height: MediaQuery + .of(context) + .size + .height * 0.4, + width: MediaQuery + .of(context) + .size + .width * 0.6, + child: Scrollbar( + controller: _controller, + child: ListView.separated( + controller: _controller, + itemCount: answers.length, + itemBuilder: (BuildContext context, int index) { + return buildAnswerButton(answers[index]); + }, separatorBuilder: (BuildContext context, int index) { + return const Divider(); + }, ), ), - ], - ), - const SizedBox(height: 20.0), - Text( - questionText, - style: const TextStyle( - fontSize: 16.0, ), - ), - const SizedBox(height: 20.0), - for (var answer in answers) buildAnswerButton(answer), - ], - ), - ); + ], // Column children + ), // Column + ), // Scaffold + ); // MaterialApp } Widget buildAnswerButton(String answer) { - bool isSelected = selectedAnswer.contains(answer); + bool isSelected = answer == selectedArea; return GestureDetector( onTap: () { setState(() { - if (isSelected) { - selectedAnswer.remove(answer); - } else { - selectedAnswer.clear(); - selectedAnswer.add(answer); - } - selectedAnswer = answer as List; + selectedArea = answer; berried = answer; - widget.onBerriedSelected(berried); - + widget.onBerriedSelected(month); + enableForwardNavigation = true; + + + Container( + color: isSelected ? Colors.white : null, + padding: const EdgeInsets.all(1.0), + margin: const EdgeInsets.symmetric(vertical: 1.0), + child: Text( + answer, + style: TextStyle( + color: isSelected ? Colors.white : Colors.black, + fontWeight: FontWeight.bold, + ), + ), + ); }); + }, + child: Container( color: isSelected ? Colors.green : null, - padding: const EdgeInsets.all(12.0), - margin: const EdgeInsets.symmetric(vertical: 8.0), + padding: const EdgeInsets.all(1.0), + margin: const EdgeInsets.symmetric(vertical: 1.0), child: Text( answer, style: TextStyle(