2023-01-18 05:34:54 -05:00
|
|
|
import 'package:flutter/material.dart';
|
2023-10-22 18:38:32 -04:00
|
|
|
import 'package:flutter/services.dart';
|
2023-01-18 05:34:54 -05:00
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
|
import 'package:frosty/screens/settings/account/account_options.dart';
|
|
|
|
|
import 'package:frosty/screens/settings/stores/auth_store.dart';
|
|
|
|
|
import 'package:frosty/widgets/app_bar.dart';
|
|
|
|
|
import 'package:frosty/widgets/profile_picture.dart';
|
|
|
|
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
|
|
|
|
|
|
|
|
class ProfileCard extends StatelessWidget {
|
|
|
|
|
final AuthStore authStore;
|
|
|
|
|
|
|
|
|
|
const ProfileCard({Key? key, required this.authStore}) : super(key: key);
|
|
|
|
|
|
2023-10-22 18:38:32 -04:00
|
|
|
Future<void> _showAccountOptionsModalBottomSheet(BuildContext context) {
|
|
|
|
|
return showModalBottomSheet(
|
2023-01-18 05:34:54 -05:00
|
|
|
context: context,
|
2023-10-22 18:38:32 -04:00
|
|
|
builder: (context) {
|
|
|
|
|
return AccountOptions(authStore: authStore);
|
|
|
|
|
},
|
2023-01-18 05:34:54 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Observer(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
if (authStore.error != null) {
|
2023-10-22 18:38:32 -04:00
|
|
|
return ListTile(
|
2023-01-18 05:34:54 -05:00
|
|
|
leading: const Icon(
|
|
|
|
|
Icons.error_outline_rounded,
|
|
|
|
|
color: Colors.red,
|
|
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
title: const Text('Failed to connect'),
|
|
|
|
|
trailing: FilledButton.tonal(
|
2023-01-18 05:34:54 -05:00
|
|
|
onPressed: authStore.init,
|
|
|
|
|
child: const Text('Reconnect'),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (authStore.isLoggedIn && authStore.user.details != null) {
|
2023-10-22 18:38:32 -04:00
|
|
|
return ListTile(
|
2023-01-18 05:34:54 -05:00
|
|
|
leading: ProfilePicture(
|
|
|
|
|
userLogin: authStore.user.details!.login,
|
|
|
|
|
radius: 12,
|
|
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
title: Text(authStore.user.details!.displayName),
|
|
|
|
|
trailing: const Icon(Icons.chevron_right_rounded),
|
|
|
|
|
onTap: () => _showAccountOptionsModalBottomSheet(context),
|
2023-01-18 05:34:54 -05:00
|
|
|
);
|
|
|
|
|
}
|
2023-10-22 18:38:32 -04:00
|
|
|
return ListTile(
|
2023-01-18 05:34:54 -05:00
|
|
|
leading: const Icon(Icons.no_accounts_rounded),
|
2023-10-22 18:38:32 -04:00
|
|
|
title: const Text('Anonymous'),
|
2023-04-29 11:34:28 -04:00
|
|
|
subtitle: const Text(
|
2023-10-22 18:38:32 -04:00
|
|
|
'Log in to enable the ability to chat, view followed streams, and more.',
|
|
|
|
|
),
|
2023-01-18 05:34:54 -05:00
|
|
|
trailing: const SizedBox(
|
|
|
|
|
height: double.infinity,
|
|
|
|
|
child: Icon(Icons.chevron_right_rounded),
|
|
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
onTap: () => Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
appBar: const FrostyAppBar(
|
|
|
|
|
title: Text('Connect with Twitch'),
|
|
|
|
|
),
|
|
|
|
|
body: WebViewWidget(
|
|
|
|
|
controller: authStore.createAuthWebViewController(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
onLongPress: () async {
|
|
|
|
|
final clipboardText =
|
|
|
|
|
(await Clipboard.getData(Clipboard.kTextPlain))?.text;
|
|
|
|
|
|
|
|
|
|
if (clipboardText == null) return;
|
|
|
|
|
|
|
|
|
|
authStore.login(token: clipboardText);
|
|
|
|
|
},
|
2023-01-18 05:34:54 -05:00
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|