addmember_serv.dart 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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> addmember(BuildContext context, int projId, int userId, String role /*Map data*/) async {
  8. final dio = Dio();
  9. Response response;
  10. AlertDialog alert2 = AlertDialog(
  11. title: Text("Add Member 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/projects/$projId/member",
  28. options: Options(headers: headers),
  29. data:
  30. // data
  31. {'user_id':userId,'role':role}
  32. );
  33. if (response.statusCode == 201){
  34. return context.go('/listplatform/listmember');
  35. }
  36. } catch (error){
  37. showDialog(context: context, builder: (context) => alert2);
  38. }
  39. }