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..0e97d84 100644 --- a/lib/question_screens/question14.dart +++ b/lib/question_screens/question14.dart @@ -151,7 +151,7 @@ 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(