11/9/1
This commit is contained in:
@@ -1,64 +1,199 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:SEFER/views/widgets/my_scafold.dart';
|
||||
import 'package:SEFER/views/widgets/mycircular.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
import '../../../controller/home/profile/complaint_controller.dart';
|
||||
import '../../widgets/elevated_btn.dart';
|
||||
import 'package:SEFER/constant/colors.dart';
|
||||
import 'package:SEFER/constant/style.dart';
|
||||
import 'package:SEFER/controller/functions/crud.dart';
|
||||
import 'package:SEFER/controller/home/profile/complaint_controller.dart';
|
||||
import 'package:SEFER/views/widgets/my_dialog.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'dart:io';
|
||||
|
||||
import '../../../controller/functions/audio_record1.dart';
|
||||
|
||||
class ComplaintPage extends StatelessWidget {
|
||||
// Rename class
|
||||
ComplaintPage({super.key});
|
||||
ComplaintController complaintController =
|
||||
Get.put(ComplaintController()); // Update controller instance
|
||||
final ComplaintController complaintController =
|
||||
Get.put(ComplaintController());
|
||||
final AudioRecorderController audioRecorderController =
|
||||
Get.put(AudioRecorderController());
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MyScafolld(
|
||||
title: 'Complaint'.tr,
|
||||
body: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(26),
|
||||
child: Form(
|
||||
key: complaintController.formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: complaintController.complaintController,
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
hintText: 'Enter your complaint here'.tr,
|
||||
labelText: 'Complaint'.tr, // Update label
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter your complaint.'.tr;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
complaintController.isLoading
|
||||
? const MyCircularProgressIndicator()
|
||||
: MyElevatedButton(
|
||||
onPressed: () {
|
||||
if (complaintController.formKey.currentState!
|
||||
.validate()) {
|
||||
complaintController
|
||||
.addComplaint(); // Update method name
|
||||
|
||||
// Clear the complaint form
|
||||
complaintController.formKey.currentState!.reset();
|
||||
}
|
||||
},
|
||||
title: 'Submit'.tr,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
return GetBuilder<ComplaintController>(builder: (complaintController) {
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text('Complaint'.tr, style: AppStyle.title),
|
||||
),
|
||||
],
|
||||
isleading: true,
|
||||
);
|
||||
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('SEFER 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),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user