Commit 79c9cf73 authored by Ilham Maulana's avatar Ilham Maulana 💻

feat: loading on login submit

parent 34821612
......@@ -36,9 +36,13 @@ class AuthProvider with ChangeNotifier {
return await storage.read(key: 'access_token');
}
void setLoading(bool value) {
isLoading = value;
}
Future<void> signIn(String username, String password) async {
isLoading = true;
try {
setLoading(true);
final response = await http.post(
Uri.parse('$baseUrl/auth/login'),
body: jsonEncode({'username': username, 'password': password}),
......@@ -62,7 +66,7 @@ class AuthProvider with ChangeNotifier {
debugPrint("Login failed $code");
}
isLoading = false;
setLoading(false);
notifyListeners();
} catch (error) {
debugPrint("Login failed $error");
......
......@@ -133,7 +133,16 @@ class _LoginForm extends State<LoginForm> {
passwordController.text,
);
},
child: const Text("Submit"),
child: authProvider.isLoading
? const SizedBox(
width: 20.0,
height: 20.0,
child: CircularProgressIndicator(
color: Colors.white,
strokeWidth: 3.0,
),
)
: const Text("Submit"),
),
),
SizedBox(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment