You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
242 lines
7.4 KiB
Dart
242 lines
7.4 KiB
Dart
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:cupertino_lists/cupertino_lists.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:isekai_wiki/components/isekai_nav_bar.dart';
|
|
import 'package:isekai_wiki/models/user.dart';
|
|
import 'package:isekai_wiki/pages/about.dart';
|
|
import 'package:isekai_wiki/styles.dart';
|
|
|
|
import '../components/dummy_icon.dart';
|
|
import '../components/follow_scale.dart';
|
|
|
|
class OwnProfileController extends GetxController {
|
|
late UserController uc;
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
uc = Get.find<UserController>();
|
|
}
|
|
|
|
Future<void> handleLoginClick() {
|
|
handleStartAuth();
|
|
return Future.delayed(const Duration(milliseconds: 100));
|
|
}
|
|
|
|
Future<void> handleStartAuth() async {
|
|
await uc.startAuthFlow();
|
|
}
|
|
|
|
Future<void> handleLogoutClick() {
|
|
handleLogout();
|
|
return Future.delayed(const Duration(milliseconds: 100));
|
|
}
|
|
|
|
Future<void> handleLogout() async {
|
|
await uc.logout();
|
|
}
|
|
}
|
|
|
|
class OwnProfileTab extends StatelessWidget {
|
|
const OwnProfileTab({super.key});
|
|
|
|
Widget _buildUserAvatar(UserController uc, {double size = 56}) {
|
|
return Obx(() {
|
|
var avatarUrl = uc.getAvatar(128);
|
|
|
|
if (avatarUrl != null && avatarUrl.isNotEmpty) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(size / 2)),
|
|
),
|
|
child: CachedNetworkImage(
|
|
width: size,
|
|
height: size,
|
|
placeholder: (_, __) =>
|
|
const CupertinoActivityIndicator(radius: 12),
|
|
imageUrl: avatarUrl,
|
|
),
|
|
);
|
|
} else {
|
|
return DummyIcon(
|
|
color: CupertinoColors.systemGrey,
|
|
icon: CupertinoIcons.person_fill,
|
|
size: size,
|
|
rounded: true,
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
Widget _buildUserSection(BuildContext context) {
|
|
var c = Get.find<OwnProfileController>();
|
|
var uc = Get.find<UserController>();
|
|
|
|
return FollowTextScale(
|
|
child: Obx(
|
|
() => !uc.isLoggedIn
|
|
? CupertinoListSection.insetGrouped(
|
|
backgroundColor: Styles.themePageBackgroundColor,
|
|
children: <CupertinoListTile>[
|
|
CupertinoListTile.notched(
|
|
title:
|
|
const Text('登录/注册', style: Styles.listTileLargeTitle),
|
|
padding: const EdgeInsets.only(
|
|
left: 6, right: 14, top: 0, bottom: 0),
|
|
leading: const DummyIcon(
|
|
color: CupertinoColors.systemGrey,
|
|
icon: CupertinoIcons.person_fill,
|
|
size: 60,
|
|
rounded: true,
|
|
),
|
|
leadingSize: 80,
|
|
leadingToTitle: 4,
|
|
trailing: uc.authProcessing.value
|
|
? const Padding(
|
|
padding: EdgeInsets.only(right: 5),
|
|
child: CupertinoActivityIndicator(
|
|
radius: 12,
|
|
),
|
|
)
|
|
: const CupertinoListTileChevron(),
|
|
onTap: c.handleLoginClick,
|
|
),
|
|
],
|
|
)
|
|
: CupertinoListSection.insetGrouped(
|
|
backgroundColor: Styles.themePageBackgroundColor,
|
|
children: <CupertinoListTile>[
|
|
CupertinoListTile.notched(
|
|
title: Text(uc.getDisplayName,
|
|
style: Styles.listTileLargeTitle),
|
|
leading: _buildUserAvatar(uc),
|
|
leadingSize: 80,
|
|
leadingToTitle: 4,
|
|
trailing: const CupertinoListTileChevron(),
|
|
onTap: () {},
|
|
),
|
|
CupertinoListTile.notched(
|
|
title: const Text('退出登录'),
|
|
leading: const DummyIcon(
|
|
color: CupertinoColors.systemRed,
|
|
icon: CupertinoIcons.arrow_right_square,
|
|
),
|
|
trailing: const CupertinoListTileChevron(),
|
|
onTap: () {},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildArticleListsSection(BuildContext context) {
|
|
return FollowTextScale(
|
|
child: CupertinoListSection.insetGrouped(
|
|
backgroundColor: Styles.themePageBackgroundColor,
|
|
children: <CupertinoListTile>[
|
|
CupertinoListTile.notched(
|
|
title: const Text('收藏'),
|
|
leading: const DummyIcon(
|
|
color: CupertinoColors.systemYellow,
|
|
icon: CupertinoIcons.star_fill,
|
|
),
|
|
trailing: const CupertinoListTileChevron(),
|
|
onTap: () {},
|
|
),
|
|
CupertinoListTile.notched(
|
|
title: const Text('阅读历史'),
|
|
leading: const DummyIcon(
|
|
color: CupertinoColors.systemBlue,
|
|
icon: CupertinoIcons.time_solid,
|
|
),
|
|
trailing: const CupertinoListTileChevron(),
|
|
onTap: () {},
|
|
),
|
|
CupertinoListTile.notched(
|
|
title: const Text('贡献'),
|
|
leading: const DummyIcon(
|
|
color: CupertinoColors.systemOrange,
|
|
icon: CupertinoIcons.create,
|
|
),
|
|
trailing: const CupertinoListTileChevron(),
|
|
onTap: () {},
|
|
),
|
|
],
|
|
));
|
|
}
|
|
|
|
Widget _buildSettingsSection(BuildContext context) {
|
|
return FollowTextScale(
|
|
child: CupertinoListSection.insetGrouped(
|
|
backgroundColor: Styles.themePageBackgroundColor,
|
|
children: <CupertinoListTile>[
|
|
CupertinoListTile.notched(
|
|
title: const Text('设置'),
|
|
leading: const DummyIcon(
|
|
color: CupertinoColors.systemGrey,
|
|
icon: CupertinoIcons.settings,
|
|
),
|
|
trailing: const CupertinoListTileChevron(),
|
|
onTap: () {},
|
|
),
|
|
CupertinoListTile.notched(
|
|
title: const Text('关于'),
|
|
leading: const DummyIcon(
|
|
color: CupertinoColors.systemBlue,
|
|
icon: CupertinoIcons.info,
|
|
),
|
|
trailing: const CupertinoListTileChevron(),
|
|
onTap: () async {
|
|
await Navigator.of(context, rootNavigator: false).push(
|
|
CupertinoPageRoute(
|
|
builder: (_) => const AboutPage(),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
));
|
|
}
|
|
|
|
SliverChildBuilderDelegate _buildSliverChildBuilderDelegate(
|
|
BuildContext context) {
|
|
return SliverChildBuilderDelegate(
|
|
(context, index) {
|
|
switch (index) {
|
|
case 0:
|
|
return _buildUserSection(context);
|
|
case 1:
|
|
return _buildArticleListsSection(context);
|
|
case 2:
|
|
return _buildSettingsSection(context);
|
|
default:
|
|
// Do nothing. For now.
|
|
}
|
|
return null;
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Get.put(OwnProfileController());
|
|
|
|
return CustomScrollView(
|
|
slivers: <Widget>[
|
|
const IsekaiSliverNavigationBar(
|
|
largeTitle: Text('我的'),
|
|
),
|
|
SliverSafeArea(
|
|
top: false,
|
|
minimum: const EdgeInsets.only(top: 4),
|
|
sliver: SliverList(
|
|
delegate: _buildSliverChildBuilderDelegate(context),
|
|
),
|
|
)
|
|
],
|
|
);
|
|
}
|
|
}
|