123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- // ignore_for_file: use_build_context_synchronously
- import 'dart:convert';
- import 'package:dio/dio.dart';
- import 'package:flutter/material.dart';
- import '../globals.dart';
- Future<void> edit(BuildContext context, int id, String username, String name) async{
- final dio = Dio();
- Response response;
- AlertDialog alert = AlertDialog(
- title: Text("Edit Sukses"),
- content: Text("Data teredit"),
- actions: [
- TextButton(
- child: Text('Ok'),
- onPressed: () => Navigator.of(context).pop(),
- ),
- ],
- );
- AlertDialog alert2 = AlertDialog(
- title: Text("Edit Gagal"),
- content: Text("Data Invalid"),
- actions: [
- TextButton(
- child: Text('Ok'),
- onPressed: () => Navigator.of(context).pop(),
- ),
- ],
- );
- var auth = 'Basic ${base64Encode(utf8.encode('$USER_LOGIN:$PASS_LOGIN'))}';
- Map<String, String> headers = {
- 'content-type': 'application/json',
- 'accept': 'application/json',
- 'authorization': auth
- };
- try {
- response = await dio.put("http://localhost:8080/api/v1/users/$id",
- options: Options(headers: headers),
- data: {'username':username, 'name':name}
- );
- print(response);
- if(response.statusCode == 200){
- showDialog(context: context, builder: (context) => alert);
-
- }
- } catch (error){
- showDialog(context: context, builder: (context) => alert2);
- }
- }
|