Skip to content
Open
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
Binary file added patient/assets/illustrations/i9n_adhd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added patient/assets/illustrations/i9n_aq10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added patient/assets/illustrations/i9n_autism.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions patient/lib/gen/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

106 changes: 48 additions & 58 deletions patient/lib/presentation/assessments/assessment_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import 'package:patient/model/assessment_models/assessment_models.dart';
import 'package:patient/presentation/widgets/snackbar_service.dart';
import 'package:patient/provider/assessment_provider.dart';
import 'package:provider/provider.dart';
import 'package:patient/presentation/result/result.dart';


class AssessmentScreen extends StatefulWidget {
const AssessmentScreen({
Expand All @@ -26,25 +24,22 @@ class AssessmentScreenState extends State<AssessmentScreen> {
super.initState();
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
WidgetsBinding.instance.addPostFrameCallback((_) {
final assessmentProvider = context.read<AssessmentProvider>();
if (assessmentProvider.submitAssessmentStatus.isSuccess) {
SnackbarService.showSuccess(
'${assessmentProvider.assessmentResultModel?.message}');
} else if (assessmentProvider.submitAssessmentStatus.isFailure) {
SnackbarService.showError(
'Something went wrong. Please try again later.');
}
});
void _handleSubmit() async {
final assessmentProvider = context.read<AssessmentProvider>();
await assessmentProvider.submitAssessment();

if (assessmentProvider.submitAssessmentStatus.isSuccess) {
SnackbarService.showSuccess(
'${assessmentProvider.assessmentResultModel?.message}');
} else if (assessmentProvider.submitAssessmentStatus.isFailure) {
final errorMessage = assessmentProvider.errorMessage ??
'Something went wrong. Please try again later.';
SnackbarService.showError(errorMessage);
}
}

@override
Widget build(BuildContext context) {
Provider.of<AssessmentProvider>(context, listen: true)
.submitAssessmentStatus;
return Scaffold(
body: SafeArea(
child: Consumer<AssessmentProvider>(
Expand Down Expand Up @@ -98,36 +93,33 @@ class AssessmentScreenState extends State<AssessmentScreen> {
),
const SizedBox(height: 20),
Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 25),
child: SizedBox(
width: double.infinity,
height: 50,
child: ElevatedButton(
onPressed: () {

context.read<AssessmentProvider>().submitAssessment();

},
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.secondaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 25),
child: SizedBox(
width: double.infinity,
height: 50,
child: ElevatedButton(
onPressed: _handleSubmit,
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.secondaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
elevation: 2,
padding: const EdgeInsets.symmetric(vertical: 12),
),
elevation: 2, // Small shadow effect
padding: const EdgeInsets.symmetric(vertical: 12),
),
child: const Text(
'Submit Assessment',
style: TextStyle(
fontSize: 17,
color: Colors.white,
fontWeight: FontWeight.bold,
child: const Text(
'Submit Assessment',
style: TextStyle(
fontSize: 17,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
),
),
)),
),
],
),
);
Expand All @@ -152,7 +144,6 @@ class QuestionCard extends StatelessWidget {

@override
Widget build(BuildContext context) {

return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
Expand Down Expand Up @@ -195,23 +186,22 @@ class QuestionCard extends StatelessWidget {
side: const BorderSide(
color: Color(0xFF666666),
width: 1.5,

),
Expanded(
child: Text(
optionText,
style: const TextStyle(
fontSize: 14,
color: AppTheme.subtitleColor,
),
),
Expanded(
child: Text(
optionText,
style: const TextStyle(
fontSize: 14,
color: AppTheme.subtitleColor,
),
),
],
),
);
}),
],
),
),
],
),
);
}),
],
);
}
}
}
60 changes: 28 additions & 32 deletions patient/lib/presentation/assessments/widgets/assessment_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,36 @@ class AssessmentCard extends StatelessWidget {
borderRadius: BorderRadius.circular(16),
),
child: Padding(
padding: const EdgeInsets.only(top: 18.0, left: 18.0, right: 18.0),
child: Row(
padding: const EdgeInsets.all(18.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
assessment.name,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w700,
color: AppTheme.primaryColor,
),
),
const SizedBox(height: 8),
Text(
assessment.description,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: Colors.black,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
AssessmentIcon(
icon: assessment.imageUrl,
),
],
),
],
Text(
assessment.name,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w700,
color: AppTheme.primaryColor,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 8),
Text(
assessment.description,
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w500,
color: Colors.black,
),
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 16),
Align(
alignment: Alignment.centerRight,
child: AssessmentIcon(
icon: assessment.imageUrl,
),
),
],
Expand Down
28 changes: 22 additions & 6 deletions patient/lib/presentation/assessments/widgets/assessment_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,27 @@ class AssessmentIcon extends StatelessWidget {

@override
Widget build(BuildContext context) {
return Image.network(
icon,
width: 80,
height: 80,
fit: BoxFit.contain,
);
// Check if the icon is a network URL or an asset path
if (icon.startsWith('http')) {
return Image.network(
icon,
width: 80,
height: 80,
fit: BoxFit.contain,
errorBuilder: (context, error, stackTrace) {
return const Icon(Icons.error_outline, size: 80);
},
);
} else {
return Image.asset(
icon,
width: 80,
height: 80,
fit: BoxFit.contain,
errorBuilder: (context, error, stackTrace) {
return const Icon(Icons.error_outline, size: 80);
},
);
}
}
}
29 changes: 18 additions & 11 deletions patient/lib/provider/assessment_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,38 @@ class AssessmentProvider with ChangeNotifier {

String _selectedAssesssmentId = '';

AssessmentAnswerModel _assessmentAnswerModel = AssessmentAnswerModel(questions: [], assessmentId: '');
AssessmentAnswerModel _assessmentAnswerModel =
AssessmentAnswerModel(questions: [], assessmentId: '');
AssessmentAnswerModel? get assessmentAnswerModel => _assessmentAnswerModel;

ApiStatus _submitAssessmentStatus = ApiStatus.initial;
ApiStatus _submitAssessmentStatus = ApiStatus.initial;
ApiStatus get submitAssessmentStatus => _submitAssessmentStatus;

String? _errorMessage;
String? get errorMessage => _errorMessage;

AssessmentResultModel? _assessmentResultModel;
AssessmentResultModel? get assessmentResultModel => _assessmentResultModel;


set assessmentAnswers(AssessmentQuestionAnswerModel answers) {
final index = _assessmentAnswerModel.questions.indexWhere((element) => element.questionId == answers.questionId);
if(index != -1) {
set assessmentAnswers(AssessmentQuestionAnswerModel answers) {
final index = _assessmentAnswerModel.questions
.indexWhere((element) => element.questionId == answers.questionId);
if (index != -1) {
_assessmentAnswerModel.questions[index] = answers;
} else {
_assessmentAnswerModel.questions.add(answers);
}
notifyListeners();
}
}

String get selectedAssessmentId => _selectedAssesssmentId;
set selectedAssessmentId(String value) {
_selectedAssesssmentId = value;
_assessmentAnswerModel = _assessmentAnswerModel.copyWith(assessmentId: value, questions: []);
_assessmentAnswerModel =
_assessmentAnswerModel.copyWith(assessmentId: value, questions: []);
notifyListeners();
}


void fetchAllAssessments() async {
final result = await _repository.fetchAllAssessments();
if (result is ActionResultSuccess) {
Expand All @@ -54,15 +58,18 @@ class AssessmentProvider with ChangeNotifier {
//implement the submitAssessment method to submit the assessment when the submitted_assessment table is created
Future<void> submitAssessment() async {
_submitAssessmentStatus = ApiStatus.initial;
_errorMessage = null;
notifyListeners();
final result = await _repository.submitAssessment(_assessmentAnswerModel.toEntity());

final result =
await _repository.submitAssessment(_assessmentAnswerModel.toEntity());
if (result is ActionResultSuccess) {
_submitAssessmentStatus = ApiStatus.success;
_assessmentResultModel = result.data;
} else {
_submitAssessmentStatus = ApiStatus.failure;
_errorMessage = (result as ActionResultFailure).errorMessage;
}
notifyListeners();
}

}
Loading