Update: 2026-06-14 05:48:58

This commit is contained in:
Hamza-Ayed
2026-06-14 05:48:58 +03:00
parent 2645ed0cf1
commit 8e3b9eca4d
22 changed files with 789 additions and 179 deletions

View File

@@ -6,6 +6,7 @@ import 'package:get/get.dart';
import 'package:siro_driver/constant/colors.dart';
import 'package:siro_driver/constant/style.dart';
import 'package:siro_driver/controller/functions/tts.dart';
import 'package:siro_driver/controller/functions/translate_helper.dart';
class DialogConfig {
static const Duration animationDuration = Duration(milliseconds: 200);
@@ -136,6 +137,158 @@ class MyDialog extends GetxController {
barrierColor: Colors.black.withAlpha(102), // 0.4 opacity
);
}
void getChatDialog(String title, String body, VoidCallback onPressed) {
final textToSpeechController = Get.put(TextToSpeechController());
HapticFeedback.mediumImpact();
String currentText = body;
bool isTranslated = false;
bool isLoading = false;
Get.dialog(
StatefulBuilder(
builder: (context, setState) {
final theme = Theme.of(context);
return TweenAnimationBuilder<double>(
duration: DialogConfig.animationDuration,
tween: Tween(begin: 0.0, end: 1.0),
builder: (context, value, child) {
return Transform.scale(
scale: 0.95 + (0.05 * value),
child: Opacity(opacity: value, child: child),
);
},
child: BackdropFilter(
filter: ImageFilter.blur(
sigmaX: DialogConfig.blurStrength,
sigmaY: DialogConfig.blurStrength,
),
child: Builder(builder: (context) {
return CupertinoAlertDialog(
title: Column(
children: [
Text(
title.tr,
style: AppStyle.title.copyWith(
fontSize: 20,
fontWeight: FontWeight.w700,
letterSpacing: -0.5,
color: AppColor.primaryColor,
),
),
const SizedBox(height: 8),
],
),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
CupertinoButton(
padding: const EdgeInsets.all(8),
onPressed: () async {
HapticFeedback.selectionClick();
await textToSpeechController.speakText(title);
await textToSpeechController.speakText(currentText);
},
child: Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color:
AppColor.primaryColor.withAlpha(26), // 0.1 opacity
borderRadius: BorderRadius.circular(8),
),
child: Icon(
CupertinoIcons.speaker_2_fill,
color: AppColor.primaryColor,
size: 24,
),
),
),
const SizedBox(height: 8),
if (isLoading)
const Center(
child: Padding(
padding: EdgeInsets.all(8.0),
child: CupertinoActivityIndicator(),
),
)
else
Text(
currentText,
style: AppStyle.title.copyWith(
fontSize: 16,
height: 1.3,
color: theme.textTheme.bodyLarge?.color ?? AppColor.writeColor,
),
textAlign: TextAlign.center,
),
],
),
actions: [
CupertinoDialogAction(
onPressed: () async {
if (isLoading) return;
HapticFeedback.lightImpact();
if (isTranslated) {
setState(() {
currentText = body;
isTranslated = false;
});
} else {
setState(() {
isLoading = true;
});
try {
final targetLang = Get.locale?.languageCode ?? 'ar';
final translated = await TranslateHelper.translateText(body, targetLang);
setState(() {
currentText = translated;
isTranslated = true;
isLoading = false;
});
} catch (e) {
setState(() {
isLoading = false;
});
}
}
},
child: Text(
isTranslated ? 'Original'.tr : 'Translate'.tr,
style: TextStyle(
color: AppColor.blueColor,
fontWeight: FontWeight.w600,
fontSize: 17,
),
),
),
CupertinoDialogAction(
onPressed: () {
HapticFeedback.mediumImpact();
Navigator.of(context, rootNavigator: true).pop();
onPressed();
},
child: Text(
'OK'.tr,
style: TextStyle(
color: AppColor.greenColor,
fontWeight: FontWeight.w600,
fontSize: 17,
),
),
),
],
);
}),
),
);
},
),
barrierDismissible: true,
barrierColor: Colors.black.withAlpha(102), // 0.4 opacity
);
}
}
class MyDialogContent extends GetxController {