2024-04-13 16:03:50 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:solian/providers/auth.dart';
|
2024-04-21 12:55:17 +00:00
|
|
|
import 'package:solian/router.dart';
|
2024-05-03 08:16:42 +00:00
|
|
|
import 'package:solian/utils/theme.dart';
|
2024-05-03 05:39:52 +00:00
|
|
|
import 'package:solian/widgets/account/account_avatar.dart';
|
2024-04-25 15:03:16 +00:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
2024-05-03 05:39:52 +00:00
|
|
|
import 'package:solian/widgets/scaffold.dart';
|
2024-04-13 16:03:50 +00:00
|
|
|
|
2024-05-03 05:51:44 +00:00
|
|
|
class AccountScreen extends StatelessWidget {
|
2024-04-13 16:03:50 +00:00
|
|
|
const AccountScreen({super.key});
|
|
|
|
|
2024-05-02 04:51:16 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-05-03 05:39:52 +00:00
|
|
|
return IndentScaffold(
|
2024-05-03 05:51:44 +00:00
|
|
|
title: AppLocalizations.of(context)!.account,
|
2024-05-03 08:16:42 +00:00
|
|
|
fixedAppBarColor: SolianTheme.isLargeScreen(context),
|
2024-05-08 14:01:06 +00:00
|
|
|
body: AccountScreenWidget(
|
2024-05-03 05:51:44 +00:00
|
|
|
onSelect: (item) {
|
|
|
|
SolianRouter.router.pushNamed(item);
|
|
|
|
},
|
|
|
|
),
|
2024-05-02 04:51:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AccountScreenWidget extends StatefulWidget {
|
2024-05-03 05:51:44 +00:00
|
|
|
final Function(String item) onSelect;
|
2024-05-02 04:51:16 +00:00
|
|
|
|
|
|
|
const AccountScreenWidget({super.key, required this.onSelect});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<AccountScreenWidget> createState() => _AccountScreenWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AccountScreenWidgetState extends State<AccountScreenWidget> {
|
|
|
|
bool _isAuthorized = false;
|
2024-04-13 16:03:50 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
Future.delayed(Duration.zero, () async {
|
|
|
|
var authorized = await context.read<AuthProvider>().isAuthorized();
|
2024-05-02 04:51:16 +00:00
|
|
|
setState(() => _isAuthorized = authorized);
|
2024-04-13 16:03:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final auth = context.watch<AuthProvider>();
|
|
|
|
|
2024-05-02 04:51:16 +00:00
|
|
|
if (_isAuthorized) {
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
const Padding(
|
2024-05-02 10:56:40 +00:00
|
|
|
padding: EdgeInsets.only(top: 16, bottom: 8, left: 24, right: 24),
|
2024-05-02 04:51:16 +00:00
|
|
|
child: NameCard(),
|
|
|
|
),
|
2024-05-02 10:56:40 +00:00
|
|
|
ListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
|
|
|
|
leading: const Icon(Icons.color_lens),
|
|
|
|
title: Text(AppLocalizations.of(context)!.personalize),
|
|
|
|
onTap: () {
|
2024-05-03 05:51:44 +00:00
|
|
|
widget.onSelect('account.personalize');
|
2024-05-02 10:56:40 +00:00
|
|
|
},
|
|
|
|
),
|
2024-05-02 04:51:16 +00:00
|
|
|
ListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
|
|
|
|
leading: const Icon(Icons.diversity_1),
|
|
|
|
title: Text(AppLocalizations.of(context)!.friend),
|
|
|
|
onTap: () {
|
2024-05-03 05:51:44 +00:00
|
|
|
widget.onSelect('account.friend');
|
2024-05-02 04:51:16 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
|
|
|
|
leading: const Icon(Icons.logout),
|
|
|
|
title: Text(AppLocalizations.of(context)!.signOut),
|
|
|
|
onTap: () {
|
|
|
|
auth.signoff();
|
|
|
|
setState(() {
|
|
|
|
_isAuthorized = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
ActionCard(
|
|
|
|
icon: const Icon(Icons.login, color: Colors.white),
|
|
|
|
title: AppLocalizations.of(context)!.signIn,
|
|
|
|
caption: AppLocalizations.of(context)!.signInCaption,
|
|
|
|
onTap: () {
|
2024-05-03 05:39:52 +00:00
|
|
|
SolianRouter.router.pushNamed('auth.sign-in').then((did) {
|
2024-05-02 04:51:16 +00:00
|
|
|
auth.isAuthorized().then((value) {
|
|
|
|
setState(() => _isAuthorized = value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2024-04-13 16:03:50 +00:00
|
|
|
),
|
2024-05-02 04:51:16 +00:00
|
|
|
ActionCard(
|
|
|
|
icon: const Icon(Icons.add, color: Colors.white),
|
|
|
|
title: AppLocalizations.of(context)!.signUp,
|
|
|
|
caption: AppLocalizations.of(context)!.signUpCaption,
|
|
|
|
onTap: () {
|
2024-05-03 05:39:52 +00:00
|
|
|
SolianRouter.router.pushNamed('auth.sign-up');
|
2024-05-02 04:51:16 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-04-13 16:03:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class NameCard extends StatelessWidget {
|
|
|
|
const NameCard({super.key});
|
|
|
|
|
2024-04-14 07:58:27 +00:00
|
|
|
Future<Widget> renderAvatar(BuildContext context) async {
|
|
|
|
final auth = context.read<AuthProvider>();
|
|
|
|
final profiles = await auth.getProfiles();
|
2024-05-01 16:49:38 +00:00
|
|
|
return AccountAvatar(source: profiles['picture'], direct: true);
|
2024-04-13 16:03:50 +00:00
|
|
|
}
|
|
|
|
|
2024-04-14 07:58:27 +00:00
|
|
|
Future<Column> renderLabel(BuildContext context) async {
|
|
|
|
final auth = context.read<AuthProvider>();
|
|
|
|
final profiles = await auth.getProfiles();
|
2024-04-13 16:03:50 +00:00
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
2024-05-01 16:49:38 +00:00
|
|
|
profiles['nick'],
|
2024-05-02 10:56:40 +00:00
|
|
|
maxLines: 1,
|
2024-04-13 16:03:50 +00:00
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: FontWeight.bold,
|
2024-05-02 10:56:40 +00:00
|
|
|
overflow: TextOverflow.ellipsis,
|
2024-04-13 16:03:50 +00:00
|
|
|
),
|
|
|
|
),
|
2024-05-02 10:56:40 +00:00
|
|
|
Text(
|
|
|
|
profiles['email'],
|
|
|
|
maxLines: 1,
|
|
|
|
style: const TextStyle(overflow: TextOverflow.ellipsis),
|
|
|
|
)
|
2024-04-13 16:03:50 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Card(
|
|
|
|
child: InkWell(
|
|
|
|
splashColor: Colors.indigo.withAlpha(30),
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.all(20),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
FutureBuilder(
|
2024-04-14 07:58:27 +00:00
|
|
|
future: renderAvatar(context),
|
2024-05-02 04:51:16 +00:00
|
|
|
builder: (BuildContext context, AsyncSnapshot<Widget> snapshot) {
|
2024-04-13 16:03:50 +00:00
|
|
|
if (snapshot.hasData) {
|
|
|
|
return snapshot.data!;
|
|
|
|
} else {
|
|
|
|
return const CircularProgressIndicator();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const SizedBox(width: 20),
|
|
|
|
FutureBuilder(
|
2024-04-14 07:58:27 +00:00
|
|
|
future: renderLabel(context),
|
2024-05-02 04:51:16 +00:00
|
|
|
builder: (BuildContext context, AsyncSnapshot<Column> snapshot) {
|
2024-04-13 16:03:50 +00:00
|
|
|
if (snapshot.hasData) {
|
2024-05-02 10:56:40 +00:00
|
|
|
return Expanded(child: snapshot.data!);
|
2024-04-13 16:03:50 +00:00
|
|
|
} else {
|
|
|
|
return const Column();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ActionCard extends StatelessWidget {
|
|
|
|
final Widget icon;
|
|
|
|
final String title;
|
|
|
|
final String caption;
|
|
|
|
final Function onTap;
|
|
|
|
|
2024-05-02 10:56:40 +00:00
|
|
|
const ActionCard({
|
|
|
|
super.key,
|
|
|
|
required this.onTap,
|
|
|
|
required this.title,
|
|
|
|
required this.caption,
|
|
|
|
required this.icon,
|
|
|
|
});
|
2024-04-13 16:03:50 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Card(
|
|
|
|
child: InkWell(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
onTap: () => onTap(),
|
|
|
|
child: Container(
|
|
|
|
width: 320,
|
|
|
|
padding: const EdgeInsets.all(20),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(bottom: 12),
|
|
|
|
child: CircleAvatar(
|
|
|
|
backgroundColor: Colors.indigo,
|
|
|
|
child: icon,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
title,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 18,
|
|
|
|
fontWeight: FontWeight.w900,
|
2024-05-02 10:56:40 +00:00
|
|
|
overflow: TextOverflow.clip,
|
2024-04-13 16:03:50 +00:00
|
|
|
),
|
|
|
|
),
|
2024-05-02 10:56:40 +00:00
|
|
|
Text(
|
|
|
|
caption,
|
|
|
|
style: const TextStyle(overflow: TextOverflow.clip),
|
|
|
|
),
|
2024-04-13 16:03:50 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|