page.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import 'package:flutter/material.dart';
  2. import 'package:go_router/go_router.dart';
  3. import 'package:maxkey_flutter/maxkey/maxkey.dart';
  4. import 'package:maxkey_flutter/maxkey/services/users.service.dart';
  5. import 'package:maxkey_flutter/utils.dart';
  6. import 'package:flutter_gen/gen_l10n/app_localizations.dart';
  7. part 'package:maxkey_flutter/pages/user_page/full_user_info_dialog.dart';
  8. class UserPage extends StatelessWidget {
  9. const UserPage({super.key, this.user});
  10. final MaxKeyUser? user;
  11. @override
  12. Widget build(BuildContext context) {
  13. final scheme = Theme.of(context).colorScheme;
  14. return Scaffold(
  15. appBar: AppBar(title: Text(AppLocalizations.of(context)!.userPageTitle)),
  16. body: SafeArea(
  17. child: Padding(
  18. padding: const EdgeInsets.symmetric(horizontal: 16.0),
  19. child: Column(children: [
  20. if (user != null)
  21. Ink(
  22. decoration: BoxDecoration(
  23. color: scheme.surfaceContainer,
  24. borderRadius: BorderRadius.circular(8.0),
  25. ),
  26. child: Padding(
  27. padding: const EdgeInsets.all(8.0),
  28. child: Column(children: [
  29. _UserCard(user: user!),
  30. _UserPageButtonTile(
  31. title: AppLocalizations.of(context)!.userPageUserInfoBtn,
  32. trailing: Icons.info,
  33. onTap: () async {
  34. final userInfo = await MaxKey.instance.usersService
  35. .getFullUserInfo();
  36. if (userInfo == null) return;
  37. if (context.mounted) {
  38. showDialog(
  39. context: context,
  40. builder: (context) =>
  41. _FullUserInfoDialog(userInfo: userInfo),
  42. );
  43. }
  44. },
  45. ),
  46. ]),
  47. ),
  48. ),
  49. const SizedBox(height: 8.0),
  50. _UserPageButtonTile(
  51. title: AppLocalizations.of(context)!.userPageSettingsBtn,
  52. trailing: Icons.settings,
  53. onTap: () {
  54. context.push(RoutePath.settingsPage);
  55. },
  56. ),
  57. const SizedBox(height: 8.0),
  58. _UserPageButtonTile(
  59. title: AppLocalizations.of(context)!.userPageLogoutBtn,
  60. trailing: Icons.logout,
  61. onTap: () async {
  62. await MaxKey.instance.authnService.logout();
  63. if (context.mounted) {
  64. context.pushReplacement(RoutePath.loginPage);
  65. }
  66. },
  67. )
  68. ]),
  69. ),
  70. ),
  71. );
  72. }
  73. }
  74. class _UserPageButtonTile extends StatelessWidget {
  75. const _UserPageButtonTile({
  76. super.key,
  77. required this.title,
  78. required this.trailing,
  79. required this.onTap,
  80. });
  81. final String title;
  82. final IconData trailing;
  83. final void Function() onTap;
  84. @override
  85. Widget build(BuildContext context) {
  86. final scheme = Theme.of(context).colorScheme;
  87. return ListTile(
  88. shape: RoundedRectangleBorder(
  89. borderRadius: BorderRadius.circular(8.0),
  90. ),
  91. tileColor: scheme.surfaceContainer,
  92. title: Text(title),
  93. trailing: Icon(trailing),
  94. onTap: onTap,
  95. );
  96. }
  97. }
  98. class _UserCard extends StatelessWidget {
  99. const _UserCard({super.key, required this.user});
  100. final MaxKeyUser user;
  101. @override
  102. Widget build(BuildContext context) {
  103. return Padding(
  104. padding: const EdgeInsets.all(8.0),
  105. child: Row(
  106. children: [
  107. ClipOval(
  108. child: user.picture == null
  109. ? Image.asset("assets/logo.jpg", width: 64, height: 64)
  110. : Image.memory(user.picture!, width: 64, height: 64),
  111. ),
  112. const SizedBox(width: 8),
  113. Expanded(
  114. child: Text(
  115. user.displayName,
  116. style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
  117. ),
  118. ),
  119. ],
  120. ),
  121. );
  122. }
  123. }