Move profile card to account settings
This commit is contained in:
parent
c146ac551e
commit
618dc8f07b
3 changed files with 137 additions and 141 deletions
|
|
@ -1,9 +1,9 @@
|
|||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:frosty/core/auth/auth_store.dart';
|
||||
import 'package:frosty/screens/settings/stores/settings_store.dart';
|
||||
import 'package:frosty/screens/settings/widgets/blocked_users.dart';
|
||||
import 'package:frosty/screens/settings/widgets/profile_card.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
class AccountSettings extends StatelessWidget {
|
||||
|
|
@ -54,7 +54,7 @@ class AccountSettings extends StatelessWidget {
|
|||
builder: (context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Log In to WebView'),
|
||||
title: const Text('Log in to WebView'),
|
||||
),
|
||||
body: const WebView(
|
||||
initialUrl: 'https://www.twitch.tv/login',
|
||||
|
|
@ -71,3 +71,137 @@ class AccountSettings extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ProfileCard extends StatelessWidget {
|
||||
final AuthStore authStore;
|
||||
|
||||
const ProfileCard({Key? key, required this.authStore}) : super(key: key);
|
||||
|
||||
Future<void> _showLoginDialog(BuildContext context) {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (context) => SimpleDialog(
|
||||
children: [
|
||||
ColoredBox(
|
||||
color: const Color.fromRGBO(145, 70, 255, 0.8),
|
||||
child: SimpleDialogOption(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Image.asset(
|
||||
'assets/icons/TwitchGlitchWhite.png',
|
||||
height: 25,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
const Text(
|
||||
'Connect with Twitch',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
authStore.login();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
const Center(
|
||||
child: Text(
|
||||
'Or',
|
||||
style: TextStyle(fontStyle: FontStyle.italic),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5.0),
|
||||
SimpleDialogOption(
|
||||
child: TextField(
|
||||
textAlign: TextAlign.center,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Token',
|
||||
),
|
||||
onSubmitted: (token) {
|
||||
authStore.login(customToken: token);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _showLogoutDialog(BuildContext context) {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Log Out'),
|
||||
content: const Text('Are you sure you want to log out?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: Navigator.of(context).pop,
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
authStore.logout();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('Yes'),
|
||||
style: TextButton.styleFrom(primary: Colors.red),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Observer(
|
||||
builder: (context) {
|
||||
if (authStore.error != null) {
|
||||
return ListTile(
|
||||
title: const Text('Failed to Connect'),
|
||||
trailing: OutlinedButton(
|
||||
onPressed: authStore.init,
|
||||
child: const Text('Try Again'),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (authStore.isLoggedIn && authStore.user.details != null) {
|
||||
return ListTile(
|
||||
leading: CircleAvatar(
|
||||
foregroundImage: CachedNetworkImageProvider(authStore.user.details!.profileImageUrl),
|
||||
),
|
||||
title: Text(authStore.user.details!.displayName),
|
||||
trailing: ElevatedButton.icon(
|
||||
onPressed: () => _showLogoutDialog(context),
|
||||
icon: const Icon(Icons.logout_outlined),
|
||||
label: const Text('Log Out'),
|
||||
style: ElevatedButton.styleFrom(primary: Colors.red),
|
||||
),
|
||||
);
|
||||
}
|
||||
return ListTile(
|
||||
isThreeLine: true,
|
||||
leading: const Icon(
|
||||
Icons.no_accounts,
|
||||
size: 40,
|
||||
),
|
||||
title: const Text('Anonymous User'),
|
||||
subtitle: const Text('Log in to chat, view followed streams, and more.'),
|
||||
trailing: OutlinedButton(
|
||||
onPressed: () => _showLoginDialog(context),
|
||||
child: const Text('Log In'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ class _ChatSettingsState extends State<ChatSettings> {
|
|||
width: defaultBadgeSize * settingsStore.badgeScale,
|
||||
),
|
||||
),
|
||||
const TextSpan(text: ' Badge and emote preview '),
|
||||
const TextSpan(text: ' Badge and emote preview. '),
|
||||
WidgetSpan(
|
||||
alignment: PlaceholderAlignment.middle,
|
||||
child: CachedNetworkImage(
|
||||
|
|
|
|||
|
|
@ -1,138 +0,0 @@
|
|||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
import 'package:frosty/core/auth/auth_store.dart';
|
||||
|
||||
class ProfileCard extends StatelessWidget {
|
||||
final AuthStore authStore;
|
||||
|
||||
const ProfileCard({Key? key, required this.authStore}) : super(key: key);
|
||||
|
||||
Future<void> _showLoginDialog(BuildContext context) {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (context) => SimpleDialog(
|
||||
children: [
|
||||
ColoredBox(
|
||||
color: const Color.fromRGBO(145, 70, 255, 0.8),
|
||||
child: SimpleDialogOption(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Image.asset(
|
||||
'assets/icons/TwitchGlitchWhite.png',
|
||||
height: 30,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
const Text(
|
||||
'Connect with Twitch',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
authStore.login();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
const Center(
|
||||
child: Text(
|
||||
'Or',
|
||||
style: TextStyle(fontStyle: FontStyle.italic),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5.0),
|
||||
SimpleDialogOption(
|
||||
child: TextField(
|
||||
textAlign: TextAlign.center,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Token',
|
||||
),
|
||||
onSubmitted: (token) {
|
||||
authStore.login(customToken: token);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _showLogoutDialog(BuildContext context) {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Log Out'),
|
||||
content: const Text('Are you sure you want to log out?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: Navigator.of(context).pop,
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
authStore.logout();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('Yes'),
|
||||
style: TextButton.styleFrom(primary: Colors.red),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Observer(
|
||||
builder: (context) {
|
||||
if (authStore.error != null) {
|
||||
return ListTile(
|
||||
title: const Text('Failed to Connect'),
|
||||
trailing: OutlinedButton(
|
||||
onPressed: authStore.init,
|
||||
child: const Text('Try Again'),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (authStore.isLoggedIn && authStore.user.details != null) {
|
||||
return ListTile(
|
||||
leading: CircleAvatar(
|
||||
foregroundImage: CachedNetworkImageProvider(authStore.user.details!.profileImageUrl),
|
||||
),
|
||||
title: Text(authStore.user.details!.displayName),
|
||||
trailing: ElevatedButton.icon(
|
||||
onPressed: () => _showLogoutDialog(context),
|
||||
icon: const Icon(Icons.logout_outlined),
|
||||
label: const Text('Log Out'),
|
||||
style: ElevatedButton.styleFrom(primary: Colors.red),
|
||||
),
|
||||
);
|
||||
}
|
||||
return ListTile(
|
||||
isThreeLine: true,
|
||||
leading: const Icon(
|
||||
Icons.no_accounts,
|
||||
size: 40,
|
||||
),
|
||||
title: const Text('Anonymous User'),
|
||||
subtitle: const Text('Log in to chat, view followed streams, and more.'),
|
||||
trailing: OutlinedButton(
|
||||
onPressed: () => _showLoginDialog(context),
|
||||
child: const Text('Log In'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue