import 'package:dio/dio.dart'; import 'package:server/apis/auth.dart'; import 'package:server/client.dart'; class Cart { String lastError = ''; addToCart(String productId, double count) async { try { final id = await auth.setToken(); if (id != null) { final response = await api.post( '/collections/cart/records', data: {'user_id': id, 'product_id': productId, 'count': count}, ); if (response.data != null) { return 'Well done'; } } } on DioException catch (e) { if (e.type == DioExceptionType.connectionError) { return "Internet Connection Error"; } return e.response!.data['message']; } catch (e) { print(e); return Error(); } } } final cart = Cart();