Flutter
Flutter is an open-source UI software development kit created by Google. It is used to develop cross-platform applications.

Let's Get your Flutter App running with SAWO
πŸ™Œ

Steps:

1. To get started with the integration of SAWO API on your Flutter App, add the plugin in dependencies:
1
dependencies:
2
sawo: ^0.1.2
Copied!
2. After this, install the plugin, by running the mentioned command:
1
flutter pub get
Copied!
3. As part of the next step, import the plugin into class by using the code given below:
1
import 'package:sawo/sawo.dart';
Copied!
4. To use SAWO Login you would need an API key which can be obtained by creating a project in the sawo dashboard.
5. Once you create your project, you would need to set your project name.
6. Copy the API key from the project and keep it safe and secure.
It is always recommended to store your apiKey and secretKey in a .env file. Otherwise, create a separate .dart file and add it to the .gitignore. Just make sure that you are not exposing the keys publicly and also add them to the .gitignore before pushing the project to a public repo.
7. Next, create a Sawo Instance
1
Sawo sawo = new Sawo(
2
apiKey: <YOUR-API-KEY>,
3
secretKey: <YOUR-Secret-Key>,
4
);
Copied!
8. Use the following code to redirect the user to the login page.
SAWO provides two ways to authenticate users, one by email and one by phone number.
1
// sawo object
2
Sawo sawo = Sawo(
3
apiKey: "Your API Key",
4
secretKey: "Your Secret key",
5
);
6
​
7
// user payload
8
String user = "";
9
​
10
void payloadCallback(context, payload) {
11
if (payload == null || (payload is String && payload.length == 0)) {
12
payload = "Login Failed :(";
13
}
14
setState(() {
15
user = payload;
16
});
17
}
18
​
19
@override
20
Widget build(BuildContext context) {
21
return Center(
22
child: Padding(
23
padding: const EdgeInsets.symmetric(horizontal: 20),
24
child: Column(
25
mainAxisAlignment: MainAxisAlignment.center,
26
children: [
27
Text("UserData :- $user"),
28
ElevatedButton(
29
onPressed: () {
30
sawo.signIn(
31
context: context,
32
identifierType: 'email',
33
callback: payloadCallback,
34
);
35
},
36
child: Text('Email Login'),
37
),
38
ElevatedButton(
39
onPressed: () {
40
sawo.signIn(
41
context: context,
42
identifierType: 'phone_number_sms',
43
callback: payloadCallback,
44
);
45
},
46
child: Text('Phone Login'),
47
),
48
],
49
),
50
),
51
);
52
}
53
​
Copied!
When a user is successfully verified, the callback method will get invoked with the payload which contains userID and when something is wrong the payload will be null.
Once the SAWO SDK is successfully set up, a login form will be rendered in the provided container as displayed in the picture below:
Final Render of SAWO Login
Congratulations !! The SAWO API is now ready to be used in your Flutter application 🀘.

You can also check out SAWO's Flutter Sample Code.

It's okay, we get it! You got Stuck!
😞
Feel free to contact us on #ask-for-help on our Discord​

Last modified 2mo ago