-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from gohealthnow/18-pagamento-e-exibio-de-paga…
…mento Pagamento e exibição de pagamento
- Loading branch information
Showing
12 changed files
with
226 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
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'; | ||
|
||
class CartPage extends StatefulWidget { | ||
const CartPage({ Key? key }) : super(key: key); | ||
|
||
@override | ||
_CartPageState createState() => _CartPageState(); | ||
} | ||
|
||
class _CartPageState extends State<CartPage> { | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: const HeaderBarState(), | ||
drawer: const SideMenu(), | ||
bottomNavigationBar: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: FutureBuilder<List<ProductModels>>( | ||
future: SharedLocalStorageService().getAllProducts(), | ||
builder: (context, snapshot) { | ||
if (!snapshot.hasData || snapshot.data!.isEmpty) { | ||
return const SizedBox.shrink(); | ||
} else { | ||
final total = snapshot.data!.fold<double>( | ||
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<List<ProductModels>>( | ||
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 { | ||
return ListView.builder( | ||
itemCount: snapshot.data!.length, | ||
itemBuilder: (context, index) { | ||
final product = snapshot.data![index]; | ||
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( | ||
'Preço: R\$${product.price!.toStringAsFixed(2)}'), | ||
trailing: IconButton( | ||
icon: const Icon(Icons.delete), | ||
onPressed: () { | ||
setState(() { | ||
snapshot.data!.removeAt(index); | ||
SharedLocalStorageService() | ||
.removeProduct(product.id); | ||
}); | ||
}, | ||
), | ||
), | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
}, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.