Created
July 21, 2022 17:38
-
-
Save rizkyhaksono/f23f0d3c4f57cccef063dd543a246d3b to your computer and use it in GitHub Desktop.
Login Method with API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var usernameController = TextEditingController(); | |
var passwordController = TextEditingController(); | |
Future<void> loginMethod() async { | |
if (usernameController.text.isNotEmpty && passwordController.text.isNotEmpty) { | |
var response = await http.post( | |
Uri.parse( | |
// your API | |
""), | |
body: ({ | |
'username': usernameController.text, | |
'password': passwordController.text, | |
}), | |
); | |
if (response.statusCode == 200) { | |
// check the response | |
print("Response Status: ${response.statusCode}"); | |
} else { | |
// ignore: use_build_context_synchronously | |
ScaffoldMessenger.of(context).showSnackBar( | |
const SnackBar(content: Text("Your data is incorrect!"))); | |
} | |
} else { | |
ScaffoldMessenger.of(context).showSnackBar( | |
const SnackBar(content: Text("Username and password must be written!"))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment