Flutter + Django + Rest Framework

Flutter + Django + Rest Framework

So a few days ago I made Yet Another Flutter Login (YAFL) which is a nice little starter for working with Firebase login. Sometimes though I like to fall back to good ol’ Django and Python so I did a little refactoring of YAFL, threw together a django server and made Flutter DRF. The only real changes from YAFL is how it connects using the excellent http and retry packages.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
final resp = await retry(
() async {
final response = await client
.post('$baseUrl$loginUrl', body: loginToJson(login), headers: {}..addAll(jsonHeader()))
.timeout(Duration(seconds: 5));
return response;
},
retryIf: (e) => e is SocketException || e is TimeoutException,
);
if (resp.statusCode == 200) {
var jsonResponse = json.decode(resp.body);
_token = jsonResponse['key'];
await storage.write(key: 'token', value: _token);
_isSignedIn = true;
prefs.setString('email', email);
} else {
caughtExc(resp.body.toString());
signout();
}

On the server side there is quite a lot of boilerplate to write so I opted to get up and running quickly with cookiecutter-django and django-rest-auth the result of which you can find at flutter_drf_django.

Hope it’s useful to someone else and if you have any feedback, please let me know :)

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×