feedback funtionality
This commit is contained in:
parent
822ad32902
commit
5036122bce
@ -76,23 +76,13 @@
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
import 'package:excel/excel.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
||||||
|
import 'package:pocketbase/pocketbase.dart';
|
||||||
|
import 'package:uae_stat/domain/use_cases/language.dart';
|
||||||
import 'package:uae_stat/presentation/components/my_drawer.dart';
|
import 'package:uae_stat/presentation/components/my_drawer.dart';
|
||||||
|
|
||||||
// class FeedbackPage extends StatelessWidget {
|
import '../../components/lang_toggle.dart';
|
||||||
// const FeedbackPage({super.key});
|
|
||||||
|
|
||||||
// @override
|
|
||||||
// Widget build(BuildContext context) {
|
|
||||||
// return const Scaffold(
|
|
||||||
// body: Center(
|
|
||||||
// child: Text('Feedback'),
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
class FeedbackForm extends StatefulWidget {
|
class FeedbackForm extends StatefulWidget {
|
||||||
const FeedbackForm({super.key});
|
const FeedbackForm({super.key});
|
||||||
@ -102,17 +92,45 @@ class FeedbackForm extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _FeedbackFormState extends State<FeedbackForm> {
|
class _FeedbackFormState extends State<FeedbackForm> {
|
||||||
|
final _pb =
|
||||||
|
PocketBase('http://127.0.0.1:8090'); // Initialize PocketBase client
|
||||||
|
|
||||||
|
final TextEditingController _feedbackController = TextEditingController();
|
||||||
|
|
||||||
double _easeOfUseRating = 0;
|
double _easeOfUseRating = 0;
|
||||||
double _qualityRating = 0;
|
double _qualityRating = 0;
|
||||||
double _designRating = 0;
|
double _designRating = 0;
|
||||||
double _redundancyRating = 0;
|
double _redundancyRating = 0;
|
||||||
|
int? _selectedEmojiIndex;
|
||||||
|
|
||||||
|
// Map of emoji labels and values for sending to PocketBase
|
||||||
|
final List<Map<String, dynamic>> _emojiOptions = [
|
||||||
|
{
|
||||||
|
"icon": Icons.sentiment_very_dissatisfied,
|
||||||
|
"label": "Terrible",
|
||||||
|
"value": 1
|
||||||
|
},
|
||||||
|
{"icon": Icons.sentiment_dissatisfied, "label": "Bad", "value": 2},
|
||||||
|
{"icon": Icons.sentiment_neutral, "label": "Okay", "value": 3},
|
||||||
|
{"icon": Icons.sentiment_satisfied, "label": "Good", "value": 4},
|
||||||
|
{"icon": Icons.sentiment_very_satisfied, "label": "Amazing", "value": 5},
|
||||||
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
drawer: const MyDrawer(),
|
drawer: const MyDrawer(),
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('Feedback Form'),
|
backgroundColor: const Color(0xFFf8f9ff),
|
||||||
|
title: Text(
|
||||||
|
context.translate('Feedback Form', 'نموذج الملاحظات'),
|
||||||
|
),
|
||||||
|
actions: const [
|
||||||
|
Align(
|
||||||
|
alignment: AlignmentDirectional.topEnd,
|
||||||
|
child: LangToggle(),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
body: Padding(
|
body: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
@ -120,60 +138,71 @@ class _FeedbackFormState extends State<FeedbackForm> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
const Text(
|
Text(
|
||||||
'Do you have a suggestion or had any problem? Let us know.',
|
context.translate(
|
||||||
style: TextStyle(fontSize: 18),
|
'Do you have a suggestion or had any problem? Let us know.',
|
||||||
|
'هل لديك اقتراح أو واجهت أي مشكلة؟ اسمحوا لنا أن نعرف.'),
|
||||||
|
style: const TextStyle(fontSize: 18),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
const Text(
|
Text(
|
||||||
'How was your experience with us today?',
|
context.translate('How was your experience with us today?',
|
||||||
style: TextStyle(fontSize: 16),
|
'كيف كانت تجربتك معنا اليوم؟'),
|
||||||
|
style: const TextStyle(fontSize: 16),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: [
|
children: List.generate(_emojiOptions.length, (index) {
|
||||||
_buildEmojiButton(
|
return _buildEmojiButton(
|
||||||
Icons.sentiment_very_dissatisfied,
|
icon: _emojiOptions[index]["icon"],
|
||||||
'Terrible',
|
label: _emojiOptions[index]["label"],
|
||||||
),
|
index: index,
|
||||||
_buildEmojiButton(Icons.sentiment_dissatisfied, 'Bad'),
|
);
|
||||||
_buildEmojiButton(Icons.sentiment_neutral, 'Okay'),
|
}),
|
||||||
_buildEmojiButton(Icons.sentiment_satisfied, 'Good'),
|
|
||||||
_buildEmojiButton(Icons.sentiment_very_satisfied, 'Amazing'),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 30),
|
const SizedBox(height: 30),
|
||||||
const Text(
|
Text(
|
||||||
'How good did we do in these aspects?',
|
context.translate('How good did we do in these aspects?',
|
||||||
style: TextStyle(fontSize: 16),
|
'ما مدى جودة ما قمنا به في هذه الجوانب؟'),
|
||||||
|
style: const TextStyle(fontSize: 16),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
_buildRatingRow('Ease of use', _easeOfUseRating, (rating) {
|
_buildRatingRow(
|
||||||
|
context.translate('Ease of use', 'سهولة الاستخدام'),
|
||||||
|
_easeOfUseRating, (rating) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_easeOfUseRating = rating;
|
_easeOfUseRating = rating;
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
_buildRatingRow('Quality', _qualityRating, (rating) {
|
_buildRatingRow(
|
||||||
|
context.translate('Quality', 'جودة'), _qualityRating,
|
||||||
|
(rating) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_qualityRating = rating;
|
_qualityRating = rating;
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
_buildRatingRow('Design', _designRating, (rating) {
|
_buildRatingRow(
|
||||||
|
context.translate('Design', 'تصميم'), _designRating,
|
||||||
|
(rating) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_designRating = rating;
|
_designRating = rating;
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
_buildRatingRow('Redundant', _redundancyRating, (rating) {
|
_buildRatingRow(
|
||||||
|
context.translate('Redundant', 'متكرر'), _redundancyRating,
|
||||||
|
(rating) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_redundancyRating = rating;
|
_redundancyRating = rating;
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
const TextField(
|
TextField(
|
||||||
|
controller: _feedbackController,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: 'Tell us how we can improve',
|
hintText: context.translate(
|
||||||
border: OutlineInputBorder(
|
'Tell us how we can improve', 'أخبرنا كيف يمكننا تحسين'),
|
||||||
|
border: const OutlineInputBorder(
|
||||||
borderSide: BorderSide(color: Colors.blueAccent)),
|
borderSide: BorderSide(color: Colors.blueAccent)),
|
||||||
),
|
),
|
||||||
maxLines: 5,
|
maxLines: 5,
|
||||||
@ -181,10 +210,10 @@ class _FeedbackFormState extends State<FeedbackForm> {
|
|||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
Center(
|
Center(
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: () {
|
onPressed: _submitFeedback,
|
||||||
// Handle the submit action
|
child: Text(
|
||||||
},
|
context.translate('Submit', 'يُقدِّم'),
|
||||||
child: const Text('Submit'),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -194,19 +223,30 @@ class _FeedbackFormState extends State<FeedbackForm> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildEmojiButton(IconData icon, String label) {
|
Widget _buildEmojiButton({
|
||||||
|
required IconData icon,
|
||||||
|
required String label,
|
||||||
|
required int index,
|
||||||
|
}) {
|
||||||
|
bool isSelected = _selectedEmojiIndex == index;
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: Icon(icon, size: 40),
|
icon: Icon(icon, size: 40),
|
||||||
color: Colors.amber,
|
color: isSelected ? Colors.green : Colors.amber,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// Handle the emoji rating
|
setState(() {
|
||||||
|
_selectedEmojiIndex = index;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
label,
|
label,
|
||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: isSelected ? Colors.green : Colors.black,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
@ -237,4 +277,54 @@ class _FeedbackFormState extends State<FeedbackForm> {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _submitFeedback() async {
|
||||||
|
if (_selectedEmojiIndex == null) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text("Please select your experience rating.")),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final feedbackData = {
|
||||||
|
"ease_of_use": _easeOfUseRating,
|
||||||
|
"quality": _qualityRating,
|
||||||
|
"design": _designRating,
|
||||||
|
"redundancy": _redundancyRating,
|
||||||
|
"emoji_rating": _emojiOptions[_selectedEmojiIndex!]
|
||||||
|
["label"], // Emoji rating
|
||||||
|
"feedback": _feedbackController.text,
|
||||||
|
};
|
||||||
|
// print(feedbackData);
|
||||||
|
// return;
|
||||||
|
try {
|
||||||
|
final adminAuth = await _pb.admins
|
||||||
|
.authWithPassword('surendar.m@venbainfotech.com', 'Venba@123456');
|
||||||
|
final adminToken = adminAuth.token;
|
||||||
|
await _pb
|
||||||
|
.collection('feedback')
|
||||||
|
.create(body: feedbackData, headers: {'Authorization': adminToken});
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text("Feedback submitted successfully!")),
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
_easeOfUseRating = 0;
|
||||||
|
_qualityRating = 0;
|
||||||
|
_designRating = 0;
|
||||||
|
_redundancyRating = 0;
|
||||||
|
_selectedEmojiIndex = null;
|
||||||
|
_feedbackController.clear();
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text("Failed to submit feedback: $e")),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_feedbackController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user