| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import 'package:flutter/material.dart';
- import 'package:intl/intl.dart';
- import 'package:japp_flutter/core/models/challenge_model.dart';
- import 'package:japp_flutter/features/challenge/view_models/challenge_detail_vm.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- class ChallengeDetailScreen extends ConsumerWidget {
- final int challengeId;
- const ChallengeDetailScreen({super.key, required this.challengeId});
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- final challengeAsync = ref.watch(challengeDetailProvider);
- return Scaffold(
- appBar: AppBar(
- title: const Text("挑战详情"),
- actions: [
- IconButton(
- icon: const Icon(Icons.edit),
- onPressed: () {
- final challenge = challengeAsync.value;
- if (challenge != null) {
- Navigator.pushNamed(context, '/edit/${challenge.id}');
- }
- },
- ),
- ],
- ),
- body: switch (challengeAsync) {
- AsyncError(:final error) => Center(child: Text('加载失败: $error')),
- AsyncData(value: final value) => _buildChallengeContent(value!),
- _ => const Center(child: CircularProgressIndicator()),
- },
- );
- }
- Widget _buildChallengeContent(ChallengeModel challenge) {
- return SingleChildScrollView(
- padding: const EdgeInsets.all(16),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- challenge.title,
- style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
- ),
- const SizedBox(height: 16),
- Text(
- challenge.description,
- style: const TextStyle(fontSize: 16, height: 1.5),
- ),
- ],
- ),
- );
- }
- Widget _buildDateInfo(String label, DateTime date) {
- return Padding(
- padding: const EdgeInsets.only(bottom: 8),
- child: Row(
- children: [
- Text('$label: ', style: const TextStyle(fontWeight: FontWeight.bold)),
- Text(DateFormat('yyyy年MM月dd日').format(date)),
- ],
- ),
- );
- }
- Widget _buildParticipantInfo(int count) {
- return Row(
- children: [
- const Icon(Icons.people, size: 20),
- const SizedBox(width: 8),
- Text('$count 人参与'),
- ],
- );
- }
- }
|