"Refactor FilesModel: rename 'basename' to 'name', make 'name' nullable, and update usages in AiApiService and AiMessageBar widgets."
This commit is contained in:
parent
b23c60a511
commit
a366dcd230
|
|
@ -6,7 +6,7 @@ import 'package:path/path.dart' as p;
|
|||
|
||||
class FilesModel {
|
||||
final String path;
|
||||
late String basename;
|
||||
late String? name;
|
||||
late String extname;
|
||||
late File main;
|
||||
final bool isRecorded;
|
||||
|
|
@ -18,7 +18,7 @@ class FilesModel {
|
|||
|
||||
FilesModel(
|
||||
this.path, {
|
||||
final String? name,
|
||||
this.name,
|
||||
this.isRecorded = false,
|
||||
this.audio,
|
||||
this.image,
|
||||
|
|
@ -26,11 +26,11 @@ class FilesModel {
|
|||
this.bytes,
|
||||
this.duration,
|
||||
}) {
|
||||
basename = name ?? p.basename(path);
|
||||
name = name ?? p.basename(path);
|
||||
extname = path.isNotEmpty
|
||||
? p.extension(path)
|
||||
: name != null
|
||||
? p.extension(name)
|
||||
? p.extension(name!)
|
||||
: '';
|
||||
|
||||
main = File(path);
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ class AiApiService {
|
|||
|
||||
mimeType = lookupMimeType(filename, headerBytes: bytes) ?? 'audio/mp4';
|
||||
} else {
|
||||
filename = file.basename;
|
||||
filename = file.name!;
|
||||
mimeType = lookupMimeType(filename, headerBytes: bytes) ??
|
||||
'application/octet-stream';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -896,7 +896,7 @@ class _AiMessageBarState extends State<AiMessageBar> {
|
|||
SizedBox(
|
||||
height: 24,
|
||||
child: MarqueeText(
|
||||
text: state.file != null ? state.file!.basename : '',
|
||||
text: state.file != null ? state.file!.name! : '',
|
||||
style: const TextStyle(fontSize: 14),
|
||||
stop: const Duration(seconds: 3),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -252,8 +252,7 @@ class _AiMessageBarIOSState extends State<AiMessageBarIOS> {
|
|||
file: state
|
||||
.file?.path,
|
||||
fileName: state
|
||||
.file
|
||||
?.basename,
|
||||
.file?.name,
|
||||
fileLocal:
|
||||
state.file,
|
||||
finished: true,
|
||||
|
|
@ -288,7 +287,7 @@ class _AiMessageBarIOSState extends State<AiMessageBarIOS> {
|
|||
?.path,
|
||||
fileName: state
|
||||
.file
|
||||
?.basename,
|
||||
?.name,
|
||||
fileLocal:
|
||||
state
|
||||
.file,
|
||||
|
|
@ -561,7 +560,7 @@ class _AiMessageBarIOSState extends State<AiMessageBarIOS> {
|
|||
? const Padding(
|
||||
padding: EdgeInsets.fromLTRB(8, 8, 8, 4),
|
||||
child: DidvanText(
|
||||
'مدلهای هوش مصنوعی میتوانند اشتباه کنند، صحت اطلاعات مهم را بررسی کنید.',
|
||||
'مدلهای هوش مصنوعی میتوانند اشتباه کنند، صحت اطلاعات مهم را بررسی کنید.',
|
||||
fontSize: 12,
|
||||
),
|
||||
)
|
||||
|
|
@ -604,11 +603,10 @@ class _AiMessageBarIOSState extends State<AiMessageBarIOS> {
|
|||
MediaService.onLoadingPickFile(context);
|
||||
FilePickerResult? result = await MediaService.pickPdfFile();
|
||||
if (result != null) {
|
||||
Uint8List? bytes =
|
||||
result.files.first.bytes; // Access the bytes property
|
||||
String? name = result.files.first.name;
|
||||
if (kIsWeb) {
|
||||
Uint8List? bytes =
|
||||
result.files.first.bytes; // Access the bytes property
|
||||
String? name = result.files.first.name;
|
||||
|
||||
// Store bytes and file name directly in your state or model
|
||||
state.file = FilesModel(
|
||||
'', // No need for a file path on web
|
||||
|
|
@ -619,7 +617,7 @@ class _AiMessageBarIOSState extends State<AiMessageBarIOS> {
|
|||
);
|
||||
} else {
|
||||
state.file = FilesModel(result.files.single.path!,
|
||||
audio: false, image: false);
|
||||
name: name, audio: false, image: false);
|
||||
}
|
||||
}
|
||||
Future.delayed(
|
||||
|
|
@ -764,7 +762,7 @@ class _AiMessageBarIOSState extends State<AiMessageBarIOS> {
|
|||
SizedBox(
|
||||
height: 24,
|
||||
child: MarqueeText(
|
||||
text: state.file != null ? state.file!.basename : '',
|
||||
text: state.file != null ? state.file!.name! : '',
|
||||
style: const TextStyle(fontSize: 14),
|
||||
stop: const Duration(seconds: 3),
|
||||
),
|
||||
|
|
|
|||
Loading…
Reference in New Issue