delete_member.dart 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // ignore_for_file: use_build_context_synchronously
  2. import 'dart:convert';
  3. import 'package:dio/dio.dart';
  4. import 'package:flutter/material.dart';
  5. import '../globals.dart';
  6. Future<void> delmember(BuildContext context, int id) async{
  7. final dio = Dio();
  8. Response response;
  9. AlertDialog alert = AlertDialog(
  10. title: Text("Delete Sukses"),
  11. content: Text("Data terhapus"),
  12. actions: [
  13. TextButton(
  14. child: Text('Ok'),
  15. onPressed: () => Navigator.of(context).pop(),
  16. ),
  17. ],
  18. );
  19. AlertDialog alert2 = AlertDialog(
  20. title: Text("Delete Gagal"),
  21. content: Text("Data Invalid"),
  22. actions: [
  23. TextButton(
  24. child: Text('Ok'),
  25. onPressed: () => Navigator.of(context).pop(),
  26. ),
  27. ],
  28. );
  29. var auth = 'Basic ${base64Encode(utf8.encode('$USER_LOGIN:$PASS_LOGIN'))}';
  30. Map<String, String> headers = {
  31. 'content-type': 'application/json',
  32. 'accept': 'application/json',
  33. 'authorization': auth
  34. };
  35. try {
  36. response = await dio.delete("http://localhost:8080/api/v1/projects/member/$id",
  37. options: Options(headers: headers)
  38. );
  39. if(response.statusCode == 200){
  40. showDialog(context: context, builder: (context) => alert);
  41. }
  42. } catch (error){
  43. showDialog(context: context, builder: (context) => alert2);
  44. }
  45. }