63 lines
2.0 KiB
Dart
63 lines
2.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:shadcn_ui/shadcn_ui.dart';
|
|
|
|
import '../../data/api/report_data_source.dart';
|
|
import '../../data/content_providers.dart';
|
|
import '../../routing/app_routes.dart';
|
|
import '../../theme/yanting_tokens.dart';
|
|
import '../../widgets/institution_card.dart';
|
|
import '../../widgets/page_header.dart';
|
|
import '../../widgets/states.dart';
|
|
|
|
class InstitutionsPage extends HookConsumerWidget {
|
|
const InstitutionsPage({required this.dataSource, super.key});
|
|
|
|
final ReportDataSource dataSource;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final snapshot = ref.watch(institutionsProvider);
|
|
return snapshot.when(
|
|
loading: () => const LoadingState(),
|
|
error: (error, _) => ErrorState(
|
|
message: error.toString(),
|
|
onRetry: () => ref.invalidate(institutionsProvider),
|
|
),
|
|
data: (items) {
|
|
final sorted = [...items]
|
|
..sort((a, b) => b.reportCount.compareTo(a.reportCount));
|
|
if (sorted.isEmpty) {
|
|
return const EmptyState(
|
|
title: '暂无机构信息',
|
|
message: '稍后再试',
|
|
icon: Icons.account_balance_outlined,
|
|
);
|
|
}
|
|
return ListView(
|
|
padding: const EdgeInsets.fromLTRB(
|
|
YantingSpacing.screenX,
|
|
4,
|
|
YantingSpacing.screenX,
|
|
16,
|
|
),
|
|
children: [
|
|
const PageHeader(title: '机构', subtitle: '可获取研报的机构'),
|
|
const SizedBox(height: YantingSpacing.x3),
|
|
const ShadSeparator.horizontal(),
|
|
const SizedBox(height: YantingSpacing.x3),
|
|
for (final item in sorted) ...[
|
|
InstitutionCard(
|
|
institution: item,
|
|
onTap: () =>
|
|
openInstitutionDetail(context, dataSource, item.id),
|
|
),
|
|
const SizedBox(height: YantingSpacing.x3),
|
|
],
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|