Skip to content

Commit c6a26f3

Browse files
committed
add ability to remove the current product
1 parent e497dd8 commit c6a26f3

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

lib/api_connection.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,18 @@ class APIConnection {
9191
}
9292

9393
// Remove product from database
94-
Future<void> removeProduct(String name) async {
94+
Future<void> removeCurrentProduct() async {
9595
final response = await http.delete(
96-
Uri.parse('$baseUrl/products/$name'),
96+
Uri.parse('$baseUrl/products/$selectedCategory'),
9797
headers: <String, String>{
9898
'Content-Type': 'application/json; charset=UTF-8',
9999
},
100100
);
101-
102101
if (response.statusCode != 200) {
103102
throw Exception('Failed to remove product');
104103
}
104+
105+
categories = fetchCategories();
106+
await categories;
105107
}
106108
}

lib/product_search.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,23 @@ class _ProductSearchState extends State<ProductSearch> {
8989
child: const Text('Add Product'),
9090
),
9191
),
92+
Padding(
93+
padding: const EdgeInsets.all(8.0),
94+
child: ElevatedButton(
95+
onPressed: () {
96+
GetIt.I.get<APIConnection>().removeCurrentProduct().then(
97+
(value) {
98+
ScaffoldMessenger.of(context).showSnackBar(
99+
const SnackBar(
100+
content: Text('Removed current product'),
101+
),
102+
);
103+
},
104+
);
105+
},
106+
child: const Text('Remove current Product'),
107+
),
108+
)
92109
],
93110
),
94111
);

0 commit comments

Comments
 (0)