A complete Flutter app that uses smart_refresh_token with:
SecureTokenStorage(lib/secure_token_storage.dart), built onflutter_secure_storage. Copy it into your app.- A
StreamBuilderonauth.authStatusthat switches between the logged-in and logged-out UI. TokenRefreshLifecycleObserver, which refreshes on app resume.- An in-app fake server (
lib/fake_server.dart), so it runs offline on Android, iOS, macOS, Windows, Linux and web.
flutter runTry it:
- Log in.
- Expire access token (server side), then 10 parallel requests. The
log shows
10 succeeded, 1 refresh call(s). - Wait about 20 seconds: the token is refreshed proactively before the next request.
- Revoke refresh token, Expire access token, then GET /me. The session ends and the UI switches back to logged out.
To use a real backend, delete fake_server.dart and the
httpClientAdapter = server line in main.dart, then point baseUrl at your
API.