feat: integrate real AudioPlayer, real ImagePicker for Camera/Gallery, and on-the-fly OGG-to-MP3 converter on server
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import '../controllers/chat_controller.dart';
|
||||
import '../models/conversation_model.dart';
|
||||
import '../models/message_model.dart';
|
||||
@@ -232,19 +234,21 @@ class ChatScreen extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
_buildAttachmentItem(
|
||||
icon: Icons.photo,
|
||||
color: Colors.purple,
|
||||
label: 'Photo',
|
||||
icon: Icons.camera_alt,
|
||||
color: Colors.green,
|
||||
label: 'Camera',
|
||||
onTap: () {
|
||||
Get.back();
|
||||
// Real red dot 5x5 pixel PNG base64
|
||||
const base64Photo = 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
|
||||
ctrl.sendMediaMessage(
|
||||
base64Photo,
|
||||
'image/png',
|
||||
'photo.png',
|
||||
caption: '📸 Photo sent from Mywhatsapp App!',
|
||||
);
|
||||
_pickAndSendImage(ctrl, ImageSource.camera);
|
||||
},
|
||||
),
|
||||
_buildAttachmentItem(
|
||||
icon: Icons.photo_library,
|
||||
color: Colors.purple,
|
||||
label: 'Gallery',
|
||||
onTap: () {
|
||||
Get.back();
|
||||
_pickAndSendImage(ctrl, ImageSource.gallery);
|
||||
},
|
||||
),
|
||||
_buildAttachmentItem(
|
||||
@@ -272,6 +276,41 @@ class ChatScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
void _pickAndSendImage(ChatController ctrl, ImageSource source) async {
|
||||
try {
|
||||
final ImagePicker picker = ImagePicker();
|
||||
final XFile? image = await picker.pickImage(
|
||||
source: source,
|
||||
imageQuality: 75,
|
||||
);
|
||||
if (image == null) return;
|
||||
|
||||
final bytes = await image.readAsBytes();
|
||||
final base64String = base64Encode(bytes);
|
||||
|
||||
String mimetype = 'image/jpeg';
|
||||
if (image.path.toLowerCase().endsWith('.png')) {
|
||||
mimetype = 'image/png';
|
||||
} else if (image.path.toLowerCase().endsWith('.gif')) {
|
||||
mimetype = 'image/gif';
|
||||
}
|
||||
|
||||
await ctrl.sendMediaMessage(
|
||||
base64String,
|
||||
mimetype,
|
||||
image.name,
|
||||
caption: '📸 Photo sent via Mywhatsapp!',
|
||||
);
|
||||
} catch (e) {
|
||||
Get.snackbar(
|
||||
'Error picking image',
|
||||
e.toString(),
|
||||
backgroundColor: Colors.redAccent.withOpacity(0.8),
|
||||
colorText: Colors.white,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildAttachmentItem({
|
||||
required IconData icon,
|
||||
required Color color,
|
||||
|
||||
Reference in New Issue
Block a user