Merge pull request #7 from Shchoholiev/feature/SA-220-move-header-to-main

feature/SA-220-move-header-to-main
This commit is contained in:
Mykhailo Bilodid 2023-12-10 13:21:32 +02:00 committed by GitHub
commit e038027b58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 28 deletions

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:shopping_assistant_mobile_client/screens/chat.dart';
import 'package:shopping_assistant_mobile_client/screens/wishlists.dart'; import 'package:shopping_assistant_mobile_client/screens/wishlists.dart';
void main() { void main() {
@ -15,9 +16,9 @@ class MyApp extends StatefulWidget {
'Settings', 'Settings',
]; ];
static const List<Widget> _widgetOptions = <Widget>[ static List<Widget> _widgetOptions = <Widget>[
WishlistsScreen(), WishlistsScreen(),
Text(''), ChatScreen(wishlistId: '', wishlistName: 'New Chat',),
Text(''), Text(''),
]; ];
@ -37,6 +38,7 @@ class _MyAppState extends State<MyApp> {
}); });
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
@ -51,7 +53,9 @@ class _MyAppState extends State<MyApp> {
), ),
), ),
home: Scaffold( home: Scaffold(
appBar: AppBar( appBar: _selectedIndex == 1
? null
: AppBar(
title: Text(MyApp._pageNameOptions[_selectedIndex]), title: Text(MyApp._pageNameOptions[_selectedIndex]),
centerTitle: true, centerTitle: true,
bottom: PreferredSize( bottom: PreferredSize(

View File

@ -38,7 +38,7 @@ class MessageBubble extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
message, message.trim(),
style: TextStyle(color: isOutgoing ? Colors.white : Colors.black, style: TextStyle(color: isOutgoing ? Colors.white : Colors.black,
fontSize: 18.0 fontSize: 18.0
), ),
@ -63,6 +63,11 @@ class MessageBubble extends StatelessWidget {
} }
class ChatScreen extends StatefulWidget { class ChatScreen extends StatefulWidget {
String wishlistId;
String wishlistName;
ChatScreen({Key? key, required this.wishlistId, required this.wishlistName}) : super(key: key);
@override @override
State createState() => ChatScreenState(); State createState() => ChatScreenState();
} }
@ -79,8 +84,6 @@ class ChatScreenState extends State<ChatScreen> {
final ScrollController _scrollController = ScrollController(); final ScrollController _scrollController = ScrollController();
late Widget appBarTitle; late Widget appBarTitle;
String wishlistId = '';
void initState() { void initState() {
super.initState(); super.initState();
appBarTitle = Text('New Chat', style: TextStyle(fontSize: 18.0)); appBarTitle = Text('New Chat', style: TextStyle(fontSize: 18.0));
@ -88,7 +91,7 @@ class ChatScreenState extends State<ChatScreen> {
_handleSSEMessage(Message(text: '${event.data}')); _handleSSEMessage(Message(text: '${event.data}'));
}); });
Future.delayed(Duration(milliseconds: 2000)); Future.delayed(Duration(milliseconds: 2000));
if(!wishlistId.isEmpty) if(!widget.wishlistId.isEmpty)
{ {
_loadPreviousMessages(); _loadPreviousMessages();
showButtonsContainer = false; showButtonsContainer = false;
@ -99,8 +102,9 @@ class ChatScreenState extends State<ChatScreen> {
Future<void> _loadPreviousMessages() async { Future<void> _loadPreviousMessages() async {
final pageNumber = 1; final pageNumber = 1;
final pageSize = 200; final pageSize = 200;
appBarTitle = Text(widget.wishlistName, style: TextStyle(fontSize: 18.0));
try { try {
final previousMessages = await _searchService.getMessagesFromPersonalWishlist("6560b4c210686c50ed4b9fec", pageNumber, pageSize); final previousMessages = await _searchService.getMessagesFromPersonalWishlist(widget.wishlistId, pageNumber, pageSize);
final reversedMessages = previousMessages.reversed.toList(); final reversedMessages = previousMessages.reversed.toList();
setState(() { setState(() {
messages.addAll(reversedMessages); messages.addAll(reversedMessages);
@ -123,6 +127,7 @@ 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;
logger.d("Product status: ${message.isProduct}"); logger.d("Product status: ${message.isProduct}");
if (lastMessage != null && lastMessage.role != "User" && message.role != "User") { if (lastMessage != null && lastMessage.role != "User" && message.role != "User") {
final updatedMessage = Message( final updatedMessage = Message(
@ -156,7 +161,7 @@ class ChatScreenState extends State<ChatScreen> {
showButtonsContainer = false; showButtonsContainer = false;
isWaitingForResponse = true; isWaitingForResponse = true;
}); });
wishlistId = await _searchService.startPersonalWishlist(message); widget.wishlistId = await _searchService.startPersonalWishlist(message);
await _sendMessageToAPI(message); await _sendMessageToAPI(message);
await updateChatTitle(_searchService.wishlistId.toString()); await updateChatTitle(_searchService.wishlistId.toString());
_scrollToBottom(); _scrollToBottom();
@ -183,7 +188,7 @@ class ChatScreenState extends State<ChatScreen> {
void _sendMessage() { void _sendMessage() {
final message = _messageController.text; final message = _messageController.text;
if (wishlistId.isEmpty) { if (widget.wishlistId.isEmpty) {
setState(() { setState(() {
messages.add(Message(text: "What are you looking for?", role: "Application")); messages.add(Message(text: "What are you looking for?", role: "Application"));
messages.add(Message(text: message, role: "User")); messages.add(Message(text: message, role: "User"));
@ -384,6 +389,8 @@ class ChatScreenState extends State<ChatScreen> {
child: Row( child: Row(
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 15.0), // Adjust the left padding as needed
child: TextField( child: TextField(
controller: _messageController, controller: _messageController,
onChanged: (text) { onChanged: (text) {
@ -393,7 +400,8 @@ class ChatScreenState extends State<ChatScreen> {
}, },
decoration: InputDecoration( decoration: InputDecoration(
hintText: 'Enter your message...', hintText: 'Enter your message...',
contentPadding: EdgeInsets.symmetric(vertical: 20.0) contentPadding: EdgeInsets.symmetric(vertical: 20.0),
),
), ),
), ),
), ),

View File

@ -4,6 +4,8 @@ import 'package:graphql/client.dart';
import 'package:shopping_assistant_mobile_client/models/wishlist.dart'; import 'package:shopping_assistant_mobile_client/models/wishlist.dart';
import 'package:shopping_assistant_mobile_client/network/api_client.dart'; import 'package:shopping_assistant_mobile_client/network/api_client.dart';
import 'chat.dart';
class WishlistsScreen extends StatefulWidget { class WishlistsScreen extends StatefulWidget {
const WishlistsScreen({super.key}); const WishlistsScreen({super.key});
@ -211,16 +213,20 @@ class _WishlistItemState extends State<WishlistItem> {
), ),
Positioned( Positioned(
child: GestureDetector( child: GestureDetector(
onTap: () => print(Navigator.push( onTap: () {
Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => builder: (context) => ChatScreen(wishlistId: widget._wishlist.id, wishlistName: widget._wishlist.name),
Text('Chat ' + widget._wishlist.id)))), ),
onHorizontalDragUpdate: (DragUpdateDetails details) => { );
if (details.delta.dx < -1) },
{_transformLeft()} onHorizontalDragUpdate: (DragUpdateDetails details) {
else if (details.delta.dx > 1) if (details.delta.dx < -1) {
{_transformRight()} _transformLeft();
} else if (details.delta.dx > 1) {
_transformRight();
}
}, },
child: AnimatedContainer( child: AnimatedContainer(
transform: Matrix4.translationValues(_xOffset, 0, 0), transform: Matrix4.translationValues(_xOffset, 0, 0),