-
-
Save fabiojansenbr/4bfdb89a6093437ad225679963ef94ef to your computer and use it in GitHub Desktop.
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
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:get_it/get_it.dart'; | |
import 'package:shared_preferences/shared_preferences.dart'; | |
import 'package:supabase/supabase.dart'; | |
class SplashView extends StatefulWidget { | |
const SplashView({Key? key}) : super(key: key); | |
@override | |
_SplashViewState createState() => _SplashViewState(); | |
} | |
class _SplashViewState extends State<SplashView> { | |
@override | |
void initState() { | |
super.initState(); | |
checkLogin(); | |
} | |
void checkLogin() async { | |
final sharedPreferences = await SharedPreferences.getInstance(); | |
final session = sharedPreferences.getString('user'); | |
if (session == null) { | |
Navigator.pushReplacementNamed(context, '/login'); | |
} else { | |
final response = | |
await GetIt.instance<SupabaseClient>().auth.recoverSession(session); | |
sharedPreferences.setString('user', response.data!.persistSessionString); | |
Navigator.pushReplacementNamed(context, '/home'); | |
} | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: CupertinoActivityIndicator(), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment