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

View File

@ -38,7 +38,7 @@ class MessageBubble extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
message,
message.trim(),
style: TextStyle(color: isOutgoing ? Colors.white : Colors.black,
fontSize: 18.0
),
@ -63,6 +63,11 @@ class MessageBubble extends StatelessWidget {
}
class ChatScreen extends StatefulWidget {
String wishlistId;
String wishlistName;
ChatScreen({Key? key, required this.wishlistId, required this.wishlistName}) : super(key: key);
@override
State createState() => ChatScreenState();
}
@ -79,8 +84,6 @@ class ChatScreenState extends State<ChatScreen> {
final ScrollController _scrollController = ScrollController();
late Widget appBarTitle;
String wishlistId = '';
void initState() {
super.initState();
appBarTitle = Text('New Chat', style: TextStyle(fontSize: 18.0));
@ -88,7 +91,7 @@ class ChatScreenState extends State<ChatScreen> {
_handleSSEMessage(Message(text: '${event.data}'));
});
Future.delayed(Duration(milliseconds: 2000));
if(!wishlistId.isEmpty)
if(!widget.wishlistId.isEmpty)
{
_loadPreviousMessages();
showButtonsContainer = false;
@ -99,8 +102,9 @@ class ChatScreenState extends State<ChatScreen> {
Future<void> _loadPreviousMessages() async {
final pageNumber = 1;
final pageSize = 200;
appBarTitle = Text(widget.wishlistName, style: TextStyle(fontSize: 18.0));
try {
final previousMessages = await _searchService.getMessagesFromPersonalWishlist("6560b4c210686c50ed4b9fec", pageNumber, pageSize);
final previousMessages = await _searchService.getMessagesFromPersonalWishlist(widget.wishlistId, pageNumber, pageSize);
final reversedMessages = previousMessages.reversed.toList();
setState(() {
messages.addAll(reversedMessages);
@ -123,6 +127,7 @@ class ChatScreenState extends State<ChatScreen> {
final lastMessage = messages.isNotEmpty ? messages.last : null;
message.isProduct = _searchService.checkerForProduct();
message.isSuggestion = _searchService.checkerForSuggestion();
bool checker = false;
logger.d("Product status: ${message.isProduct}");
if (lastMessage != null && lastMessage.role != "User" && message.role != "User") {
final updatedMessage = Message(
@ -156,7 +161,7 @@ class ChatScreenState extends State<ChatScreen> {
showButtonsContainer = false;
isWaitingForResponse = true;
});
wishlistId = await _searchService.startPersonalWishlist(message);
widget.wishlistId = await _searchService.startPersonalWishlist(message);
await _sendMessageToAPI(message);
await updateChatTitle(_searchService.wishlistId.toString());
_scrollToBottom();
@ -183,7 +188,7 @@ class ChatScreenState extends State<ChatScreen> {
void _sendMessage() {
final message = _messageController.text;
if (wishlistId.isEmpty) {
if (widget.wishlistId.isEmpty) {
setState(() {
messages.add(Message(text: "What are you looking for?", role: "Application"));
messages.add(Message(text: message, role: "User"));
@ -384,16 +389,19 @@ class ChatScreenState extends State<ChatScreen> {
child: Row(
children: <Widget>[
Expanded(
child: TextField(
controller: _messageController,
onChanged: (text) {
setState(() {
isSendButtonEnabled = text.isNotEmpty;
});
},
decoration: InputDecoration(
hintText: 'Enter your message...',
contentPadding: EdgeInsets.symmetric(vertical: 20.0)
child: Padding(
padding: const EdgeInsets.only(left: 15.0), // Adjust the left padding as needed
child: TextField(
controller: _messageController,
onChanged: (text) {
setState(() {
isSendButtonEnabled = text.isNotEmpty;
});
},
decoration: InputDecoration(
hintText: 'Enter your message...',
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/network/api_client.dart';
import 'chat.dart';
class WishlistsScreen extends StatefulWidget {
const WishlistsScreen({super.key});
@ -211,16 +213,20 @@ class _WishlistItemState extends State<WishlistItem> {
),
Positioned(
child: GestureDetector(
onTap: () => print(Navigator.push(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
Text('Chat ' + widget._wishlist.id)))),
onHorizontalDragUpdate: (DragUpdateDetails details) => {
if (details.delta.dx < -1)
{_transformLeft()}
else if (details.delta.dx > 1)
{_transformRight()}
builder: (context) => ChatScreen(wishlistId: widget._wishlist.id, wishlistName: widget._wishlist.name),
),
);
},
onHorizontalDragUpdate: (DragUpdateDetails details) {
if (details.delta.dx < -1) {
_transformLeft();
} else if (details.delta.dx > 1) {
_transformRight();
}
},
child: AnimatedContainer(
transform: Matrix4.translationValues(_xOffset, 0, 0),