Skip to content

Instantly share code, notes, and snippets.

@fabiojansenbr
Created June 14, 2021 16:37
Show Gist options
  • Save fabiojansenbr/7f6afe40e12de468f07cac5828069f0a to your computer and use it in GitHub Desktop.
Save fabiojansenbr/7f6afe40e12de468f07cac5828069f0a to your computer and use it in GitHub Desktop.
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