addbug_serv.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 'package:go_router/go_router.dart';
  6. import '../globals.dart';
  7. Future<void> addbug(BuildContext context, String desc, String qc, String dev, String platform, String goodday, String image, String level, String status, String devStatus /*Map data*/) async {
  8. final dio = Dio();
  9. Response response;
  10. AlertDialog alert2 = AlertDialog(
  11. title: Text("Add Bug Gagal"),
  12. content: Text("Data Invalid"),
  13. actions: [
  14. TextButton(
  15. child: Text('Ok'),
  16. onPressed: () => Navigator.of(context).pop(),
  17. ),
  18. ],
  19. );
  20. var auth = 'Basic ${base64Encode(utf8.encode('$USER_LOGIN:$PASS_LOGIN'))}';
  21. Map<String, String> headers = {
  22. 'content-type': 'application/json',
  23. 'accept': 'application/json',
  24. 'authorization': auth
  25. };
  26. try{
  27. response = await dio.post("http://localhost:8080/api/v1/bugs",
  28. options: Options(headers: headers),
  29. data:
  30. // data
  31. {'description':desc, 'qc': qc, 'dev': dev, 'platform':platform, 'goodday_url':goodday, 'image_url':image, 'level':level, 'status':status, 'dev_status':devStatus}
  32. );
  33. if (response.statusCode == 201){
  34. return context.go('/listbug');
  35. }
  36. } catch (error){
  37. showDialog(context: context, builder: (context) => alert2);
  38. }
  39. }