2024-11-28 05:15:15 +00:00
|
|
|
import 'dart:math' as math;
|
2024-12-09 16:21:32 +00:00
|
|
|
import 'dart:ui';
|
2024-11-28 05:15:15 +00:00
|
|
|
|
2024-11-08 16:09:46 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2024-11-27 15:03:18 +00:00
|
|
|
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
2024-11-27 15:37:40 +00:00
|
|
|
import 'package:gap/gap.dart';
|
2024-12-09 15:45:10 +00:00
|
|
|
import 'package:go_router/go_router.dart';
|
2024-11-27 15:03:18 +00:00
|
|
|
import 'package:google_fonts/google_fonts.dart';
|
2024-11-10 11:47:48 +00:00
|
|
|
import 'package:material_symbols_icons/symbols.dart';
|
2024-11-27 15:03:18 +00:00
|
|
|
import 'package:provider/provider.dart';
|
2024-11-10 11:47:48 +00:00
|
|
|
import 'package:styled_widget/styled_widget.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2024-12-09 16:18:39 +00:00
|
|
|
import 'package:surface/providers/post.dart';
|
2024-11-27 15:03:18 +00:00
|
|
|
import 'package:surface/providers/sn_network.dart';
|
2024-11-27 16:04:45 +00:00
|
|
|
import 'package:surface/providers/userinfo.dart';
|
2024-11-27 15:03:18 +00:00
|
|
|
import 'package:surface/types/check_in.dart';
|
2024-12-09 16:18:39 +00:00
|
|
|
import 'package:surface/types/post.dart';
|
2024-12-05 14:22:38 +00:00
|
|
|
import 'package:surface/widgets/app_bar_leading.dart';
|
2024-11-27 15:03:18 +00:00
|
|
|
import 'package:surface/widgets/dialog.dart';
|
2024-12-09 16:18:39 +00:00
|
|
|
import 'package:surface/widgets/post/post_item.dart';
|
2024-11-27 15:03:18 +00:00
|
|
|
|
2024-12-14 10:18:13 +00:00
|
|
|
import '../providers/widget.dart';
|
|
|
|
|
2024-11-27 15:03:18 +00:00
|
|
|
class HomeScreenDashEntry {
|
|
|
|
final String name;
|
|
|
|
final Widget child;
|
|
|
|
final int rows, cols;
|
|
|
|
|
|
|
|
const HomeScreenDashEntry({
|
|
|
|
required this.name,
|
|
|
|
required this.child,
|
|
|
|
this.rows = 1,
|
|
|
|
this.cols = 1,
|
|
|
|
});
|
|
|
|
}
|
2024-11-08 16:09:46 +00:00
|
|
|
|
|
|
|
class HomeScreen extends StatefulWidget {
|
|
|
|
const HomeScreen({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<HomeScreen> createState() => _HomeScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _HomeScreenState extends State<HomeScreen> {
|
2024-11-27 15:03:18 +00:00
|
|
|
static const List<HomeScreenDashEntry> kCards = [
|
2024-12-09 16:18:39 +00:00
|
|
|
HomeScreenDashEntry(
|
|
|
|
name: 'dashEntryRecommendation',
|
|
|
|
cols: 2,
|
|
|
|
rows: 2,
|
|
|
|
child: _HomeDashRecommendationPostWidget(),
|
|
|
|
),
|
2024-11-27 15:03:18 +00:00
|
|
|
HomeScreenDashEntry(
|
|
|
|
name: 'dashEntryCheckIn',
|
|
|
|
child: _HomeDashCheckInWidget(),
|
|
|
|
),
|
2024-12-09 15:45:10 +00:00
|
|
|
HomeScreenDashEntry(
|
|
|
|
name: 'dashEntryNotification',
|
|
|
|
child: _HomeDashNotificationWidget(),
|
|
|
|
),
|
2024-11-27 15:03:18 +00:00
|
|
|
];
|
|
|
|
|
2024-11-08 16:09:46 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-11-14 14:21:13 +00:00
|
|
|
return Scaffold(
|
2024-11-08 16:09:46 +00:00
|
|
|
appBar: AppBar(
|
2024-12-05 14:22:38 +00:00
|
|
|
leading: AutoAppBarLeading(),
|
2024-11-08 16:09:46 +00:00
|
|
|
title: Text("screenHome").tr(),
|
|
|
|
),
|
2024-11-27 16:29:53 +00:00
|
|
|
body: LayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
|
|
|
return Align(
|
2024-12-09 15:45:10 +00:00
|
|
|
alignment: constraints.maxWidth > 640 ? Alignment.center : Alignment.topCenter,
|
2024-11-27 16:29:53 +00:00
|
|
|
child: Container(
|
|
|
|
constraints: const BoxConstraints(maxWidth: 640),
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: Column(
|
2024-12-09 15:45:10 +00:00
|
|
|
mainAxisAlignment: constraints.maxWidth > 640 ? MainAxisAlignment.center : MainAxisAlignment.start,
|
2024-11-27 16:29:53 +00:00
|
|
|
children: [
|
|
|
|
_HomeDashSpecialDayWidget().padding(top: 8, horizontal: 8),
|
2024-12-10 13:08:32 +00:00
|
|
|
StaggeredGrid.extent(
|
|
|
|
maxCrossAxisExtent: 280,
|
2024-11-27 16:29:53 +00:00
|
|
|
mainAxisSpacing: 8,
|
|
|
|
crossAxisSpacing: 8,
|
|
|
|
children: kCards.map((card) {
|
|
|
|
return StaggeredGridTile.count(
|
|
|
|
crossAxisCellCount: card.cols,
|
|
|
|
mainAxisCellCount: card.rows,
|
|
|
|
child: card.child,
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
).padding(horizontal: 8),
|
|
|
|
],
|
2024-12-10 13:08:32 +00:00
|
|
|
).padding(vertical: 8),
|
2024-11-27 16:29:53 +00:00
|
|
|
),
|
2024-11-27 15:03:18 +00:00
|
|
|
),
|
2024-11-27 16:29:53 +00:00
|
|
|
);
|
|
|
|
},
|
2024-11-27 15:03:18 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-27 16:04:45 +00:00
|
|
|
class _HomeDashSpecialDayWidget extends StatelessWidget {
|
|
|
|
const _HomeDashSpecialDayWidget({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final ua = context.watch<UserProvider>();
|
|
|
|
final today = DateTime.now();
|
|
|
|
final birthday = ua.user?.profile?.birthday?.toLocal();
|
2024-12-09 15:45:10 +00:00
|
|
|
final isBirthday = birthday != null && birthday.day == today.day && birthday.month == today.month;
|
2024-11-27 16:04:45 +00:00
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
if (isBirthday)
|
|
|
|
Card(
|
|
|
|
child: ListTile(
|
|
|
|
leading: Text('🎂').fontSize(24),
|
|
|
|
title: Text('happyBirthday').tr(args: [ua.user?.nick ?? 'user']),
|
|
|
|
),
|
|
|
|
).padding(bottom: 8),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-27 15:03:18 +00:00
|
|
|
class _HomeDashCheckInWidget extends StatefulWidget {
|
|
|
|
const _HomeDashCheckInWidget({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<_HomeDashCheckInWidget> createState() => _HomeDashCheckInWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _HomeDashCheckInWidgetState extends State<_HomeDashCheckInWidget> {
|
|
|
|
bool _isBusy = false;
|
|
|
|
|
|
|
|
SnCheckInRecord? _todayRecord;
|
|
|
|
|
2024-11-27 15:37:40 +00:00
|
|
|
static const int kSuggestionPositiveHintCount = 6;
|
|
|
|
static const int kSuggestionNegativeHintCount = 6;
|
|
|
|
|
2024-11-27 15:03:18 +00:00
|
|
|
Future<void> _pullCheckIn() async {
|
|
|
|
setState(() => _isBusy = true);
|
|
|
|
try {
|
|
|
|
final sn = context.read<SnNetworkProvider>();
|
2024-12-14 10:18:13 +00:00
|
|
|
final home = context.read<HomeWidgetProvider>();
|
2024-11-27 15:03:18 +00:00
|
|
|
final resp = await sn.client.get('/cgi/id/check-in/today');
|
|
|
|
_todayRecord = SnCheckInRecord.fromJson(resp.data);
|
2024-12-14 10:18:13 +00:00
|
|
|
home.saveWidgetData('today_check_in', _todayRecord!.toJson());
|
2024-11-27 15:03:18 +00:00
|
|
|
} finally {
|
|
|
|
setState(() => _isBusy = false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _doCheckIn() async {
|
|
|
|
setState(() => _isBusy = true);
|
|
|
|
try {
|
|
|
|
final sn = context.read<SnNetworkProvider>();
|
2024-12-14 10:18:13 +00:00
|
|
|
final home = context.read<HomeWidgetProvider>();
|
2024-11-27 15:03:18 +00:00
|
|
|
final resp = await sn.client.post('/cgi/id/check-in');
|
|
|
|
_todayRecord = SnCheckInRecord.fromJson(resp.data);
|
2024-12-14 10:18:13 +00:00
|
|
|
home.saveWidgetData('today_check_in', _todayRecord!.toJson());
|
2024-11-27 15:03:18 +00:00
|
|
|
} catch (err) {
|
|
|
|
if (!mounted) return;
|
|
|
|
context.showErrorDialog(err);
|
|
|
|
} finally {
|
|
|
|
setState(() => _isBusy = false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-27 15:37:40 +00:00
|
|
|
Widget _buildDetailChunk(int index, bool positive) {
|
2024-12-09 15:45:10 +00:00
|
|
|
final prefix = positive ? 'dailyCheckPositiveHint' : 'dailyCheckNegativeHint';
|
|
|
|
final mod = positive ? kSuggestionPositiveHintCount : kSuggestionNegativeHintCount;
|
2024-11-28 05:15:15 +00:00
|
|
|
final pos = math.max(1, _todayRecord!.resultModifiers[index] % mod);
|
2024-11-27 15:37:40 +00:00
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
2024-11-28 05:15:15 +00:00
|
|
|
prefix.tr(args: ['$prefix$pos'.tr()]),
|
2024-12-09 15:45:10 +00:00
|
|
|
style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.bold),
|
2024-12-15 04:10:45 +00:00
|
|
|
),
|
2024-11-27 15:37:40 +00:00
|
|
|
Text(
|
2024-11-28 05:15:15 +00:00
|
|
|
'$prefix${pos}Description',
|
2024-11-27 15:37:40 +00:00
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
|
|
).tr(),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _showCheckInDetail() {
|
|
|
|
showDialog(
|
|
|
|
useRootNavigator: true,
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
|
|
|
return AlertDialog(
|
|
|
|
title: Text('dailyCheckDetailTitle'.tr(args: [
|
|
|
|
DateFormat('MM/dd').format(DateTime.now().toUtc()),
|
|
|
|
])),
|
|
|
|
content: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
2024-11-29 15:30:40 +00:00
|
|
|
if (_todayRecord?.resultTier != 0)
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
_buildDetailChunk(0, true),
|
|
|
|
const Gap(8),
|
|
|
|
_buildDetailChunk(1, true),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
else
|
|
|
|
Text(
|
|
|
|
'dailyCheckEverythingIsNegative',
|
2024-12-09 15:45:10 +00:00
|
|
|
style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.bold),
|
2024-11-29 15:30:40 +00:00
|
|
|
).tr(),
|
2024-11-27 15:37:40 +00:00
|
|
|
const Gap(8),
|
2024-11-29 15:30:40 +00:00
|
|
|
if (_todayRecord?.resultTier != 4)
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
_buildDetailChunk(2, false),
|
|
|
|
const Gap(8),
|
|
|
|
_buildDetailChunk(3, false),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
else
|
|
|
|
Text(
|
|
|
|
'dailyCheckEverythingIsPositive',
|
2024-12-09 15:45:10 +00:00
|
|
|
style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.bold),
|
2024-11-29 15:30:40 +00:00
|
|
|
).tr(),
|
2024-11-27 15:37:40 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
child: Text('dialogDismiss').tr(),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-11-27 15:03:18 +00:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2024-11-27 16:29:53 +00:00
|
|
|
final ua = context.read<UserProvider>();
|
|
|
|
Future.delayed(const Duration(milliseconds: 500), () async {
|
|
|
|
if (!ua.isAuthorized) return;
|
|
|
|
await _pullCheckIn();
|
|
|
|
});
|
2024-11-27 15:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Card(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2024-11-10 11:47:48 +00:00
|
|
|
children: [
|
2024-11-27 15:03:18 +00:00
|
|
|
Expanded(
|
|
|
|
child: AnimatedSwitcher(
|
|
|
|
switchInCurve: Curves.fastOutSlowIn,
|
|
|
|
switchOutCurve: Curves.fastOutSlowIn,
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
transitionBuilder: (child, animation) {
|
|
|
|
return ScaleTransition(
|
|
|
|
scale: animation,
|
|
|
|
child: child,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: _todayRecord == null
|
|
|
|
? Column(
|
|
|
|
key: Key('daily-check-in-overview-none'),
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
'dailyCheckIn',
|
|
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
|
|
).tr(),
|
|
|
|
Text(
|
|
|
|
'dailyCheckInNone',
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
).tr(),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
: Column(
|
|
|
|
key: Key('daily-check-in-overview-has'),
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
_todayRecord!.symbol,
|
|
|
|
style: GoogleFonts.notoSerifHk(
|
|
|
|
textStyle: Theme.of(context).textTheme.titleLarge,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
'+${_todayRecord!.resultExperience} EXP',
|
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
2024-11-27 15:37:40 +00:00
|
|
|
),
|
2024-11-27 15:03:18 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
DateFormat('EEE\nMM/dd').format(DateTime.now().toUtc()),
|
|
|
|
).fontSize(13).opacity(0.75),
|
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
color: Theme.of(context).colorScheme.surfaceContainer,
|
|
|
|
),
|
|
|
|
child: AnimatedSwitcher(
|
|
|
|
switchInCurve: Curves.fastOutSlowIn,
|
|
|
|
switchOutCurve: Curves.fastOutSlowIn,
|
|
|
|
duration: const Duration(milliseconds: 300),
|
|
|
|
child: _todayRecord == null
|
|
|
|
? IconButton(
|
|
|
|
key: UniqueKey(),
|
|
|
|
tooltip: 'dailyCheckAction'.tr(),
|
|
|
|
icon: const Icon(Symbols.local_fire_department),
|
|
|
|
onPressed: _isBusy ? null : _doCheckIn,
|
|
|
|
)
|
|
|
|
: IconButton(
|
|
|
|
key: UniqueKey(),
|
|
|
|
tooltip: 'dailyCheckDetail'.tr(),
|
|
|
|
icon: const Icon(Symbols.help),
|
2024-11-27 15:37:40 +00:00
|
|
|
onPressed: _showCheckInDetail,
|
2024-11-27 15:03:18 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
).padding(all: 24),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-09 15:45:10 +00:00
|
|
|
class _HomeDashNotificationWidget extends StatefulWidget {
|
|
|
|
const _HomeDashNotificationWidget({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<_HomeDashNotificationWidget> createState() => _HomeDashNotificationWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _HomeDashNotificationWidgetState extends State<_HomeDashNotificationWidget> {
|
|
|
|
int? _count;
|
|
|
|
|
|
|
|
Future<void> _fetchNotificationCount() async {
|
2024-12-10 13:45:27 +00:00
|
|
|
final ua = context.read<UserProvider>();
|
|
|
|
if (!ua.isAuthorized) {
|
|
|
|
setState(() => _count = 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-12-09 15:45:10 +00:00
|
|
|
final sn = context.read<SnNetworkProvider>();
|
|
|
|
final resp = await sn.client.get('/cgi/id/notifications/count');
|
|
|
|
_count = resp.data['count'];
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_fetchNotificationCount();
|
|
|
|
}
|
2024-11-27 15:03:18 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Card(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
2024-11-10 11:47:48 +00:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2024-11-27 15:03:18 +00:00
|
|
|
Text(
|
2024-12-09 15:45:10 +00:00
|
|
|
'notification',
|
2024-11-27 15:03:18 +00:00
|
|
|
style: Theme.of(context).textTheme.titleLarge,
|
2024-12-09 15:45:10 +00:00
|
|
|
).tr(),
|
2024-11-27 15:03:18 +00:00
|
|
|
Text(
|
2024-12-09 15:45:10 +00:00
|
|
|
_count == null ? 'loading'.tr() : 'notificationUnreadCount'.plural(_count ?? 0),
|
2024-11-27 15:03:18 +00:00
|
|
|
style: Theme.of(context).textTheme.bodyLarge,
|
|
|
|
),
|
2024-11-10 11:47:48 +00:00
|
|
|
],
|
2024-11-27 15:03:18 +00:00
|
|
|
),
|
2024-11-10 11:47:48 +00:00
|
|
|
),
|
2024-11-27 15:03:18 +00:00
|
|
|
Align(
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
color: Theme.of(context).colorScheme.surfaceContainer,
|
|
|
|
),
|
|
|
|
child: IconButton(
|
|
|
|
icon: const Icon(Symbols.arrow_right_alt),
|
2024-12-09 15:45:10 +00:00
|
|
|
onPressed: () {
|
|
|
|
GoRouter.of(context).goNamed('notification');
|
|
|
|
},
|
2024-11-27 15:03:18 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
2024-11-10 11:47:48 +00:00
|
|
|
],
|
2024-11-27 15:03:18 +00:00
|
|
|
).padding(all: 24),
|
2024-11-08 16:09:46 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-12-09 16:18:39 +00:00
|
|
|
|
|
|
|
class _HomeDashRecommendationPostWidget extends StatefulWidget {
|
|
|
|
const _HomeDashRecommendationPostWidget({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<_HomeDashRecommendationPostWidget> createState() => _HomeDashRecommendationPostWidgetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _HomeDashRecommendationPostWidgetState extends State<_HomeDashRecommendationPostWidget> {
|
|
|
|
bool _isBusy = false;
|
|
|
|
List<SnPost>? _posts;
|
|
|
|
|
|
|
|
Future<void> _fetchRecommendationPosts() async {
|
|
|
|
setState(() => _isBusy = true);
|
|
|
|
try {
|
|
|
|
final pt = context.read<SnPostContentProvider>();
|
2024-12-14 16:52:42 +00:00
|
|
|
final home = context.read<HomeWidgetProvider>();
|
2024-12-09 16:18:39 +00:00
|
|
|
_posts = await pt.listRecommendations();
|
2024-12-14 16:52:42 +00:00
|
|
|
home.saveWidgetData('post_featured', _posts!.map((e) => e.toJson()).toList());
|
2024-12-09 16:18:39 +00:00
|
|
|
} catch (err) {
|
|
|
|
if (!mounted) return;
|
|
|
|
context.showErrorDialog(err);
|
|
|
|
} finally {
|
|
|
|
setState(() => _isBusy = false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_fetchRecommendationPosts();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (_isBusy) {
|
|
|
|
return Card(
|
|
|
|
child: CircularProgressIndicator().center(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Card(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2024-12-10 13:08:32 +00:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
const Icon(Symbols.star),
|
|
|
|
const Gap(8),
|
|
|
|
Text(
|
|
|
|
'postRecommendation',
|
|
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
|
|
).tr()
|
|
|
|
],
|
|
|
|
).padding(horizontal: 18, top: 12, bottom: 8),
|
2024-12-09 16:18:39 +00:00
|
|
|
Expanded(
|
|
|
|
child: PageView.builder(
|
2024-12-09 16:21:32 +00:00
|
|
|
scrollBehavior: ScrollConfiguration.of(context).copyWith(dragDevices: {
|
|
|
|
PointerDeviceKind.mouse,
|
|
|
|
PointerDeviceKind.touch,
|
|
|
|
}),
|
2024-12-09 16:18:39 +00:00
|
|
|
itemCount: _posts?.length ?? 0,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return SingleChildScrollView(
|
|
|
|
child: GestureDetector(
|
|
|
|
child: PostItem(
|
|
|
|
data: _posts![index],
|
|
|
|
showMenu: false,
|
2024-12-10 13:08:32 +00:00
|
|
|
).padding(bottom: 8),
|
2024-12-09 16:18:39 +00:00
|
|
|
onTap: () {
|
|
|
|
GoRouter.of(context).pushNamed('postDetail', pathParameters: {
|
|
|
|
'slug': _posts![index].id.toString(),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|