// ignore_for_file: use_build_context_synchronously import 'dart:convert'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:namer_app/globals.dart' as globals; Future submit(BuildContext context, String email, String password) async { final dio = Dio(); Response response; if (email.isEmpty || password.isEmpty) { final snackBar = SnackBar( duration: const Duration(seconds: 5), content: Text("Username dan password harus diisi"), backgroundColor: Colors.red, ); ScaffoldMessenger.of(context).showSnackBar(snackBar); return; } AlertDialog alert2 = AlertDialog( title: Text("Login Gagal"), content: Text("Username atau Password salah"), actions: [ TextButton( child: Text('Ok'), onPressed: () => Navigator.of(context).pop(), ), ], ); var auth = 'Basic ${base64Encode(utf8.encode('$email:$password'))}'; Map headers = { 'content-type': 'application/json', 'accept': 'application/json', 'authorization': auth }; try{ response = await dio.get('http://localhost:8080/api/v1/users', options: Options(headers: headers)); if (response.statusCode == 200){ globals.userLogin = email; return context.go('/login/bug'); } } catch (error){ showDialog(context: context, builder: (context) => alert2);} }