diff --git a/lib/question_screens/question15.dart b/lib/question_screens/question15.dart new file mode 100644 index 0000000..88b0529 --- /dev/null +++ b/lib/question_screens/question15.dart @@ -0,0 +1,149 @@ +import 'dart:convert'; + +import 'package:flutter/material.dart'; + +class QuestionAnswer15Page extends StatefulWidget { + final String name; + final String image; + final String additionalInfo; + final Function(String) onAdditionalInfo; + + const QuestionAnswer15Page({ + Key? key, + required this.name, + required this.image, + required this.onAdditionalInfo, required this.additionalInfo + }) : super(key: key); + + @override + _QuestionAnswerPage15State createState() => _QuestionAnswerPage15State(); +} + +class _QuestionAnswerPage15State extends State { + String questionText = ''; + String selectedAnswer = ''; + late List answers = []; + late String otherText = ''; + late int otherPosition = 0; + String additionalInfo=''; + + @override + void initState() { + super.initState(); + loadQuestions(); + } + + void loadQuestions() async { + // 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[14]; + + + // Set question text and answers list + setState(() { + questionText = firstQuestionData['description']; + otherText = firstQuestionData['otherText']; + + // Load answers from JSON data + List answerList = firstQuestionData['answers']; + answers = answerList.map((answer) => answer.toString()).toList(); + }); + } + + @override + Widget build(BuildContext context) { + return 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( + selectedAnswer == 'Yes' ? otherText : questionText, + style: const TextStyle(fontSize: 16), + ), + ), + if (selectedAnswer != 'Yes') + SizedBox( + width: MediaQuery.of(context).size.width * 0.8, + child: Column( + children: answers.map((answer) { + return Padding( + padding: const EdgeInsets.symmetric( + vertical: 7.0), // Add vertical padding + child: buildAnswerButton(answer, selectedAnswer == answer), + ); + }).toList(), + ), + ), + const SizedBox(height: 20), + if (selectedAnswer == 'Yes') + SizedBox( + width: MediaQuery.of(context).size.width * 0.8, + child: TextFormField( + decoration: const InputDecoration( + labelText: 'Type your observation', + border: OutlineInputBorder(), + ), + onChanged: (value) { + // Handle text field changes + }, + ), + ), + ], // Column children + ), // Column + ); + } + + Widget buildAnswerButton(String answer, bool selected) { + return GestureDetector( + onTap: () { + setState(() { + selectedAnswer = answer; + additionalInfo = answer; + widget.onAdditionalInfo(additionalInfo); + }); + }, + child: Container( + alignment: Alignment.centerLeft, + padding: const EdgeInsets.all(1.0), + margin: const EdgeInsets.symmetric(vertical: 1.0), + width: double.maxFinite, + decoration: BoxDecoration( + color: selected ? Colors.green : null, + border: const Border(bottom: BorderSide(color: Colors.black))), + height: 30, + child: Text( + answer, + textAlign: TextAlign.start, + style: TextStyle( + color: selected ? Colors.white : Colors.black, + fontWeight: FontWeight.bold, + ), + ), + ), + ); + } +} \ No newline at end of file diff --git a/lib/question_screens/question8.dart b/lib/question_screens/question8.dart new file mode 100644 index 0000000..3caf2af --- /dev/null +++ b/lib/question_screens/question8.dart @@ -0,0 +1,133 @@ +import 'dart:convert'; +import 'package:flutter/material.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + + +class QuestionAnswer8Page extends StatefulWidget { + + final String name; + final String image; + final Function(String) onWhenObserved; + + const QuestionAnswer8Page({ + Key? key, + required this.name, + required this.image, + required this.onWhenObserved + }) : super(key: key); + + + @override + _QuestionAnswerPage8State createState() => _QuestionAnswerPage8State(); +} + +class _QuestionAnswerPage8State extends State { + String selectedArea = ''; + List answers = []; + String questionText = ''; + String whenObserved=''; + + @override + void initState() { + super.initState(); + loadQuestions(); + } + + void loadQuestions() async { + // 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[7]; + + // 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: 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), + ), + ), + Expanded( + child: SizedBox( + width: MediaQuery.of(context).size.width * 0.8, + child: Scrollbar( + child: ListView.separated( + itemCount: answers.length, + itemBuilder: (BuildContext context, int index) { + return buildAnswerButton(answers[index]); + }, separatorBuilder: (BuildContext context, int index) { + return const Divider(); + }, + ), + ), + ), + ), + ], // Column children + ), // Column + ); + + } + + Widget buildAnswerButton(String answer) { + bool isSelected = answer == selectedArea; + + return GestureDetector( + onTap: () { + setState(() { + selectedArea = answer; + whenObserved = answer; + widget.onWhenObserved(whenObserved); + }); + }, + 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 4da5d5f..8159e30 100644 --- a/lib/question_screens/questions_utils.dart +++ b/lib/question_screens/questions_utils.dart @@ -1,15 +1,21 @@ import 'package:flutter/cupertino.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/question3.dart'; import 'package:remar_flutter_app/question_screens/question4.dart'; +import 'package:remar_flutter_app/question_screens/question5.dart'; +import 'package:remar_flutter_app/question_screens/question6.dart'; import 'package:remar_flutter_app/question_screens/question7.dart'; +import 'package:remar_flutter_app/question_screens/question8.dart'; +//import 'package:remar_flutter_app/question_screens/question8.dart'; import 'package:remar_flutter_app/question_screens/question9.dart'; +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/question15.dart'; import 'package:remar_flutter_app/question_screens/question16.dart'; - - // list of answers const String crabSpecies = 'Ucides cordatus'; @@ -22,6 +28,9 @@ String state = ''; String county = ''; String intensity =''; String berried=''; +String whenObserved=''; +String additionalInfo=''; + // Define callback functions for updating the properties void onYearSelected(String selectedYear) { @@ -36,6 +45,13 @@ void onIntensitySelected(String selectedIntensity) { intensity = selectedIntensity; } + +void onWhenObserved(String selectedWhenObserved) { + whenObserved = selectedWhenObserved; + print(whenObserved); +} + + void onStateSelected(String selectedState) { state = selectedState; } @@ -49,6 +65,12 @@ void onBerriedSelected(String selectedBerried) { } +void onAdditionalInfoSelected(String selectedAdditionalInfo) { + additionalInfo = selectedAdditionalInfo; +} + + + // Create instances of question widgets with callback functions Widget question3 = QuestionAnswer3Page( image: crabImage, @@ -71,6 +93,15 @@ Widget question7 = QuestionAnswer7Page( onIntensitySelected: onIntensitySelected, ); + +Widget question8 = const QuestionAnswer8Page( + image: crabImage, + name: crabSpecies, + onWhenObserved: onWhenObserved, + +); + + Widget question9 = QuestionAnswer9Page( image: crabImage, name: crabSpecies, @@ -103,8 +134,10 @@ List questionsPagesList = [ question3, question4, question7, + question8, question11, question12, + question15, question16 //const QuestionAnswer13Page(), ]; \ No newline at end of file diff --git a/test/widget_test.dart b/test/widget_test.dart index 21e5896..9bbf623 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -11,12 +11,14 @@ import 'package:remar_flutter_app/main.dart'; + void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. await tester.pumpWidget(MyApp()); + // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); expect(find.text('1'), findsNothing);