"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 {
|
class FilesModel {
|
||||||
final String path;
|
final String path;
|
||||||
late String basename;
|
late String? name;
|
||||||
late String extname;
|
late String extname;
|
||||||
late File main;
|
late File main;
|
||||||
final bool isRecorded;
|
final bool isRecorded;
|
||||||
|
|
@ -18,7 +18,7 @@ class FilesModel {
|
||||||
|
|
||||||
FilesModel(
|
FilesModel(
|
||||||
this.path, {
|
this.path, {
|
||||||
final String? name,
|
this.name,
|
||||||
this.isRecorded = false,
|
this.isRecorded = false,
|
||||||
this.audio,
|
this.audio,
|
||||||
this.image,
|
this.image,
|
||||||
|
|
@ -26,11 +26,11 @@ class FilesModel {
|
||||||
this.bytes,
|
this.bytes,
|
||||||
this.duration,
|
this.duration,
|
||||||
}) {
|
}) {
|
||||||
basename = name ?? p.basename(path);
|
name = name ?? p.basename(path);
|
||||||
extname = path.isNotEmpty
|
extname = path.isNotEmpty
|
||||||
? p.extension(path)
|
? p.extension(path)
|
||||||
: name != null
|
: name != null
|
||||||
? p.extension(name)
|
? p.extension(name!)
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
main = File(path);
|
main = File(path);
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ class AiApiService {
|
||||||
|
|
||||||
mimeType = lookupMimeType(filename, headerBytes: bytes) ?? 'audio/mp4';
|
mimeType = lookupMimeType(filename, headerBytes: bytes) ?? 'audio/mp4';
|
||||||
} else {
|
} else {
|
||||||
filename = file.basename;
|
filename = file.name!;
|
||||||
mimeType = lookupMimeType(filename, headerBytes: bytes) ??
|
mimeType = lookupMimeType(filename, headerBytes: bytes) ??
|
||||||
'application/octet-stream';
|
'application/octet-stream';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -896,7 +896,7 @@ class _AiMessageBarState extends State<AiMessageBar> {
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 24,
|
height: 24,
|
||||||
child: MarqueeText(
|
child: MarqueeText(
|
||||||
text: state.file != null ? state.file!.basename : '',
|
text: state.file != null ? state.file!.name! : '',
|
||||||
style: const TextStyle(fontSize: 14),
|
style: const TextStyle(fontSize: 14),
|
||||||
stop: const Duration(seconds: 3),
|
stop: const Duration(seconds: 3),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -252,8 +252,7 @@ class _AiMessageBarIOSState extends State<AiMessageBarIOS> {
|
||||||
file: state
|
file: state
|
||||||
.file?.path,
|
.file?.path,
|
||||||
fileName: state
|
fileName: state
|
||||||
.file
|
.file?.name,
|
||||||
?.basename,
|
|
||||||
fileLocal:
|
fileLocal:
|
||||||
state.file,
|
state.file,
|
||||||
finished: true,
|
finished: true,
|
||||||
|
|
@ -288,7 +287,7 @@ class _AiMessageBarIOSState extends State<AiMessageBarIOS> {
|
||||||
?.path,
|
?.path,
|
||||||
fileName: state
|
fileName: state
|
||||||
.file
|
.file
|
||||||
?.basename,
|
?.name,
|
||||||
fileLocal:
|
fileLocal:
|
||||||
state
|
state
|
||||||
.file,
|
.file,
|
||||||
|
|
@ -604,11 +603,10 @@ class _AiMessageBarIOSState extends State<AiMessageBarIOS> {
|
||||||
MediaService.onLoadingPickFile(context);
|
MediaService.onLoadingPickFile(context);
|
||||||
FilePickerResult? result = await MediaService.pickPdfFile();
|
FilePickerResult? result = await MediaService.pickPdfFile();
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
if (kIsWeb) {
|
|
||||||
Uint8List? bytes =
|
Uint8List? bytes =
|
||||||
result.files.first.bytes; // Access the bytes property
|
result.files.first.bytes; // Access the bytes property
|
||||||
String? name = result.files.first.name;
|
String? name = result.files.first.name;
|
||||||
|
if (kIsWeb) {
|
||||||
// Store bytes and file name directly in your state or model
|
// Store bytes and file name directly in your state or model
|
||||||
state.file = FilesModel(
|
state.file = FilesModel(
|
||||||
'', // No need for a file path on web
|
'', // No need for a file path on web
|
||||||
|
|
@ -619,7 +617,7 @@ class _AiMessageBarIOSState extends State<AiMessageBarIOS> {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
state.file = FilesModel(result.files.single.path!,
|
state.file = FilesModel(result.files.single.path!,
|
||||||
audio: false, image: false);
|
name: name, audio: false, image: false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Future.delayed(
|
Future.delayed(
|
||||||
|
|
@ -764,7 +762,7 @@ class _AiMessageBarIOSState extends State<AiMessageBarIOS> {
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 24,
|
height: 24,
|
||||||
child: MarqueeText(
|
child: MarqueeText(
|
||||||
text: state.file != null ? state.file!.basename : '',
|
text: state.file != null ? state.file!.name! : '',
|
||||||
style: const TextStyle(fontSize: 14),
|
style: const TextStyle(fontSize: 14),
|
||||||
stop: const Duration(seconds: 3),
|
stop: const Duration(seconds: 3),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue