199 lines
9.6 KiB
Dart
199 lines
9.6 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:Tripz/constant/colors.dart';
|
|
import 'package:Tripz/constant/style.dart';
|
|
import 'package:Tripz/controller/home/profile/complaint_controller.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:get/get.dart';
|
|
import 'dart:io';
|
|
|
|
import '../../../controller/functions/audio_record1.dart';
|
|
import '../../widgets/mydialoug.dart';
|
|
|
|
class ComplaintPage extends StatelessWidget {
|
|
final ComplaintController complaintController =
|
|
Get.put(ComplaintController());
|
|
final AudioRecorderController audioRecorderController =
|
|
Get.put(AudioRecorderController());
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GetBuilder<ComplaintController>(builder: (complaintController) {
|
|
return CupertinoPageScaffold(
|
|
navigationBar: CupertinoNavigationBar(
|
|
middle: Text('Complaint'.tr, style: AppStyle.title),
|
|
),
|
|
child: complaintController.isLoading
|
|
? const Center(child: CupertinoActivityIndicator())
|
|
: SafeArea(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Form(
|
|
key: complaintController.formKey,
|
|
child: ListView(
|
|
children: [
|
|
// Complaint Text Field
|
|
CupertinoFormSection(
|
|
header: Text('Submit Your Complaint'.tr),
|
|
children: [
|
|
CupertinoTextField(
|
|
controller:
|
|
complaintController.complaintController,
|
|
placeholder: 'Enter your complaint here'.tr,
|
|
padding: const EdgeInsets.symmetric(
|
|
vertical: 12, horizontal: 16),
|
|
maxLines: 5,
|
|
decoration: BoxDecoration(
|
|
border: Border.all(
|
|
color: CupertinoColors.systemGrey4),
|
|
borderRadius: BorderRadius.circular(10),
|
|
color: CupertinoColors.white,
|
|
),
|
|
style: AppStyle.subtitle,
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 24),
|
|
|
|
// FutureBuilder to load recorded audio files
|
|
FutureBuilder<List<String>>(
|
|
future: audioRecorderController.getRecordedFiles(),
|
|
builder: (context, snapshot) {
|
|
if (snapshot.connectionState ==
|
|
ConnectionState.waiting) {
|
|
return const Center(
|
|
child: CupertinoActivityIndicator());
|
|
} else if (snapshot.hasError) {
|
|
return Text('Error: ${snapshot.error}',
|
|
style: AppStyle.subtitle);
|
|
} else if (snapshot.hasData &&
|
|
snapshot.data!.isEmpty) {
|
|
return Text('No audio files recorded.'.tr,
|
|
style: AppStyle.subtitle);
|
|
}
|
|
|
|
// List of recorded audio files
|
|
return CupertinoFormSection(
|
|
header: Text('attach audio of complain'.tr),
|
|
children: snapshot.data!.map((audioFilePath) {
|
|
final audioFile = File(audioFilePath);
|
|
return CupertinoListTile(
|
|
title: Text(audioFilePath.split('/').last,
|
|
style: AppStyle.title),
|
|
trailing: const Icon(
|
|
CupertinoIcons.play_arrow,
|
|
color: AppColor.accentColor),
|
|
onTap: () async {
|
|
MyDialogContent().getDialog(
|
|
'be sure'.tr,
|
|
Text('attach correct audio'.tr),
|
|
() async {
|
|
await complaintController
|
|
.uploadAudioFile(audioFile);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}).toList(),
|
|
);
|
|
},
|
|
),
|
|
const SizedBox(height: 24),
|
|
|
|
// Trip Details Section
|
|
CupertinoFormSection(
|
|
header: Text('Trip Details'.tr),
|
|
children: [
|
|
CupertinoListTile(
|
|
title: complaintController.feedBack.isEmpty
|
|
? Text('No Ride found yet'.tr)
|
|
: Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
'${'Date'.tr}: ${complaintController.feedBack[0]['date']}',
|
|
style: AppStyle.title),
|
|
Text(
|
|
'${'Price'.tr}: ${complaintController.feedBack[0]['price']}',
|
|
style: AppStyle.title),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 24),
|
|
CupertinoFormSection(
|
|
header: Text('Tripz answer'.tr),
|
|
children: [
|
|
SizedBox(
|
|
height: 100,
|
|
child: ListView(
|
|
children: [
|
|
// Check if passengerReport is not null
|
|
if (complaintController.passengerReport !=
|
|
null)
|
|
// Access the 'solution' key safely
|
|
Text(
|
|
complaintController
|
|
.passengerReport!['solution']
|
|
?.toString() ??
|
|
'No solution available',
|
|
style: AppStyle.title,
|
|
)
|
|
else
|
|
const SizedBox(), // Fallback if passengerReport is null
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 24),
|
|
// Submit Button
|
|
CupertinoButton(
|
|
color: AppColor.blueColor,
|
|
padding: const EdgeInsets.symmetric(
|
|
vertical: 14, horizontal: 30),
|
|
onPressed: () async {
|
|
if (complaintController.formKey.currentState!
|
|
.validate()) {
|
|
if (complaintController.audioLink.toString() ==
|
|
'') {
|
|
MyDialogContent().getDialog(
|
|
'title',
|
|
Text(
|
|
'the audio file not uploaded yet \nDo you want to upload without audio file'
|
|
.tr), () async {
|
|
await complaintController.geminiAudio(
|
|
jsonEncode(complaintController.feedBack),
|
|
complaintController.audioLink,
|
|
complaintController
|
|
.complaintController.text);
|
|
complaintController.formKey.currentState!
|
|
.reset();
|
|
});
|
|
Get.back();
|
|
} else {
|
|
await complaintController.geminiAudio(
|
|
jsonEncode(complaintController.feedBack),
|
|
complaintController.audioLink,
|
|
complaintController
|
|
.complaintController.text);
|
|
complaintController.formKey.currentState!
|
|
.reset();
|
|
}
|
|
complaintController.addComplaint();
|
|
}
|
|
},
|
|
child: Text('Submit'.tr, style: AppStyle.title),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
}
|