12/22/2
This commit is contained in:
@@ -1,84 +1,142 @@
|
||||
import 'package:sefer_driver/views/widgets/elevated_btn.dart';
|
||||
import 'package:sefer_driver/views/widgets/my_textField.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../controller/rate/rate_app_controller.dart';
|
||||
|
||||
class RatingScreen extends StatelessWidget {
|
||||
// Initialize the RatingController using GetX for state management
|
||||
final RatingController ratingController = Get.put(RatingController());
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
// Display title "Rate Our App", with .tr for localization support
|
||||
title: Text("Rate Our App".tr),
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text(
|
||||
"Rate Our App".tr,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
body: Center(
|
||||
child: Obx(() {
|
||||
// Observe changes in userRating; when updated, rebuild the UI accordingly
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ListView(
|
||||
// mainAxisAlignment:
|
||||
// MainAxisAlignment.center, // Center content vertically
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
child: Image.asset('assets/images/logo.gif')),
|
||||
const SizedBox(height: 10),
|
||||
// Text prompt asking the user to rate the app, with localization support
|
||||
Text("How would you rate our app?".tr),
|
||||
const SizedBox(height: 10), // Vertical spacing between elements
|
||||
MyTextForm(
|
||||
controller: ratingController.comment,
|
||||
label: 'write comment here'.tr,
|
||||
hint: 'write comment here'.tr,
|
||||
type: TextInputType.name,
|
||||
),
|
||||
// Build and display the row of rating stars
|
||||
_buildRatingStars(),
|
||||
child: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
child: Center(
|
||||
child: Obx(() {
|
||||
return Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 20, vertical: 30),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
// App logo or visual
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Image.asset(
|
||||
'assets/images/logo.gif',
|
||||
height: 120,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
const SizedBox(
|
||||
height: 20), // Additional spacing before the button
|
||||
// Rating Prompt
|
||||
Text(
|
||||
"How would you rate our app?".tr,
|
||||
textAlign: TextAlign.center,
|
||||
style: CupertinoTheme.of(context)
|
||||
.textTheme
|
||||
.navTitleTextStyle
|
||||
.copyWith(fontSize: 18, fontWeight: FontWeight.w600),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Button to submit the selected rating
|
||||
MyElevatedButton(
|
||||
onPressed: () {
|
||||
// Calls submitRating() method in the controller with the current rating value
|
||||
ratingController
|
||||
.submitRating(ratingController.userRating.value);
|
||||
},
|
||||
// Button text "Submit Rating" with localization support
|
||||
title: "Submit Rating".tr,
|
||||
// Comment Box
|
||||
CupertinoTextField(
|
||||
controller: ratingController.comment,
|
||||
placeholder: 'Write your comment here'.tr,
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: CupertinoColors.systemGrey4),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: CupertinoColors.white,
|
||||
),
|
||||
prefix: Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: Icon(CupertinoIcons.pencil_ellipsis_rectangle,
|
||||
color: CupertinoColors.systemGrey),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Star Rating Section
|
||||
_buildRatingStars(),
|
||||
|
||||
const SizedBox(height: 30),
|
||||
|
||||
// Submit Button
|
||||
CupertinoButton(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24, vertical: 14),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: CupertinoColors.activeGreen,
|
||||
onPressed: () {
|
||||
if (ratingController.userRating.value > 0) {
|
||||
ratingController
|
||||
.submitRating(ratingController.userRating.value);
|
||||
Get.snackbar(
|
||||
"Thank You!".tr,
|
||||
"Your rating has been submitted.".tr,
|
||||
backgroundColor: CupertinoColors.systemGrey6,
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
margin: const EdgeInsets.all(16),
|
||||
borderRadius: 12,
|
||||
);
|
||||
} else {
|
||||
Get.snackbar(
|
||||
"Error".tr,
|
||||
"Please select a rating before submitting.".tr,
|
||||
backgroundColor: CupertinoColors.systemRed,
|
||||
snackPosition: SnackPosition.BOTTOM,
|
||||
margin: const EdgeInsets.all(16),
|
||||
borderRadius: 12,
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Text(
|
||||
"Submit Rating".tr,
|
||||
style: const TextStyle(
|
||||
color: CupertinoColors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Widget function to display a row of clickable star icons for rating
|
||||
// Widget for building rating stars with animations
|
||||
Widget _buildRatingStars() {
|
||||
return Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center, // Center-aligns stars horizontally
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(5, (index) {
|
||||
return IconButton(
|
||||
// Display a star icon, filled if selected, otherwise grey
|
||||
icon: Icon(
|
||||
Icons.star,
|
||||
color: index < ratingController.userRating.value
|
||||
? Colors.orange // Orange for selected stars
|
||||
: Colors.grey, // Grey for unselected stars
|
||||
),
|
||||
onPressed: () {
|
||||
// Update user rating in the controller when a star is clicked
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
ratingController.userRating.value = index + 1;
|
||||
},
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: Icon(
|
||||
CupertinoIcons.star_fill,
|
||||
size: 40,
|
||||
color: index < ratingController.userRating.value
|
||||
? CupertinoColors.systemYellow
|
||||
: CupertinoColors.systemGrey3,
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user