Skip to main content

Adding Login Functionality

Premium
5 min read

Now that we have a Registration form, we need our users to be able to log inLogin:

Here's what we need to do:

  1. We must install a device_info_plus package to get Device information.
  2. We need a login() function on our Auth Provider.
  3. We need to add a Login form.

Installing New Package

First, we will need a package to be installed...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 41 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

LA
Luis Antonio Parrado ✓ Link copied!

I got some compatibility issues with the device_info_plus package and the Android NDK version, to be specific this was the error message:

Your project is configured with Android NDK 26.3.11579264, but the following plugin(s) depend on a different Android NDK version:
- device_info_plus requires Android NDK 27.0.12077973
Fix this issue by using the highest Android NDK version (they are backward compatible).
Add the following to C:\Users\luisp\Documents\develop\projects\mobile\flutter\<my-project>\android\app\build.gradle.kts:
 
android {
ndkVersion = "27.0.12077973"
...
}

My Solution Change the Android NDK version directly in the Flutter SDK, right in the file:

<flutter-sdk-path>\packages\flutter_tools\gradle\src\main\groovy\flutter.groovy

searching the line

public final String ndkVersion = "26.3.11579264"

and replace it by

public final String ndkVersion = "27.0.12077973"
MK
Matthew Kille ✓ Link copied!

What's the 'best practice' robust means of dealing with the login response status code outside of the 200 or 422 handled here? At the moment it seems any error code will result in the response.body being returned as if it were a valid API token.

Is this enough?

if (response.statusCode != 200) {
throw Exception('Unexpected error ${response.statusCode}');
}
M
Modestas ✓ Link copied!

It really depends on what you want to handle. For generic handling of an issue - this is fine.

But in case you want to handle things in a graceful way - you need to handle each status individually. And that could add a lot of work (no automation or handle all), but it gives a nicer user experience.

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.