not fix but good
This commit is contained in:
parent
34b9d46d71
commit
f72228b339
|
|
@ -0,0 +1,21 @@
|
||||||
|
|
||||||
|
const init = () => {
|
||||||
|
console.log('js is connected!');
|
||||||
|
|
||||||
|
const showAlert = (message) => {
|
||||||
|
alert(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
const reqFullScreen = () => {
|
||||||
|
document.documentElement.requestFullscreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
window._showAlert = showAlert;
|
||||||
|
window._reqFullScreen = reqFullScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
window.onload = () => {
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// ignore_for_file: depend_on_referenced_packages
|
// ignore_for_file: depend_on_referenced_packages, avoid_web_libraries_in_flutter
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
@ -8,9 +8,6 @@ import 'package:didvan/services/storage/storage.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:http_parser/http_parser.dart';
|
import 'package:http_parser/http_parser.dart';
|
||||||
import 'package:mime/mime.dart';
|
|
||||||
import 'package:path/path.dart' as p;
|
|
||||||
import 'package:http_parser/http_parser.dart' as parser;
|
|
||||||
|
|
||||||
class AiApiService {
|
class AiApiService {
|
||||||
static const String baseUrl = 'https://api.didvan.app/ai';
|
static const String baseUrl = 'https://api.didvan.app/ai';
|
||||||
|
|
@ -45,9 +42,20 @@ class AiApiService {
|
||||||
if (file.bytes != null) {
|
if (file.bytes != null) {
|
||||||
bytes = file.bytes!;
|
bytes = file.bytes!;
|
||||||
} else {
|
} else {
|
||||||
final Uri audioUri = Uri.parse(file.path);
|
final Uri audioUri = Uri.parse(file.path.replaceAll('%3A', ':'));
|
||||||
final http.Response audioResponse = await http.get(audioUri);
|
final http.Response audioResponse = await http.get(audioUri);
|
||||||
bytes = audioResponse.bodyBytes;
|
bytes = audioResponse.bodyBytes;
|
||||||
|
|
||||||
|
// Fetch the blob using JavaScript interop
|
||||||
|
// final blob = await html.window
|
||||||
|
// .fetch(file.path.replaceAll('%3A', ':'))
|
||||||
|
// .then((response) => response.blob());
|
||||||
|
|
||||||
|
// // Read the blob as an array buffer
|
||||||
|
// final reader = html.FileReader();
|
||||||
|
// reader.readAsArrayBuffer(blob);
|
||||||
|
// await reader.onLoadEnd.first;
|
||||||
|
// bytes = reader.result as Uint8List;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// For other platforms
|
// For other platforms
|
||||||
|
|
@ -75,8 +83,7 @@ class AiApiService {
|
||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<Stream<List<int>>> getResponse(
|
Future<Stream<List<int>>> getResponse(http.MultipartRequest req) async {
|
||||||
http.MultipartRequest req) async {
|
|
||||||
try {
|
try {
|
||||||
final response = await http.Client().send(req);
|
final response = await http.Client().send(req);
|
||||||
if (response.statusCode == 400) {
|
if (response.statusCode == 400) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
@JS()
|
||||||
|
library js_introp;
|
||||||
|
|
||||||
|
import 'package:js/js.dart';
|
||||||
|
|
||||||
|
@JS()
|
||||||
|
external _showAlert(String message);
|
||||||
|
|
||||||
|
@JS()
|
||||||
|
external _reqFullScreen();
|
||||||
|
|
||||||
|
class JsInteropService {
|
||||||
|
showAlert() {
|
||||||
|
_showAlert(
|
||||||
|
'Helooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo MF');
|
||||||
|
}
|
||||||
|
|
||||||
|
fullScreen() {
|
||||||
|
_reqFullScreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -22,28 +22,6 @@ class MediaService {
|
||||||
|
|
||||||
static Duration? get duration => audioPlayer.duration;
|
static Duration? get duration => audioPlayer.duration;
|
||||||
|
|
||||||
static Future<Duration?> getDuration({required String src}) async {
|
|
||||||
final ap = AudioPlayer();
|
|
||||||
Duration? duration;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (src.startsWith('/uploads')) {
|
|
||||||
duration = await ap.setUrl(
|
|
||||||
'${RequestHelper.baseUrl + src}?accessToken=${RequestService.token}');
|
|
||||||
} else if (src.startsWith('blob:')) {
|
|
||||||
duration = await ap.setAudioSource(AudioSource.uri(Uri.parse(src)));
|
|
||||||
} else {
|
|
||||||
duration = await ap.setFilePath(src);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
print('Error setting audio source: $e');
|
|
||||||
} finally {
|
|
||||||
await ap.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
return duration;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> handleAudioPlayback({
|
static Future<void> handleAudioPlayback({
|
||||||
required dynamic audioSource,
|
required dynamic audioSource,
|
||||||
required int id,
|
required int id,
|
||||||
|
|
@ -56,13 +34,13 @@ class MediaService {
|
||||||
String tag;
|
String tag;
|
||||||
tag =
|
tag =
|
||||||
'${currentPodcast?.description == 'radar' ? 'radar' : isVoiceMessage ? 'message' : 'podcast'}-$id';
|
'${currentPodcast?.description == 'radar' ? 'radar' : isVoiceMessage ? 'message' : 'podcast'}-$id';
|
||||||
|
print("tag: $tag");
|
||||||
if (!isVoiceMessage && MediaProvider.downloadedItemIds.contains(id)) {
|
if (!isVoiceMessage && MediaProvider.downloadedItemIds.contains(id)) {
|
||||||
audioSource = '${StorageService.appDocsDir}/podcasts/podcast-$id.mp3';
|
audioSource = '${StorageService.appDocsDir}/podcasts/podcast-$id.mp3';
|
||||||
isNetworkAudio = false;
|
isNetworkAudio = false;
|
||||||
}
|
}
|
||||||
if (audioPlayerTag == tag) {
|
if (audioPlayerTag == tag) {
|
||||||
if (audioPlayer.playerState ==
|
if (audioPlayer.playing) {
|
||||||
PlayerState(true, ProcessingState.ready)) {
|
|
||||||
await audioPlayer.pause();
|
await audioPlayer.pause();
|
||||||
} else {
|
} else {
|
||||||
await audioPlayer.play();
|
await audioPlayer.play();
|
||||||
|
|
@ -70,7 +48,7 @@ class MediaService {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// await audioPlayer.stop();
|
await audioPlayer.stop();
|
||||||
audioPlayerTag = tag;
|
audioPlayerTag = tag;
|
||||||
String source;
|
String source;
|
||||||
if (isNetworkAudio) {
|
if (isNetworkAudio) {
|
||||||
|
|
|
||||||
|
|
@ -1,64 +1,100 @@
|
||||||
|
import 'package:didvan/services/media/media.dart';
|
||||||
import 'package:didvan/services/network/request.dart';
|
import 'package:didvan/services/network/request.dart';
|
||||||
import 'package:didvan/services/network/request_helper.dart';
|
import 'package:didvan/services/network/request_helper.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:just_audio/just_audio.dart';
|
import 'package:just_audio/just_audio.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:universal_html/html.dart' as html;
|
||||||
|
|
||||||
class VoiceService {
|
class VoiceService {
|
||||||
static final audioPlayer = AudioPlayer();
|
static final audioPlayer = AudioPlayer();
|
||||||
static int? index;
|
static String? src;
|
||||||
static ConcatenatingAudioSource? _playlist;
|
|
||||||
|
|
||||||
VoiceService({required final List<AudioSource> audios}) {
|
|
||||||
_playlist = ConcatenatingAudioSource(
|
|
||||||
// Start loading next item just before reaching it
|
|
||||||
useLazyPreparation: true,
|
|
||||||
// Customise the shuffle algorithm
|
|
||||||
shuffleOrder: DefaultShuffleOrder(),
|
|
||||||
// Specify the playlist items
|
|
||||||
children: audios,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Future<Duration?> getDuration({
|
static Future<Duration?> getDuration({
|
||||||
required String src,
|
required String src,
|
||||||
}) async {
|
}) async {
|
||||||
|
final ap = AudioPlayer();
|
||||||
|
Duration? duration;
|
||||||
|
try {
|
||||||
if (src.startsWith('/uploads')) {
|
if (src.startsWith('/uploads')) {
|
||||||
return await audioPlayer.setUrl(
|
final source =
|
||||||
'${RequestHelper.baseUrl + src}?accessToken=${RequestService.token}');
|
'${RequestHelper.baseUrl + src}?accessToken=${RequestService.token}';
|
||||||
} else if (src.startsWith('blob:')) {
|
if (kIsWeb) {
|
||||||
return await audioPlayer.setAudioSource(AudioSource.uri(Uri.parse(src)));
|
final response =
|
||||||
|
await http.get(Uri.parse(source.replaceAll('%3A', ':')));
|
||||||
|
final bytes = response.bodyBytes;
|
||||||
|
final blob = html.Blob([bytes]);
|
||||||
|
final blobUrl = html.Url.createObjectUrlFromBlob(blob);
|
||||||
|
duration = await ap.setAudioSource(
|
||||||
|
AudioSource.uri(Uri.parse(blobUrl)),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return await audioPlayer.setFilePath(src);
|
final lockCachingAudioSource =
|
||||||
|
LockCachingAudioSource(Uri.parse(source));
|
||||||
|
|
||||||
|
duration = await ap.setAudioSource(lockCachingAudioSource);
|
||||||
}
|
}
|
||||||
|
} else if (src.startsWith('blob:')) {
|
||||||
|
duration = await ap.setAudioSource(AudioSource.uri(Uri.parse(src)));
|
||||||
|
} else {
|
||||||
|
duration = await ap.setFilePath(src);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (kDebugMode) {
|
||||||
|
print('Error setting audio source: $e');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
await ap.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<bool> voiceHelper({required int index}) async {
|
await ap.load();
|
||||||
|
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> voiceHelper({required String src}) async {
|
||||||
try {
|
try {
|
||||||
if (VoiceService.index == index) {
|
if (VoiceService.src == src) {
|
||||||
if (audioPlayer.playerState ==
|
if (audioPlayer.playing) {
|
||||||
PlayerState(true, ProcessingState.ready)) {
|
|
||||||
await audioPlayer.pause();
|
await audioPlayer.pause();
|
||||||
} else {
|
} else {
|
||||||
await audioPlayer.play();
|
await audioPlayer.play();
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
return true;
|
}
|
||||||
|
audioPlayer.stop();
|
||||||
|
VoiceService.src = src;
|
||||||
|
if (src.startsWith('/uploads')) {
|
||||||
|
final source =
|
||||||
|
'${RequestHelper.baseUrl + src}?accessToken=${RequestService.token}';
|
||||||
|
if (kIsWeb) {
|
||||||
|
final response =
|
||||||
|
await http.get(Uri.parse(source.replaceAll('%3A', ':')));
|
||||||
|
final bytes = response.bodyBytes;
|
||||||
|
final blob = html.Blob([bytes]);
|
||||||
|
final blobUrl = html.Url.createObjectUrlFromBlob(blob);
|
||||||
|
await audioPlayer.setAudioSource(
|
||||||
|
AudioSource.uri(Uri.parse(blobUrl)),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
final lockCachingAudioSource =
|
||||||
|
LockCachingAudioSource(Uri.parse(source));
|
||||||
|
|
||||||
|
await audioPlayer.setAudioSource(lockCachingAudioSource);
|
||||||
|
}
|
||||||
|
} else if (src.startsWith('blob:')) {
|
||||||
|
await audioPlayer.setAudioSource(AudioSource.uri(Uri.parse(src)));
|
||||||
|
} else {
|
||||||
|
await audioPlayer.setFilePath(src);
|
||||||
}
|
}
|
||||||
VoiceService.index = index;
|
|
||||||
await audioPlayer.setAudioSource(_playlist!,
|
|
||||||
initialIndex: index, initialPosition: Duration.zero);
|
|
||||||
await audioPlayer
|
|
||||||
.setLoopMode(LoopMode.off); // Set playlist to loop (off|all|one)
|
|
||||||
await audioPlayer.play();
|
await audioPlayer.play();
|
||||||
return true;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
resetVoicePlayer();
|
resetVoicePlayer();
|
||||||
// rethrow;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> resetVoicePlayer() async {
|
static Future<void> resetVoicePlayer() async {
|
||||||
index = null;
|
src = null;
|
||||||
|
|
||||||
await audioPlayer.stop();
|
await audioPlayer.stop();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,11 +47,11 @@ class RequestService {
|
||||||
if (body != null) _requestBody = body;
|
if (body != null) _requestBody = body;
|
||||||
if (requestHeaders != null) _headers.addAll(requestHeaders);
|
if (requestHeaders != null) _headers.addAll(requestHeaders);
|
||||||
if (useAutherization) _headers.addAll({'Authorization': 'Bearer $token'});
|
if (useAutherization) _headers.addAll({'Authorization': 'Bearer $token'});
|
||||||
if (kDebugMode) {
|
// if (kDebugMode) {
|
||||||
try {
|
// try {
|
||||||
print('Authorization : Bearer $token');
|
// print('Authorization : Bearer $token');
|
||||||
} catch (e) {}
|
// } catch (e) {}
|
||||||
}
|
// }
|
||||||
if (body != null) _requestBody = body;
|
if (body != null) _requestBody = body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
// ignore_for_file: library_private_types_in_public_api, deprecated_member_use, depend_on_referenced_packages
|
// ignore_for_file: library_private_types_in_public_api, deprecated_member_use, depend_on_referenced_packages
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:didvan/config/design_config.dart';
|
import 'package:didvan/config/design_config.dart';
|
||||||
import 'package:didvan/config/theme_data.dart';
|
import 'package:didvan/config/theme_data.dart';
|
||||||
|
|
@ -23,7 +21,6 @@ import 'package:didvan/views/widgets/didvan/icon_button.dart';
|
||||||
import 'package:didvan/views/widgets/didvan/text.dart';
|
import 'package:didvan/views/widgets/didvan/text.dart';
|
||||||
import 'package:didvan/views/widgets/marquee_text.dart';
|
import 'package:didvan/views/widgets/marquee_text.dart';
|
||||||
import 'package:didvan/views/widgets/skeleton_image.dart';
|
import 'package:didvan/views/widgets/skeleton_image.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
@ -49,7 +46,7 @@ class _AiChatPageState extends State<AiChatPage> {
|
||||||
state.chatId = widget.args.chat!.id!;
|
state.chatId = widget.args.chat!.id!;
|
||||||
state.chat = widget.args.chat;
|
state.chat = widget.args.chat;
|
||||||
}
|
}
|
||||||
|
// JsInteropService().showAlert();
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||||
if (state.chatId != null) {
|
if (state.chatId != null) {
|
||||||
state.getAllMessages(state.chatId!).then((value) => Future.delayed(
|
state.getAllMessages(state.chatId!).then((value) => Future.delayed(
|
||||||
|
|
|
||||||
|
|
@ -147,13 +147,19 @@ class AiChatState extends CoreProvier {
|
||||||
.toIso8601String()));
|
.toIso8601String()));
|
||||||
update();
|
update();
|
||||||
await _scrolledEnd();
|
await _scrolledEnd();
|
||||||
|
// if (file != null) {
|
||||||
|
// html.AnchorElement anchorElement = html.AnchorElement(href: file!.path);
|
||||||
|
// anchorElement.download = '${file!.path}.m4a';
|
||||||
|
// anchorElement.click();
|
||||||
|
// }
|
||||||
|
|
||||||
final req = await AiApiService.initial(
|
final req = await AiApiService.initial(
|
||||||
url: '/${bot.id}/${bot.name}'.toLowerCase(),
|
url: '/${bot.id}/${bot.name}'.toLowerCase(),
|
||||||
message: message,
|
message: message,
|
||||||
chatId: chatId,
|
chatId: chatId,
|
||||||
file: file,
|
file: file,
|
||||||
edite: isEdite);
|
edite: isEdite);
|
||||||
final res = await AiApiService.getResponse(req).catchError((e) {
|
final res = await AiApiService().getResponse(req).catchError((e) {
|
||||||
_onError(e);
|
_onError(e);
|
||||||
// return e;
|
// return e;
|
||||||
});
|
});
|
||||||
|
|
@ -189,7 +195,7 @@ class AiChatState extends CoreProvier {
|
||||||
}
|
}
|
||||||
messageOnstream.value = Stream.value(responseMessgae);
|
messageOnstream.value = Stream.value(responseMessgae);
|
||||||
|
|
||||||
// update();
|
update();
|
||||||
});
|
});
|
||||||
|
|
||||||
r.onDone(() async {
|
r.onDone(() async {
|
||||||
|
|
|
||||||
|
|
@ -7,17 +7,11 @@ import 'package:didvan/config/design_config.dart';
|
||||||
import 'package:didvan/config/theme_data.dart';
|
import 'package:didvan/config/theme_data.dart';
|
||||||
import 'package:didvan/constants/app_icons.dart';
|
import 'package:didvan/constants/app_icons.dart';
|
||||||
import 'package:didvan/services/media/media.dart';
|
import 'package:didvan/services/media/media.dart';
|
||||||
import 'package:didvan/services/network/request.dart';
|
import 'package:didvan/services/media/voice.dart';
|
||||||
import 'package:didvan/services/network/request_helper.dart';
|
|
||||||
import 'package:didvan/utils/date_time.dart';
|
|
||||||
import 'package:didvan/views/ai/widgets/message_bar_btn.dart';
|
import 'package:didvan/views/ai/widgets/message_bar_btn.dart';
|
||||||
import 'package:didvan/views/direct/widgets/message.dart';
|
|
||||||
import 'package:didvan/views/widgets/audio/audio_slider.dart';
|
|
||||||
import 'package:didvan/views/widgets/didvan/text.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||||
import 'package:get/get.dart';
|
|
||||||
import 'package:just_audio/just_audio.dart';
|
import 'package:just_audio/just_audio.dart';
|
||||||
|
|
||||||
class AudioWave extends StatefulWidget {
|
class AudioWave extends StatefulWidget {
|
||||||
|
|
@ -41,10 +35,12 @@ class _AudioWaveState extends State<AudioWave> {
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||||
await MediaService.getDuration(src: widget.file).then((duration) {
|
await VoiceService.getDuration(src: widget.file).then((duration) {
|
||||||
setState(() {
|
setState(() {
|
||||||
totalDuration = duration;
|
totalDuration = duration;
|
||||||
|
if (kDebugMode) {
|
||||||
print(totalDuration!.inSeconds);
|
print(totalDuration!.inSeconds);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -53,7 +49,7 @@ class _AudioWaveState extends State<AudioWave> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
MediaService.resetAudioPlayer();
|
VoiceService.resetVoicePlayer();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,45 +64,50 @@ class _AudioWaveState extends State<AudioWave> {
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
StreamBuilder<PlayerState>(
|
StreamBuilder<PlayerState>(
|
||||||
stream: MediaService.audioPlayer.playerStateStream,
|
stream: VoiceService.audioPlayer.playerStateStream,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (!snapshot.hasData) {
|
if (!snapshot.hasData) {
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
}
|
}
|
||||||
// if (snapshot.data!.processingState ==
|
if (snapshot.data!.processingState ==
|
||||||
// ProcessingState.completed) {
|
ProcessingState.completed) {
|
||||||
// MediaService.audioPlayer.pause();
|
VoiceService.audioPlayer.pause();
|
||||||
// MediaService.audioPlayer.seek(Duration.zero);
|
VoiceService.audioPlayer.seek(Duration.zero);
|
||||||
// }
|
}
|
||||||
print(snapshot.data);
|
print(snapshot.data);
|
||||||
|
if ((snapshot.data!.processingState ==
|
||||||
|
ProcessingState.loading ||
|
||||||
|
snapshot.data!.processingState ==
|
||||||
|
ProcessingState.buffering) &&
|
||||||
|
VoiceService.src == widget.file) {
|
||||||
|
return MessageBarBtn(
|
||||||
|
enable: true,
|
||||||
|
icon: DidvanIcons.close_regular,
|
||||||
|
click: () async {
|
||||||
|
await VoiceService.resetVoicePlayer();
|
||||||
|
},
|
||||||
|
loading: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
return MessageBarBtn(
|
return MessageBarBtn(
|
||||||
enable: true,
|
enable: true,
|
||||||
icon: snapshot.data!.playing &&
|
icon: snapshot.data!.playing &&
|
||||||
snapshot.data!.processingState !=
|
VoiceService.src == widget.file
|
||||||
ProcessingState.completed &&
|
|
||||||
MediaService.audioPlayerTag == 'message-$id'
|
|
||||||
? DidvanIcons.pause_solid
|
? DidvanIcons.pause_solid
|
||||||
: DidvanIcons.play_solid,
|
: DidvanIcons.play_solid,
|
||||||
click: () async {
|
click: () async {
|
||||||
await MediaService.handleAudioPlayback(
|
await VoiceService.voiceHelper(src: widget.file);
|
||||||
audioSource: widget.file,
|
|
||||||
id: id,
|
|
||||||
isNetworkAudio: widget.file.startsWith('/uploads'),
|
|
||||||
isVoiceMessage: true,
|
|
||||||
isBlob: widget.file.startsWith('blob:'));
|
|
||||||
MediaService.audioPlayerTag = 'message-$id';
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
StreamBuilder<Duration>(
|
Expanded(
|
||||||
stream: MediaService.audioPlayer.positionStream,
|
child: StreamBuilder<Duration>(
|
||||||
|
stream: VoiceService.audioPlayer.positionStream,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (!snapshot.hasData) {
|
if (!snapshot.hasData) {
|
||||||
return const SizedBox();
|
return const SizedBox();
|
||||||
}
|
}
|
||||||
print("Position: ${snapshot.data}");
|
return totalDuration == null
|
||||||
return Expanded(
|
|
||||||
child: totalDuration == null
|
|
||||||
? Padding(
|
? Padding(
|
||||||
padding: EdgeInsets.symmetric(
|
padding: EdgeInsets.symmetric(
|
||||||
vertical: widget.loadingPaddingSize),
|
vertical: widget.loadingPaddingSize),
|
||||||
|
|
@ -123,28 +124,19 @@ class _AudioWaveState extends State<AudioWave> {
|
||||||
itemCount: 10,
|
itemCount: 10,
|
||||||
))),
|
))),
|
||||||
)
|
)
|
||||||
: Row(
|
: Padding(
|
||||||
children: [
|
padding: const EdgeInsets.fromLTRB(24, 12, 12, 0),
|
||||||
Expanded(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 12.0),
|
|
||||||
child: Expanded(
|
|
||||||
child: ProgressBar(
|
child: ProgressBar(
|
||||||
thumbColor:
|
thumbColor: Theme.of(context).colorScheme.title,
|
||||||
Theme.of(context).colorScheme.title,
|
|
||||||
progressBarColor: DesignConfig.isDark
|
progressBarColor: DesignConfig.isDark
|
||||||
? Theme.of(context).colorScheme.title
|
? Theme.of(context).colorScheme.title
|
||||||
: Theme.of(context)
|
: Theme.of(context).colorScheme.primary,
|
||||||
.colorScheme
|
|
||||||
.primary,
|
|
||||||
baseBarColor:
|
baseBarColor:
|
||||||
Theme.of(context).colorScheme.border,
|
Theme.of(context).colorScheme.border,
|
||||||
bufferedBarColor:
|
bufferedBarColor:
|
||||||
Theme.of(context).colorScheme.splash,
|
Theme.of(context).colorScheme.splash,
|
||||||
total: totalDuration!,
|
total: totalDuration!,
|
||||||
progress: MediaService.audioPlayerTag ==
|
progress: VoiceService.src == widget.file
|
||||||
'message-$id'
|
|
||||||
? snapshot.data ?? Duration.zero
|
? snapshot.data ?? Duration.zero
|
||||||
: Duration.zero,
|
: Duration.zero,
|
||||||
thumbRadius: 6,
|
thumbRadius: 6,
|
||||||
|
|
@ -161,24 +153,15 @@ class _AudioWaveState extends State<AudioWave> {
|
||||||
// ),
|
// ),
|
||||||
// ),
|
// ),
|
||||||
onSeek: (value) {
|
onSeek: (value) {
|
||||||
if (MediaService.audioPlayerTag ==
|
if (VoiceService.src == widget.file) {
|
||||||
'message-$id') {
|
VoiceService.audioPlayer.seek(Duration(
|
||||||
MediaService.audioPlayer.seek(
|
milliseconds: value.inMilliseconds));
|
||||||
Duration(
|
|
||||||
milliseconds:
|
|
||||||
value.inMilliseconds));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
DidvanText(DateTimeUtils.normalizeTimeDuration(
|
|
||||||
snapshot.data ?? Duration.zero)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,21 @@
|
||||||
import 'package:didvan/config/theme_data.dart';
|
import 'package:didvan/config/theme_data.dart';
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||||
|
|
||||||
class MessageBarBtn extends StatelessWidget {
|
class MessageBarBtn extends StatelessWidget {
|
||||||
final bool enable;
|
final bool enable;
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
final Function()? click;
|
final Function()? click;
|
||||||
final Color? color;
|
final Color? color;
|
||||||
|
final bool loading;
|
||||||
const MessageBarBtn(
|
const MessageBarBtn(
|
||||||
{Key? key,
|
{Key? key,
|
||||||
required this.enable,
|
required this.enable,
|
||||||
required this.icon,
|
required this.icon,
|
||||||
this.click,
|
this.click,
|
||||||
this.color})
|
this.color,
|
||||||
|
this.loading = false})
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -26,12 +30,27 @@ class MessageBarBtn extends StatelessWidget {
|
||||||
: Theme.of(context).colorScheme.border),
|
: Theme.of(context).colorScheme.border),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: click,
|
onTap: click,
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
Positioned.fill(
|
||||||
child: Icon(
|
child: Icon(
|
||||||
icon,
|
icon,
|
||||||
size: 18,
|
size: 18,
|
||||||
color: enable ? Theme.of(context).colorScheme.white : null,
|
color: enable ? Theme.of(context).colorScheme.white : null,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (loading)
|
||||||
|
const Positioned.fill(
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.all(8.0),
|
||||||
|
child: SpinKitCircle(
|
||||||
|
size: 24,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import 'package:didvan/services/network/request.dart';
|
||||||
import 'package:didvan/services/network/request_helper.dart';
|
import 'package:didvan/services/network/request_helper.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter_vibrate/flutter_vibrate.dart';
|
import 'package:flutter_vibrate/flutter_vibrate.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:record/record.dart';
|
import 'package:record/record.dart';
|
||||||
|
|
||||||
|
|
@ -61,10 +62,14 @@ class DirectState extends CoreProvier {
|
||||||
Vibrate.feedback(FeedbackType.medium);
|
Vibrate.feedback(FeedbackType.medium);
|
||||||
}
|
}
|
||||||
isRecording = true;
|
isRecording = true;
|
||||||
Directory? tempDir = await getDownloadsDirectory();
|
Directory? tempDir;
|
||||||
|
if (!kIsWeb) {
|
||||||
|
tempDir = await getDownloadsDirectory();
|
||||||
|
}
|
||||||
_recorder.start(const RecordConfig(),
|
_recorder.start(const RecordConfig(),
|
||||||
path:
|
path: kIsWeb
|
||||||
'${tempDir!.path}/${DateTime.now().millisecondsSinceEpoch ~/ 1000}.m4a');
|
? ''
|
||||||
|
: '${tempDir!.path}/${DateTime.now().millisecondsSinceEpoch ~/ 1000}.m4a');
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,8 +81,12 @@ class DirectState extends CoreProvier {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (kIsWeb) {
|
if (kIsWeb) {
|
||||||
final uri = Uri.file(path);
|
// final uri = Uri.file(path);
|
||||||
recordedFile = File.fromUri(uri);
|
// recordedFile = File.fromUri(uri);
|
||||||
|
final Uri audioUri = Uri.parse(path);
|
||||||
|
final http.Response audioResponse = await http.get(audioUri);
|
||||||
|
final bytes = audioResponse.bodyBytes;
|
||||||
|
recordedFile = File.fromRawPath(bytes);
|
||||||
} else {
|
} else {
|
||||||
recordedFile = File(path);
|
recordedFile = File(path);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import 'package:didvan/models/message_data/message_data.dart';
|
||||||
import 'package:didvan/utils/date_time.dart';
|
import 'package:didvan/utils/date_time.dart';
|
||||||
import 'package:didvan/views/direct/direct_state.dart';
|
import 'package:didvan/views/direct/direct_state.dart';
|
||||||
import 'package:didvan/views/direct/widgets/audio_widget.dart';
|
import 'package:didvan/views/direct/widgets/audio_widget.dart';
|
||||||
import 'package:didvan/views/direct/widgets/downloadable_audio_widget.dart';
|
|
||||||
import 'package:didvan/views/widgets/didvan/divider.dart';
|
import 'package:didvan/views/widgets/didvan/divider.dart';
|
||||||
import 'package:didvan/views/widgets/didvan/text.dart';
|
import 'package:didvan/views/widgets/didvan/text.dart';
|
||||||
import 'package:didvan/views/widgets/skeleton_image.dart';
|
import 'package:didvan/views/widgets/skeleton_image.dart';
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,8 @@ import 'package:didvan/constants/app_icons.dart';
|
||||||
import 'package:didvan/views/ai/widgets/message_bar_btn.dart';
|
import 'package:didvan/views/ai/widgets/message_bar_btn.dart';
|
||||||
import 'package:didvan/views/direct/direct_state.dart';
|
import 'package:didvan/views/direct/direct_state.dart';
|
||||||
import 'package:didvan/views/direct/widgets/audio_widget.dart';
|
import 'package:didvan/views/direct/widgets/audio_widget.dart';
|
||||||
import 'package:didvan/views/direct/widgets/downloadable_audio_widget.dart';
|
|
||||||
import 'package:didvan/views/widgets/didvan/icon_button.dart';
|
import 'package:didvan/views/widgets/didvan/icon_button.dart';
|
||||||
import 'package:didvan/views/widgets/didvan/text.dart';
|
import 'package:didvan/views/widgets/didvan/text.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
|
@ -138,8 +136,6 @@ class _TypingState extends State<_Typing> {
|
||||||
size: 32,
|
size: 32,
|
||||||
color: Theme.of(context).colorScheme.focusedBorder,
|
color: Theme.of(context).colorScheme.focusedBorder,
|
||||||
)
|
)
|
||||||
: kIsWeb
|
|
||||||
? null
|
|
||||||
: DidvanIconButton(
|
: DidvanIconButton(
|
||||||
icon: DidvanIcons.mic_solid,
|
icon: DidvanIcons.mic_solid,
|
||||||
onPressed: state.startRecording,
|
onPressed: state.startRecording,
|
||||||
|
|
@ -157,8 +153,7 @@ class _TypingState extends State<_Typing> {
|
||||||
style: Theme.of(context).textTheme.bodyMedium,
|
style: Theme.of(context).textTheme.bodyMedium,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
border: InputBorder.none,
|
border: InputBorder.none,
|
||||||
hintText:
|
hintText: 'بنویسید یا پیام صوتی بگذارید...',
|
||||||
kIsWeb ? 'بنویسید...' : 'بنویسید یا پیام صوتی بگذارید...',
|
|
||||||
hintStyle: Theme.of(context).textTheme.bodySmall!.copyWith(
|
hintStyle: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||||
color: Theme.of(context).colorScheme.disabledText),
|
color: Theme.of(context).colorScheme.disabledText),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
update_js:
|
||||||
|
cp ./lib/assets/js/main.js ./build/flutter_assets/lib/assets/js/main.js
|
||||||
10
pubspec.lock
10
pubspec.lock
|
|
@ -73,6 +73,14 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.8.2"
|
version: "0.8.2"
|
||||||
|
azblob:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: azblob
|
||||||
|
sha256: e9e8689280bd8fa19c1c21a476547de80d2a770c81d2da9da68173c7f5479c7b
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "4.0.0"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -670,7 +678,7 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.18.1"
|
version: "0.18.1"
|
||||||
js:
|
js:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: js
|
name: js
|
||||||
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
|
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,8 @@ dependencies:
|
||||||
flutter_cache_manager: any
|
flutter_cache_manager: any
|
||||||
flutter_local_notifications: ^17.2.2
|
flutter_local_notifications: ^17.2.2
|
||||||
flutter_background_service: ^5.0.10
|
flutter_background_service: ^5.0.10
|
||||||
|
js: ^0.6.7
|
||||||
|
azblob: ^4.0.0
|
||||||
# url_launcher: ^6.3.0
|
# url_launcher: ^6.3.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
|
@ -127,6 +129,7 @@ flutter:
|
||||||
- lib/assets/images/features/
|
- lib/assets/images/features/
|
||||||
- lib/assets/icons/
|
- lib/assets/icons/
|
||||||
- lib/assets/animations/
|
- lib/assets/animations/
|
||||||
|
- lib/assets/js/
|
||||||
|
|
||||||
# An image asset can refer to one or more resolution-specific "variants", see
|
# An image asset can refer to one or more resolution-specific "variants", see
|
||||||
# https://flutter.dev/assets-and-images/#resolution-aware.
|
# https://flutter.dev/assets-and-images/#resolution-aware.
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@
|
||||||
|
|
||||||
<title>Didvan</title>
|
<title>Didvan</title>
|
||||||
<link rel="manifest" href="manifest.json" />
|
<link rel="manifest" href="manifest.json" />
|
||||||
|
<script src="/lib/assets/js/main.js" defer=""></script>
|
||||||
<style>
|
<style>
|
||||||
.container {
|
.container {
|
||||||
width: 100vw;
|
width: 100vw;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue