mirror of
https://github.com/Shchoholiev/shopping-assistant-mobile-client.git
synced 2025-04-05 00:59:38 +00:00
Merge pull request #10 from Shchoholiev/bug/SA-239-fix-display-suggestions
bug/SA-239-fix-display-suggestions
This commit is contained in:
commit
e9cd75ecfc
@ -31,7 +31,7 @@ class SearchService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool checkerForSuggestion() {
|
bool checkerForSuggestion() {
|
||||||
return type == SearchEventType.product;
|
return type == SearchEventType.suggestion;
|
||||||
}
|
}
|
||||||
|
|
||||||
String? wishlistId;
|
String? wishlistId;
|
||||||
|
@ -76,6 +76,7 @@ class ChatScreenState extends State<ChatScreen> {
|
|||||||
var logger = Logger();
|
var logger = Logger();
|
||||||
final SearchService _searchService = SearchService();
|
final SearchService _searchService = SearchService();
|
||||||
List<Message> messages = [];
|
List<Message> messages = [];
|
||||||
|
List<String> suggestions = [];
|
||||||
final TextEditingController _messageController = TextEditingController();
|
final TextEditingController _messageController = TextEditingController();
|
||||||
bool buttonsVisible = true;
|
bool buttonsVisible = true;
|
||||||
bool isSendButtonEnabled = false;
|
bool isSendButtonEnabled = false;
|
||||||
@ -127,19 +128,30 @@ class ChatScreenState extends State<ChatScreen> {
|
|||||||
final lastMessage = messages.isNotEmpty ? messages.last : null;
|
final lastMessage = messages.isNotEmpty ? messages.last : null;
|
||||||
message.isProduct = _searchService.checkerForProduct();
|
message.isProduct = _searchService.checkerForProduct();
|
||||||
message.isSuggestion = _searchService.checkerForSuggestion();
|
message.isSuggestion = _searchService.checkerForSuggestion();
|
||||||
bool checker = false;
|
if(message.isSuggestion){
|
||||||
|
suggestions.add(message.text);
|
||||||
|
}
|
||||||
logger.d("Product status: ${message.isProduct}");
|
logger.d("Product status: ${message.isProduct}");
|
||||||
if (lastMessage != null && lastMessage.role != "User" && message.role != "User") {
|
logger.d("Suggestion status: ${message.isSuggestion}");
|
||||||
|
logger.d("Message text: ${message.text}");
|
||||||
|
if (lastMessage != null && lastMessage.role != "User" && message.role != "User" && !message.isSuggestion) {
|
||||||
|
String fullMessageText = lastMessage.text + message.text;
|
||||||
|
fullMessageText = fullMessageText.replaceAll("\\n", "");
|
||||||
|
logger.d("fullMessageText: $fullMessageText");
|
||||||
final updatedMessage = Message(
|
final updatedMessage = Message(
|
||||||
text: "${lastMessage.text}${message.text}",
|
text: fullMessageText,
|
||||||
role: "Application",
|
role: "Application",
|
||||||
isProduct: message.isProduct);
|
isProduct: message.isProduct);
|
||||||
messages.removeLast();
|
messages.removeLast();
|
||||||
messages.add(updatedMessage);
|
messages.add(updatedMessage);
|
||||||
} else {
|
} else {
|
||||||
messages.add(message);
|
String messageText = message.text.replaceAll("\\n", "");
|
||||||
|
if (!message.isSuggestion) {
|
||||||
|
messages.add(Message(text: messageText, role: message.role, isProduct: message.isProduct, isSuggestion: message.isSuggestion));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
isWaitingForResponse = false;
|
isWaitingForResponse = false;
|
||||||
});
|
});
|
||||||
@ -202,9 +214,17 @@ class ChatScreenState extends State<ChatScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_messageController.clear();
|
_messageController.clear();
|
||||||
|
suggestions.clear();
|
||||||
_scrollToBottom();
|
_scrollToBottom();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _handleSuggestion(String suggestion) {
|
||||||
|
_messageController.text = suggestion;
|
||||||
|
_sendMessage();
|
||||||
|
suggestions.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void _scrollToBottom() {
|
void _scrollToBottom() {
|
||||||
_scrollController.animateTo(
|
_scrollController.animateTo(
|
||||||
_scrollController.position.maxScrollExtent,
|
_scrollController.position.maxScrollExtent,
|
||||||
@ -233,6 +253,46 @@ class ChatScreenState extends State<ChatScreen> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _generateSuggestionButtons() {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
|
child: Text(
|
||||||
|
'Several possible options',
|
||||||
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.grey),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SingleChildScrollView(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
child: Row(
|
||||||
|
children: suggestions.map((suggestion) {
|
||||||
|
return Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 5),
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: () {
|
||||||
|
_handleSuggestion(suggestion);
|
||||||
|
},
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 30, vertical: 16),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
),
|
||||||
|
primary: Colors.white,
|
||||||
|
onPrimary: Colors.blue,
|
||||||
|
side: BorderSide(color: Colors.blue, width: 2.0),
|
||||||
|
),
|
||||||
|
child: Text(suggestion, style: TextStyle(color: Colors.black)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -366,24 +426,8 @@ class ChatScreenState extends State<ChatScreen> {
|
|||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
size: 25.0,
|
size: 25.0,
|
||||||
),
|
),
|
||||||
if (messages.any((message) => message.isSuggestion))
|
if (suggestions.isNotEmpty)
|
||||||
Container(
|
_generateSuggestionButtons(),
|
||||||
padding: EdgeInsets.all(8.0),
|
|
||||||
color: Colors.grey[300],
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(Icons.lightbulb),
|
|
||||||
SizedBox(width: 8.0),
|
|
||||||
Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: messages
|
|
||||||
.where((message) => message.isSuggestion)
|
|
||||||
.map((message) => Text(message.text))
|
|
||||||
.toList(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Container(
|
Container(
|
||||||
margin: const EdgeInsets.all(8.0),
|
margin: const EdgeInsets.all(8.0),
|
||||||
child: Row(
|
child: Row(
|
||||||
@ -403,6 +447,7 @@ class ChatScreenState extends State<ChatScreen> {
|
|||||||
contentPadding: EdgeInsets.symmetric(vertical: 20.0),
|
contentPadding: EdgeInsets.symmetric(vertical: 20.0),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
|
Loading…
Reference in New Issue
Block a user