Skip to content

Commit

Permalink
refactor: replaced profile dropdown with profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
SethCohen committed Mar 13, 2023
1 parent b145354 commit 95b2f74
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 97 deletions.
71 changes: 8 additions & 63 deletions src/lib/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:asl/pages/creator_page.dart';
import 'package:asl/pages/dictionary_page.dart';
import 'package:asl/pages/lessons_page.dart';
import 'package:asl/pages/manage_page.dart';
import 'package:asl/pages/review_page.dart';
import 'package:asl/providers/google_provider.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
Expand All @@ -27,6 +28,7 @@ class _HomePageState extends State<HomePage> {
DictionaryPage(),
ReviewPage(),
CreatorPage(),
ManagePage(),
];

@override
Expand Down Expand Up @@ -112,76 +114,19 @@ class _HomePageState extends State<HomePage> {
),
),
),
// TODO replace with ManagePage()
PopupMenuButton(
IconButton(
icon: CircleAvatar(
backgroundImage: NetworkImage(user.photoURL!),
),
itemBuilder: (context) => [
PopupMenuItem(
child: TextButton(
onPressed: _signOut,
child: const Text('Sign Out'),
),
),
PopupMenuItem(
child: TextButton(
onPressed: _deleteAccount,
child: const Text('Delete Account'),
),
),
],
onPressed: () {
setState(() {
_selectedIndex = 4;
});
},
),
],
),
body: _widgetPages.elementAt(_selectedIndex)),
);
}

void _signOut() {
final provider = Provider.of<GoogleSignInProvider>(context, listen: false);
provider.googleLogout();
Navigator.pop(context);
}

void _deleteAccount() {
showDialog<String>(
context: context,
builder: (BuildContext context) => AlertDialog(
backgroundColor: Colors.grey.shade900,
title: const Text('Are You Sure?',
style: TextStyle(color: Colors.white)),
content: const Text(
'You\'re trying to delete your account.\nYour account and data will be deleted immediately. This action is not reversible.\nPlease hold YES to confirm.'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context),
style:
const ButtonStyle(splashFactory: NoSplash.splashFactory),
child: const Text('Cancel',
style: TextStyle(color: Colors.white)),
),
TextButton(
onLongPress: () {
FirebaseAuth.instance.currentUser!.delete();
final provider = Provider.of<GoogleSignInProvider>(context,
listen: false);
provider.googleLogout();
Navigator.pop(context);

const snackBar = SnackBar(
content: Text('Account Deleted'),
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);

Navigator.pop(context);
},
onPressed: () {},
child:
const Text('Yes', style: TextStyle(color: Colors.white)),
),
],
));
}
}
60 changes: 26 additions & 34 deletions src/lib/pages/manage_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,33 @@ class ManagePage extends StatefulWidget {
class _ManagePageState extends State<ManagePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Manage Account'),
),
body: Padding(
padding: const EdgeInsets.fromLTRB(48.0, 8.0, 8.0, 8.0),
child: ListView(
children: [
TextButton(
style: TextButton.styleFrom(
foregroundColor: Colors.white70,
alignment: Alignment.centerLeft,
textStyle: const TextStyle(fontWeight: FontWeight.bold),
),
onPressed: _signOut,
child: const Text(
'Sign Out',
textScaleFactor: 1.05,
),
),
TextButton(
style: TextButton.styleFrom(
foregroundColor: Colors.white70,
alignment: Alignment.centerLeft,
textStyle: const TextStyle(fontWeight: FontWeight.bold),
),
onPressed: _deleteAccount,
child: const Text(
'Delete Account',
textScaleFactor: 1.05,
),
),
],
return ListView(
children: [
TextButton(
style: TextButton.styleFrom(
foregroundColor: Colors.white70,
alignment: Alignment.centerLeft,
textStyle: const TextStyle(fontWeight: FontWeight.bold),
),
onPressed: _signOut,
child: const Text(
'Sign Out',
textScaleFactor: 1.05,
),
),
),
TextButton(
style: TextButton.styleFrom(
foregroundColor: Colors.white70,
alignment: Alignment.centerLeft,
textStyle: const TextStyle(fontWeight: FontWeight.bold),
),
onPressed: _deleteAccount,
child: const Text(
'Delete Account',
textScaleFactor: 1.05,
),
),
],
);
}

Expand Down

0 comments on commit 95b2f74

Please sign in to comment.