Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. WishlistSource ws = WishlistSource();
  2. bool _isFavorite = false;
  3.  
  4. toogleWishlist() async {
  5. bool isFavorite = await ws.isWishlist(widget.products.code);
  6. setState(() => _isFavorite = isFavorite);
  7. }
  8.  
  9. @override
  10. void initState() {
  11. toogleWishlist();
  12. super.initState();
  13. }
  14.  
  15.  
  16.  
  17. Widget _favorite() {
  18. return Positioned(
  19. right: 4.0,
  20. bottom: 4.0,
  21. child: Material(
  22. elevation: 1.0,
  23. clipBehavior: Clip.antiAliasWithSaveLayer,
  24. shape: CircleBorder(),
  25. color: Colors.white.withOpacity(0.95),
  26. child: IconButton(
  27. // color: _isFavorite ? Colors.red : ThemeApp.registerButton,
  28. icon: Icon(_isFavorite ? Icons.favorite : Icons.favorite_border),
  29. onPressed: () async {
  30. try {
  31. await ws.toggle(widget.products);
  32. await toogleWishlist();
  33. print('data $toogleWishlist');
  34. print('masuk ${widget.products}');
  35. } catch (e) {
  36. print(e);
  37. }
  38. setState(() {
  39. _isFavorite = _isFavorite ? false : true;
  40. });
  41. },
  42. ),
  43. ),
  44. );
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement