"Refactored AI chat page and message bar widgets: added file name handling, updated text direction logic, and rearranged UI components."

This commit is contained in:
OkaykOrhmn 2024-11-18 16:44:36 +03:30
parent 306b85f163
commit 7bec995377
2 changed files with 121 additions and 120 deletions

View File

@ -714,6 +714,7 @@ class _AiChatPageState extends State<AiChatPage> {
Container messageFile(
BuildContext context, Prompts message, AiChatState state) {
final String fileName = message.fileName ?? message.fileLocal?.name ?? '';
return Container(
decoration: BoxDecoration(
borderRadius: DesignConfig.mediumBorderRadius,
@ -734,9 +735,12 @@ class _AiChatPageState extends State<AiChatPage> {
SizedBox(
width: MediaQuery.sizeOf(context).width,
child: MarqueeText(
text: message.fileName.toString(),
text: fileName,
style: const TextStyle(fontSize: 14),
stop: const Duration(seconds: 3),
textDirection: fileName.startsWithEnglish()
? TextDirection.ltr
: TextDirection.rtl,
),
),
// if (state.file != null && !kIsWeb)

View File

@ -379,53 +379,17 @@ class _AiMessageBarState extends State<AiMessageBar> {
Expanded(
child: state.file != null && state.file!.isRecorded
? audioContainer()
: Directionality(
textDirection: state.message.text
.toString()
.startsWithEnglish()
: ValueListenableBuilder(
valueListenable: state.message,
builder: (context, message, child) {
return Directionality(
textDirection:
message.text.toString().startsWithEnglish()
? TextDirection.ltr
: TextDirection.rtl,
child: TextFormField(
textInputAction: TextInputAction.newline,
style: Theme.of(context).textTheme.bodyMedium,
minLines: 1,
maxLines: 6, // Set this
keyboardType: TextInputType.multiline,
controller: state.message,
enabled: !(state.file != null &&
widget.bot.attachment == 1),
decoration: InputDecoration(
contentPadding:
const EdgeInsets.fromLTRB(12, 12, 12, 12),
border: InputBorder.none,
hintText: 'بنویسید...',
hintStyle: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
color: Theme.of(context)
.colorScheme
.disabledText),
suffixIcon: state.isEdite
? InkWell(
onTap: () {
state.isEdite = false;
state.update();
},
child: const Icon(
DidvanIcons.close_circle_solid),
)
: const SizedBox(),
),
onChanged: (value) {
if (value.isEmpty || value.length == 1) {
state.update();
}
},
),
),
child: edittext(context, state),
);
}),
),
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
@ -458,11 +422,43 @@ class _AiMessageBarState extends State<AiMessageBar> {
);
}
Padding recorderAndSendButton(
AiChatState state, HistoryAiChatState historyState) {
return Padding(
TextFormField edittext(BuildContext context, AiChatState state) {
return TextFormField(
textInputAction: TextInputAction.newline,
style: Theme.of(context).textTheme.bodyMedium,
minLines: 1,
maxLines: 6, // Set this
keyboardType: TextInputType.multiline,
controller: state.message,
enabled: !(state.file != null && widget.bot.attachment == 1),
decoration: InputDecoration(
contentPadding: const EdgeInsets.fromLTRB(12, 12, 12, 12),
border: InputBorder.none,
hintText: 'بنویسید...',
hintStyle: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(color: Theme.of(context).colorScheme.disabledText),
suffixIcon: state.isEdite
? InkWell(
onTap: () {
state.isEdite = false;
state.update();
},
child: const Icon(DidvanIcons.close_circle_solid),
)
: const SizedBox(),
),
);
}
recorderAndSendButton(AiChatState state, HistoryAiChatState historyState) {
return ValueListenableBuilder(
valueListenable: state.message,
builder: (context, message, child) => Padding(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 8),
child: state.message.text.isEmpty &&
child: message.text.isEmpty &&
historyState.bot!.attachmentType!.contains('audio') &&
state.file == null &&
widget.bot.attachment != 0
@ -476,12 +472,12 @@ class _AiMessageBarState extends State<AiMessageBar> {
: MessageBarBtn(
enable: (state.file != null && state.file!.isRecorded) ||
(widget.bot.attachment == 1) ||
state.message.text.isNotEmpty,
message.text.isNotEmpty,
icon: DidvanIcons.send_light,
click: () async {
if ((state.file == null || !state.file!.isRecorded) &&
(widget.bot.attachment != 1) &&
state.message.text.isEmpty) {
message.text.isEmpty) {
return;
}
@ -494,7 +490,7 @@ class _AiMessageBarState extends State<AiMessageBar> {
.toPersianDateStr())) {
state.messages.last.prompts.add(Prompts(
error: false,
text: state.message.text,
text: message.text,
// file: state.file?.path,
// fileName: state.file?.basename,
fileLocal: state.file,
@ -512,7 +508,7 @@ class _AiMessageBarState extends State<AiMessageBar> {
prompts: [
Prompts(
error: false,
text: state.message.text,
text: message.text,
finished: true,
// file: state.file?.path,
// fileName: state.file?.basename,
@ -531,6 +527,7 @@ class _AiMessageBarState extends State<AiMessageBar> {
widget.bot, widget.assistantsName != null);
},
),
),
);
}
@ -694,7 +691,7 @@ class _AiMessageBarState extends State<AiMessageBar> {
MediaService.onLoadingPickFile(context);
FilePickerResult? result = await MediaService.pickPdfFile();
if (result != null) {
String? name = result.files.first.name;
String? name = result.files.single.name;
if (kIsWeb) {
Uint8List? bytes =
@ -910,7 +907,7 @@ class _AiMessageBarState extends State<AiMessageBar> {
SizedBox(
height: 24,
child: MarqueeText(
text: state.file != null ? state.file!.name! : '',
text: state.file != null ? state.file!.name ?? '' : '',
style: const TextStyle(fontSize: 14),
stop: const Duration(seconds: 3),
),