From 19813c2f66a711496f40584fc371cb7d265be8da Mon Sep 17 00:00:00 2001 From: Mykhailo Bilodid Date: Fri, 15 Dec 2023 21:41:15 +0200 Subject: [PATCH] SA-178 cards screen created --- lib/main.dart | 35 +----------------- lib/network/search_service.dart | 7 ++++ lib/screens/cards.dart | 60 ++++++++++++++++++++++++++++++ lib/screens/chat.dart | 65 ++++++++++++++++----------------- pubspec.lock | 26 ++++++------- 5 files changed, 113 insertions(+), 80 deletions(-) create mode 100644 lib/screens/cards.dart diff --git a/lib/main.dart b/lib/main.dart index 5be5953..0b4314b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -106,37 +106,4 @@ class _MyAppState extends State { ), ); } -} - - - - - -// Use to seed wishlists for new user -// final ApiClient client = ApiClient(); -// -// const String startPersonalWishlistMutations = r''' -// mutation startPersonalWishlist($dto: WishlistCreateDtoInput!) { -// startPersonalWishlist(dto: $dto) { -// createdById, id, name, type -// } -// } -// '''; -// -// MutationOptions mutationOptions = MutationOptions( -// document: gql(startPersonalWishlistMutations), -// variables: const { -// 'dto': { -// 'firstMessageText': 'Gaming mechanical keyboard', -// 'type': 'Product' -// }, -// }); -// -// var client = ApiClient(); -// // for (var i = 0; i < 5; i++) { -// // client -// // .mutate(mutationOptions) -// // .then((result) => print(jsonEncode(result))); -// // sleep(Duration(milliseconds: 100)); -// // } -// \ No newline at end of file +} \ No newline at end of file diff --git a/lib/network/search_service.dart b/lib/network/search_service.dart index 2197852..f0c8463 100644 --- a/lib/network/search_service.dart +++ b/lib/network/search_service.dart @@ -22,6 +22,8 @@ SearchEventType type = SearchEventType.message; class SearchService { final ApiClient client = ApiClient(); + List products = []; + late final _sseController = StreamController(); Stream get sseStream => _sseController.stream; @@ -92,6 +94,11 @@ class SearchService { final event = ServerSentEvent(chunk.event, cleanedMessage); type = chunk.event; + if(type == SearchEventType.product) { + String pattern = r'[\\\"]'; + String product = event.data.replaceAll(RegExp(pattern), ''); + products.add(product); + } _sseController.add(event); } } diff --git a/lib/screens/cards.dart b/lib/screens/cards.dart new file mode 100644 index 0000000..542a20c --- /dev/null +++ b/lib/screens/cards.dart @@ -0,0 +1,60 @@ +import 'package:flutter/material.dart'; + +class Cards extends StatefulWidget { + final String wishlistName; + List products = []; + + Cards({required this.wishlistName, required this.products}); + + @override + _CardsState createState() => _CardsState(); +} + +class _CardsState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text(widget.wishlistName), + centerTitle: true, + ), + body: Center( + child: Stack( + children: [ + // Back Card with increased rotation effect + Positioned( + left: 10, // Adjust the left position as needed + child: Transform.rotate( + angle: -5 * 3.1415926535 / 180, // Rotation angle + child: Container( + width: 400, // Increased width + height: 600, // Increased height + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.white, + border: Border.all( + color: Color(0xFF009FFF), + ), + ), + ), + ), + ), + // Main Card + Container( + width: 300, // Set the width of the main card + height: 500, // Set the height of the main card + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: Colors.white, + border: Border.all( + color: Color(0xFF009FFF), + ), + ), + ), + ], + ), + ), + ); + } +} + diff --git a/lib/screens/chat.dart b/lib/screens/chat.dart index 95f8c46..eace5c8 100644 --- a/lib/screens/chat.dart +++ b/lib/screens/chat.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:logger/logger.dart'; import 'package:shopping_assistant_mobile_client/network/search_service.dart'; +import 'package:shopping_assistant_mobile_client/screens/cards.dart'; class Message { final String text; @@ -23,41 +24,30 @@ class MessageBubble extends StatelessWidget { @override Widget build(BuildContext context) { return Align( - alignment: isOutgoing ? Alignment.centerRight : Alignment.centerLeft, - child: Container( - margin: const EdgeInsets.all(8.0), - padding: const EdgeInsets.all(16.0), - constraints: BoxConstraints( - maxWidth: 300.0, - ), - decoration: BoxDecoration( - color: isOutgoing ? Colors.blue : Colors.grey[200], - borderRadius: BorderRadius.circular(10.0), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( + alignment: isOutgoing ? Alignment.centerRight : Alignment.centerLeft, + child: Container( + margin: const EdgeInsets.all(8.0), + padding: const EdgeInsets.all(16.0), + constraints: BoxConstraints( + maxWidth: 300.0, + ), + decoration: BoxDecoration( + color: isOutgoing ? Colors.blue : Colors.grey[200], + borderRadius: BorderRadius.circular(10.0), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( message.trim(), - style: TextStyle(color: isOutgoing ? Colors.white : Colors.black, - fontSize: 18.0 - ), - ), - if (isProduct) - ElevatedButton( - onPressed: () { - print('View Product button pressed'); - }, - style: ElevatedButton.styleFrom( - primary: Colors.indigo, - onPrimary: Colors.white, - minimumSize: Size(300, 50) - ), - child: Text('View Product'), - ), - ], + style: TextStyle( + color: isOutgoing ? Colors.white : Colors.black, + fontSize: 18.0, + ), ), - ), + ], + ), + ), ); } } @@ -151,6 +141,7 @@ class ChatScreenState extends State { if (wishlistName != null) { setState(() { appBarTitle = Text(wishlistName, style: TextStyle(fontSize: 18.0)); + this.widget.wishlistName = wishlistName; }); } } @@ -181,6 +172,14 @@ class ChatScreenState extends State { _scrollToBottom(); setState(() { + if(_searchService.checkerForProduct()){ + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => Cards(wishlistName: this.widget.wishlistName, products: this._searchService.products,), + ), + ); + } isWaitingForResponse = false; }); } diff --git a/pubspec.lock b/pubspec.lock index c20e2af..86567a6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -45,10 +45,10 @@ packages: dependency: transitive description: name: collection - sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.2" + version: "1.18.0" connectivity_plus: dependency: transitive description: @@ -308,10 +308,10 @@ packages: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" nm: dependency: transitive description: @@ -497,18 +497,18 @@ packages: dependency: transitive description: name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" string_scanner: dependency: transitive description: @@ -529,10 +529,10 @@ packages: dependency: transitive description: name: test_api - sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.6.0" + version: "0.6.1" typed_data: dependency: transitive description: @@ -649,10 +649,10 @@ packages: dependency: transitive description: name: web - sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 url: "https://pub.dev" source: hosted - version: "0.1.4-beta" + version: "0.3.0" web_socket_channel: dependency: transitive description: @@ -694,5 +694,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.1.4 <4.0.0" + dart: ">=3.2.0-194.0.dev <4.0.0" flutter: ">=3.13.0"