Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions lib/question_screens/question15.dart
Original file line number Diff line number Diff line change
@@ -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<QuestionAnswer15Page> {
String questionText = '';
String selectedAnswer = '';
late List<String> 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<dynamic> jsonData = jsonDecode(jsonString);


// Extract data from the first question (question number 9)
Map<String, dynamic> firstQuestionData = jsonData[14];


// Set question text and answers list
setState(() {
questionText = firstQuestionData['description'];
otherText = firstQuestionData['otherText'];

// Load answers from JSON data
List<dynamic> 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,
),
),
),
);
}
}
133 changes: 133 additions & 0 deletions lib/question_screens/question8.dart
Original file line number Diff line number Diff line change
@@ -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<QuestionAnswer8Page> {
String selectedArea = '';
List<String> 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<dynamic> jsonData = jsonDecode(jsonString);

// Extract data from the first question (question number 9)
Map<String, dynamic> firstQuestionData = jsonData[7];

// Set question text and answers list
setState(() {
questionText = firstQuestionData['description'];

// Extract answers from the answers map
List<dynamic> answerList = firstQuestionData['answers'];

// Cast answers to List<String>
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,
),
),
),
);
}
}
43 changes: 38 additions & 5 deletions lib/question_screens/questions_utils.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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) {
Expand All @@ -36,6 +45,13 @@ void onIntensitySelected(String selectedIntensity) {
intensity = selectedIntensity;
}


void onWhenObserved(String selectedWhenObserved) {
whenObserved = selectedWhenObserved;
print(whenObserved);
}


void onStateSelected(String selectedState) {
state = selectedState;
}
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -103,8 +134,10 @@ List<Widget> questionsPagesList = [
question3,
question4,
question7,
question8,
question11,
question12,
question15,
question16
//const QuestionAnswer13Page(),
];
2 changes: 2 additions & 0 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down