-
-
Save fabiojansenbr/7f6afe40e12de468f07cac5828069f0a 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
title="home_view.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 HomeView extends StatefulWidget { | |
const HomeView({Key? key}) : super(key: key); | |
@override | |
_HomeViewState createState() => _HomeViewState(); | |
} | |
class _HomeViewState extends State<HomeView> { | |
@override | |
Widget build(BuildContext context) { | |
final currentUser = GetIt.instance<SupabaseClient>().auth.user(); | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Home'), | |
), | |
body: Container( | |
child: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
Text('Hi ${currentUser?.email}'), | |
SizedBox( | |
height: 30, | |
), | |
MaterialButton( | |
color: Colors.red, | |
onPressed: () { | |
_logout(); | |
}, | |
child: Text('Logout'), | |
) | |
], | |
), | |
), | |
), | |
); | |
} | |
_logout() async { | |
await GetIt.I.get<SupabaseClient>().auth.signOut(); | |
final sharedPreferences = await SharedPreferences.getInstance(); | |
sharedPreferences.clear(); | |
Navigator.pushReplacementNamed(context, '/'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment