From fd54cfdb5b8a795b8dc3942e8dd88f8d0997bd06 Mon Sep 17 00:00:00 2001 From: Polabiel Date: Wed, 11 Sep 2024 13:02:43 -0300 Subject: [PATCH 1/7] =?UTF-8?q?Refatorar=20servi=C3=A7o=20de=20armazenamen?= =?UTF-8?q?to=20local=20compartilhado=20e=20adicionar=20funcionalidade=20d?= =?UTF-8?q?e=20salvar=20produtos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Refatorar importações desnecessárias e atualizar texto e descrição do produto - Adicionar método para salvar produtos no armazenamento local - Adicionar método para obter todos os produtos salvos - Adicionar método para obter itens selecionados - Atualizar página de produtos para salvar dados do produto no carrinho - Adicionar página de carrinho para exibir os produtos salvos --- .../shared_local_storage_service.dart | 41 +++++++++++++++++ lib/src/app/home/cart/cart_page.dart | 44 +++++++++++++++++++ .../app/sessions/products/product_page.dart | 6 ++- lib/src/components/header_bar.dart | 3 ++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 lib/src/app/home/cart/cart_page.dart diff --git a/lib/api/services/shared_local_storage_service.dart b/lib/api/services/shared_local_storage_service.dart index 32fb125..28dea90 100644 --- a/lib/api/services/shared_local_storage_service.dart +++ b/lib/api/services/shared_local_storage_service.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:gohealth/api/interfaces/local_storage_interface.dart'; +import 'package:gohealth/api/models/product_models.dart'; import 'package:gohealth/api/models/user_models.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -77,4 +78,44 @@ class SharedLocalStorageService implements ILocalStorage { value.clear(); }); } + + void saveProduct(ProductModels productModels) { + var shared = SharedPreferences.getInstance(); + shared.then((value) { + var products = value.getString('products'); + List list = []; + if (products != null) { + var decoded = jsonDecode(products) as List; + list = decoded.map((e) => ProductModels.fromJson(e)).toList(); + } + list.add(productModels); + value.setString('products', jsonEncode(list)); + }); + } + + Future> getAllProducts() { + var shared = SharedPreferences.getInstance(); + return shared.then((value) { + var products = value.getString('products'); + if (products != null) { + var decoded = jsonDecode(products) as List; + return decoded.map((e) => ProductModels.fromJson(e)).toList(); + } else { + throw Exception('No products found'); + } + }); + } + + getSelectedItems() { + var shared = SharedPreferences.getInstance(); + return shared.then((value) { + var products = value.getString('products'); + if (products != null) { + var decoded = jsonDecode(products) as List; + return decoded.map((e) => e.toString()).toList(); + } else { + throw Exception('No products found'); + } + }); + } } diff --git a/lib/src/app/home/cart/cart_page.dart b/lib/src/app/home/cart/cart_page.dart new file mode 100644 index 0000000..48c5f82 --- /dev/null +++ b/lib/src/app/home/cart/cart_page.dart @@ -0,0 +1,44 @@ +import 'package:flutter/material.dart'; +import 'package:gohealth/api/models/product_models.dart'; +import 'package:gohealth/api/services/shared_local_storage_service.dart'; +import 'package:gohealth/src/components/header_bar.dart'; +import 'package:gohealth/src/components/side_menu.dart'; + +class CartPage extends StatefulWidget { + const CartPage({ Key? key }) : super(key: key); + + @override + _CartPageState createState() => _CartPageState(); +} + +class _CartPageState extends State { + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: const HeaderBarState(), + drawer: const SideMenu(), + body: FutureBuilder>( + future: SharedLocalStorageService().getAllProducts(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return const Center(child: CircularProgressIndicator()); + } else if (snapshot.hasError) { + return Center(child: Text('Error: ${snapshot.error}')); + } else if (!snapshot.hasData || snapshot.data!.isEmpty) { + return const Center(child: Text('No items selected.')); + } else { + return ListView.builder( + itemCount: snapshot.data!.length, + itemBuilder: (context, index) { + return ListTile( + title: Text(snapshot.data![index].toString()), // Assuming ProductModels has a toString() method + ); + }, + ); + } + }, + ), + ); + } +} \ No newline at end of file diff --git a/lib/src/app/sessions/products/product_page.dart b/lib/src/app/sessions/products/product_page.dart index d393b1d..333111e 100644 --- a/lib/src/app/sessions/products/product_page.dart +++ b/lib/src/app/sessions/products/product_page.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:gohealth/api/models/product_models.dart'; +import 'package:gohealth/api/services/shared_local_storage_service.dart'; import 'image_carousel.dart'; import 'product_details.dart'; import 'description_section.dart'; @@ -44,7 +45,10 @@ class ProductState extends State { bottomNavigationBar: Padding( padding: const EdgeInsets.all(16.0), child: ElevatedButton( - onPressed: () {}, + onPressed: () { + // Salvar os dados do produto no carrinho atráves do storage + SharedLocalStorageService().saveProduct(widget.productModels); + }, child: Text('Adicionar ao carrinho'), style: ElevatedButton.styleFrom( padding: EdgeInsets.symmetric(vertical: 16), diff --git a/lib/src/components/header_bar.dart b/lib/src/components/header_bar.dart index b3ba0d8..afd4515 100644 --- a/lib/src/components/header_bar.dart +++ b/lib/src/components/header_bar.dart @@ -84,6 +84,9 @@ class _HeaderBarState extends State { ], ), actions: [ + IconButton(onPressed: () { + // Função para carrinho + }, icon: const Icon(Icons.shopping_cart)), IconButton( icon: const Icon(Icons.notifications), onPressed: () { From dc4735b90ed4c4433c2ffbbda92f3d72c27d4f82 Mon Sep 17 00:00:00 2001 From: Polabiel Date: Wed, 11 Sep 2024 16:52:47 -0300 Subject: [PATCH 2/7] =?UTF-8?q?Refatorar=20servi=C3=A7o=20de=20armazenamen?= =?UTF-8?q?to=20local=20compartilhado=20e=20adicionar=20funcionalidade=20d?= =?UTF-8?q?e=20remover=20produto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shared_local_storage_service.dart | 14 ++++++++++++++ lib/src/app/home/cart/cart_page.dart | 19 +++++++++++++++++-- pubspec.lock | 4 ++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/lib/api/services/shared_local_storage_service.dart b/lib/api/services/shared_local_storage_service.dart index 28dea90..c0992dd 100644 --- a/lib/api/services/shared_local_storage_service.dart +++ b/lib/api/services/shared_local_storage_service.dart @@ -118,4 +118,18 @@ class SharedLocalStorageService implements ILocalStorage { } }); } + + void removeProduct(int? id) { + var shared = SharedPreferences.getInstance(); + shared.then((value) { + var products = value.getString('products'); + List list = []; + if (products != null) { + var decoded = jsonDecode(products) as List; + list = decoded.map((e) => ProductModels.fromJson(e)).toList(); + } + list.removeWhere((element) => element.id == id); + value.setString('products', jsonEncode(list)); + }); + } } diff --git a/lib/src/app/home/cart/cart_page.dart b/lib/src/app/home/cart/cart_page.dart index 48c5f82..bdd4caf 100644 --- a/lib/src/app/home/cart/cart_page.dart +++ b/lib/src/app/home/cart/cart_page.dart @@ -31,8 +31,23 @@ class _CartPageState extends State { return ListView.builder( itemCount: snapshot.data!.length, itemBuilder: (context, index) { - return ListTile( - title: Text(snapshot.data![index].toString()), // Assuming ProductModels has a toString() method + final product = snapshot.data![index]; + return Card( + margin: const EdgeInsets.all(10.0), + child: ListTile( + leading: Image.network(product.image ?? "https://via.placeholder.com/150", width: 50, height: 50, fit: BoxFit.cover), + title: Text(product.name!), + subtitle: Text('Price: \$${product.price!.toStringAsFixed(2)}'), + trailing: IconButton( + icon: const Icon(Icons.delete), + onPressed: () { + setState(() { + snapshot.data!.removeAt(index); + SharedLocalStorageService().removeProduct(product.id); + }); + }, + ), + ), ); }, ); diff --git a/pubspec.lock b/pubspec.lock index 0b2a137..207e711 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -609,10 +609,10 @@ packages: dependency: transitive description: name: vm_service - sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "14.2.4" + version: "14.2.5" web: dependency: transitive description: From dad731219d4695f9fda0e635aef84f918f5ccbad Mon Sep 17 00:00:00 2001 From: Polabiel Date: Wed, 11 Sep 2024 17:22:22 -0300 Subject: [PATCH 3/7] =?UTF-8?q?Refatorar=20texto=20dos=20bot=C3=B5es=20de?= =?UTF-8?q?=20login=20e=20registro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/app/login/login_page.dart | 2 +- lib/src/app/register/register_page.dart | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/app/login/login_page.dart b/lib/src/app/login/login_page.dart index 219d8b6..0542869 100644 --- a/lib/src/app/login/login_page.dart +++ b/lib/src/app/login/login_page.dart @@ -205,7 +205,7 @@ class LoginPageState extends State { } }, child: const Text( - 'Login', + 'Logar', style: TextStyle( fontSize: 18.0, // Tamanho do texto fontWeight: FontWeight.w900, // Deixa o texto em negrito diff --git a/lib/src/app/register/register_page.dart b/lib/src/app/register/register_page.dart index 859cbb2..e96e639 100644 --- a/lib/src/app/register/register_page.dart +++ b/lib/src/app/register/register_page.dart @@ -260,9 +260,9 @@ class RegisterPageState extends State { } }, child: const Text( - 'Register', + 'Cadastrar', style: TextStyle( - fontSize: 18.0, // Tamanho do texto + fontSize: 12.0, // Tamanho do texto fontWeight: FontWeight.w900, // Deixa o texto em negrito ), ), From f154b65c354ae82c40114ea5462be52d265e7057 Mon Sep 17 00:00:00 2001 From: Polabiel Date: Wed, 11 Sep 2024 17:22:25 -0300 Subject: [PATCH 4/7] =?UTF-8?q?Refatorar=20servi=C3=A7o=20de=20armazenamen?= =?UTF-8?q?to=20local=20compartilhado=20e=20adicionar=20funcionalidade=20d?= =?UTF-8?q?e=20navega=C3=A7=C3=A3o=20para=20a=20p=C3=A1gina=20do=20carrinh?= =?UTF-8?q?o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/components/header_bar.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/components/header_bar.dart b/lib/src/components/header_bar.dart index afd4515..2d3275c 100644 --- a/lib/src/components/header_bar.dart +++ b/lib/src/components/header_bar.dart @@ -1,6 +1,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:gohealth/api/services/shared_local_storage_service.dart'; +import 'package:gohealth/src/app/home/cart/cart_page.dart'; class HeaderBarState extends StatefulWidget implements PreferredSizeWidget { const HeaderBarState({super.key}); @@ -85,7 +86,8 @@ class _HeaderBarState extends State { ), actions: [ IconButton(onPressed: () { - // Função para carrinho + Navigator.pushReplacement( + context, MaterialPageRoute(builder: (BuildContext context) => const CartPage())); }, icon: const Icon(Icons.shopping_cart)), IconButton( icon: const Icon(Icons.notifications), From 42d86abc5c4aa058e41b691e8cc32b753bee6d66 Mon Sep 17 00:00:00 2001 From: Polabiel Date: Wed, 11 Sep 2024 17:41:18 -0300 Subject: [PATCH 5/7] =?UTF-8?q?Refatorar=20servi=C3=A7o=20de=20armazenamen?= =?UTF-8?q?to=20local=20compartilhado=20e=20adicionar=20funcionalidade=20d?= =?UTF-8?q?e=20limpar=20carrinho?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/api/services/shared_local_storage_service.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/api/services/shared_local_storage_service.dart b/lib/api/services/shared_local_storage_service.dart index c0992dd..5355e71 100644 --- a/lib/api/services/shared_local_storage_service.dart +++ b/lib/api/services/shared_local_storage_service.dart @@ -132,4 +132,11 @@ class SharedLocalStorageService implements ILocalStorage { value.setString('products', jsonEncode(list)); }); } + + void clearCart() { + var shared = SharedPreferences.getInstance(); + shared.then((value) { + value.remove('products'); + }); + } } From c2d7048bbf589bf056fd36d6d741c94c5b7a5b7f Mon Sep 17 00:00:00 2001 From: Polabiel Date: Wed, 11 Sep 2024 17:41:36 -0300 Subject: [PATCH 6/7] =?UTF-8?q?Refatorar=20navega=C3=A7=C3=A3o=20para=20ev?= =?UTF-8?q?itar=20substitui=C3=A7=C3=A3o=20de=20telas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/app/login/login_page.dart | 2 +- lib/src/app/register/register_page.dart | 2 +- lib/src/app/sessions/final_session.dart | 6 +++--- lib/src/app/sessions/first_session.dart | 2 +- lib/src/app/sessions/second_session.dart | 4 ++-- lib/src/app/splash_page.dart | 6 +++--- lib/src/components/header_bar.dart | 2 +- lib/src/components/side_menu.dart | 6 +++--- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/src/app/login/login_page.dart b/lib/src/app/login/login_page.dart index 0542869..442a514 100644 --- a/lib/src/app/login/login_page.dart +++ b/lib/src/app/login/login_page.dart @@ -187,7 +187,7 @@ class LoginPageState extends State { print(user.toJson()); } - await Navigator.pushReplacement( + await Navigator.push( context, MaterialPageRoute( builder: (context) => const SplashPage(), diff --git a/lib/src/app/register/register_page.dart b/lib/src/app/register/register_page.dart index e96e639..fdd55a5 100644 --- a/lib/src/app/register/register_page.dart +++ b/lib/src/app/register/register_page.dart @@ -235,7 +235,7 @@ class RegisterPageState extends State { print(user.toJson()); } - await Navigator.pushReplacement( + await Navigator.push( context, MaterialPageRoute( builder: (context) => const SplashPage(), diff --git a/lib/src/app/sessions/final_session.dart b/lib/src/app/sessions/final_session.dart index 40e1fc6..3b34d44 100644 --- a/lib/src/app/sessions/final_session.dart +++ b/lib/src/app/sessions/final_session.dart @@ -48,7 +48,7 @@ class FinalSessionState extends State { children: [ TextButton( onPressed: () { - Navigator.pushReplacement( + Navigator.push( context, MaterialPageRoute( builder: (context) => const SecondSessionPage())); @@ -92,7 +92,7 @@ class FinalSessionState extends State { ), TextButton( onPressed: () { - Navigator.pushReplacement( + Navigator.push( context, MaterialPageRoute( builder: (context) => const FinalSessionPage())); @@ -135,7 +135,7 @@ class FinalSessionState extends State { onPressed: () => { for (var item in itemSelected) {_viewModel.addProductInUser(item, _id!)}, - Navigator.pushReplacement( + Navigator.push( context, MaterialPageRoute( builder: (context) => const Homepage())) diff --git a/lib/src/app/sessions/first_session.dart b/lib/src/app/sessions/first_session.dart index be09bb0..eb8ff01 100644 --- a/lib/src/app/sessions/first_session.dart +++ b/lib/src/app/sessions/first_session.dart @@ -48,7 +48,7 @@ class FirstSessionState extends State { ), TextButton( onPressed: () { - Navigator.pushReplacement( + Navigator.push( context, MaterialPageRoute( builder: (context) => const SecondSessionPage())); diff --git a/lib/src/app/sessions/second_session.dart b/lib/src/app/sessions/second_session.dart index 9131f6b..755ccea 100644 --- a/lib/src/app/sessions/second_session.dart +++ b/lib/src/app/sessions/second_session.dart @@ -18,7 +18,7 @@ class SecondSessionState extends State { children: [ TextButton( onPressed: () { - Navigator.pushReplacement( + Navigator.push( context, MaterialPageRoute( builder: (context) => const FirstSessionPage())); @@ -63,7 +63,7 @@ class SecondSessionState extends State { ), TextButton( onPressed: () { - Navigator.pushReplacement( + Navigator.push( context, MaterialPageRoute( builder: (context) => const FinalSessionPage())); diff --git a/lib/src/app/splash_page.dart b/lib/src/app/splash_page.dart index 98b77c6..a682c75 100644 --- a/lib/src/app/splash_page.dart +++ b/lib/src/app/splash_page.dart @@ -37,14 +37,14 @@ class SplashPageState extends State { Future.delayed(const Duration(seconds: 2), () { if (isLogged) { if (isFirstSession) { - Navigator.pushReplacement( + Navigator.push( context, MaterialPageRoute( builder: (context) => const FirstSessionPage(), ), ); } else { - Navigator.pushReplacement( + Navigator.push( context, MaterialPageRoute( builder: (context) => const Homepage(), @@ -52,7 +52,7 @@ class SplashPageState extends State { ); } } else { - Navigator.pushReplacement( + Navigator.push( context, MaterialPageRoute( builder: (context) => const LoginPage(), diff --git a/lib/src/components/header_bar.dart b/lib/src/components/header_bar.dart index 2d3275c..29ed641 100644 --- a/lib/src/components/header_bar.dart +++ b/lib/src/components/header_bar.dart @@ -86,7 +86,7 @@ class _HeaderBarState extends State { ), actions: [ IconButton(onPressed: () { - Navigator.pushReplacement( + Navigator.push( context, MaterialPageRoute(builder: (BuildContext context) => const CartPage())); }, icon: const Icon(Icons.shopping_cart)), IconButton( diff --git a/lib/src/components/side_menu.dart b/lib/src/components/side_menu.dart index e256fc4..e5f2fb2 100644 --- a/lib/src/components/side_menu.dart +++ b/lib/src/components/side_menu.dart @@ -67,7 +67,7 @@ class SideMenuState extends State { ListTile( title: const Text('Tela Inicial', style: textStyle), onTap: () { - Navigator.pushReplacement( + Navigator.push( context, MaterialPageRoute( builder: (BuildContext context) => const Homepage())); @@ -88,7 +88,7 @@ class SideMenuState extends State { ListTile( title: const Text('Maps', style: textStyle), onTap: () async { - Navigator.pushReplacement( + Navigator.push( context, MaterialPageRoute( builder: (BuildContext context) => const MapsPage())); @@ -101,7 +101,7 @@ class SideMenuState extends State { await prefs.logout(); _repository.clearProfile(); - Navigator.pushReplacement( + Navigator.push( context, MaterialPageRoute( builder: (BuildContext context) => const SplashPage())); From 0b5b8939cb20cb7513719cc523c6779f66237c3d Mon Sep 17 00:00:00 2001 From: Polabiel Date: Wed, 11 Sep 2024 17:44:21 -0300 Subject: [PATCH 7/7] =?UTF-8?q?Refatorar=20navega=C3=A7=C3=A3o=20para=20ev?= =?UTF-8?q?itar=20substitui=C3=A7=C3=A3o=20de=20telas=20e=20adicionar=20fu?= =?UTF-8?q?ncionalidade=20de=20limpar=20carrinho=20e=20navegar=20para=20a?= =?UTF-8?q?=20p=C3=A1gina=20do=20carrinho?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/app/home/cart/cart_page.dart | 90 ++++++++++++++++--- .../app/sessions/products/product_page.dart | 8 ++ 2 files changed, 87 insertions(+), 11 deletions(-) diff --git a/lib/src/app/home/cart/cart_page.dart b/lib/src/app/home/cart/cart_page.dart index bdd4caf..3ca651d 100644 --- a/lib/src/app/home/cart/cart_page.dart +++ b/lib/src/app/home/cart/cart_page.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:gohealth/api/models/product_models.dart'; import 'package:gohealth/api/services/shared_local_storage_service.dart'; +import 'package:gohealth/src/app/home/home_page.dart'; +import 'package:gohealth/src/app/sessions/products/product_page.dart'; import 'package:gohealth/src/components/header_bar.dart'; import 'package:gohealth/src/components/side_menu.dart'; @@ -18,36 +20,102 @@ class _CartPageState extends State { return Scaffold( appBar: const HeaderBarState(), drawer: const SideMenu(), + bottomNavigationBar: Padding( + padding: const EdgeInsets.all(8.0), + child: FutureBuilder>( + future: SharedLocalStorageService().getAllProducts(), + builder: (context, snapshot) { + if (!snapshot.hasData || snapshot.data!.isEmpty) { + return const SizedBox.shrink(); + } else { + final total = snapshot.data!.fold( + 0.0, + (sum, item) => sum + (item.price ?? 0.0), + ); + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + ElevatedButton( + onPressed: () { + SharedLocalStorageService().clearCart(); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text('Pedido finalizado com sucesso'), + backgroundColor: Colors.green, + duration: Duration(seconds: 2), + ), + ); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const Homepage())); + setState(() {}); + }, + child: const Text( + 'Finalizar Pedido', + style: TextStyle(color: Colors.white), + ), + style: ElevatedButton.styleFrom( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(6), + ), + backgroundColor: Colors.green, + ), + ), + Text( + 'Total: R\$${total.toStringAsFixed(2)}', + style: const TextStyle( + fontSize: 18, fontWeight: FontWeight.bold), + ), + ], + ); + } + }, + ), + ), body: FutureBuilder>( future: SharedLocalStorageService().getAllProducts(), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return const Center(child: CircularProgressIndicator()); + } else if (!snapshot.hasData || snapshot.data!.isEmpty) { + return const Center(child: Text('Nenhum produto no carrinho')); } else if (snapshot.hasError) { return Center(child: Text('Error: ${snapshot.error}')); - } else if (!snapshot.hasData || snapshot.data!.isEmpty) { - return const Center(child: Text('No items selected.')); } else { return ListView.builder( itemCount: snapshot.data!.length, itemBuilder: (context, index) { final product = snapshot.data![index]; - return Card( + return GestureDetector( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + ProductPage(productModels: snapshot.data![index]), + ), + ); + }, + child: Card( margin: const EdgeInsets.all(10.0), child: ListTile( leading: Image.network(product.image ?? "https://via.placeholder.com/150", width: 50, height: 50, fit: BoxFit.cover), title: Text(product.name!), - subtitle: Text('Price: \$${product.price!.toStringAsFixed(2)}'), + subtitle: Text( + 'Preço: R\$${product.price!.toStringAsFixed(2)}'), trailing: IconButton( - icon: const Icon(Icons.delete), - onPressed: () { - setState(() { - snapshot.data!.removeAt(index); - SharedLocalStorageService().removeProduct(product.id); - }); - }, + icon: const Icon(Icons.delete), + onPressed: () { + setState(() { + snapshot.data!.removeAt(index); + SharedLocalStorageService() + .removeProduct(product.id); + }); + }, ), ), + ), ); }, ); diff --git a/lib/src/app/sessions/products/product_page.dart b/lib/src/app/sessions/products/product_page.dart index 333111e..8f2d814 100644 --- a/lib/src/app/sessions/products/product_page.dart +++ b/lib/src/app/sessions/products/product_page.dart @@ -48,6 +48,14 @@ class ProductState extends State { onPressed: () { // Salvar os dados do produto no carrinho atráves do storage SharedLocalStorageService().saveProduct(widget.productModels); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text('Produto adicionado ao carrinho'), + backgroundColor: Colors.green, + duration: Duration(seconds: 2), + ), + ); + Navigator.pop(context); }, child: Text('Adicionar ao carrinho'), style: ElevatedButton.styleFrom(