import 'package:flutter/material.dart'; import 'package:japp_flutter/core/models/challenge_model.dart'; class ChallengeListViewModel extends ChangeNotifier { List _challenges = []; bool _isLoading = false; String _error = ''; List get challenges => _challenges; bool get isLoading => _isLoading; String get error => _error; // 模拟数据加载 Future fetchChallenges() async { try { _isLoading = true; notifyListeners(); // 模拟网络请求延迟 await Future.delayed(const Duration(seconds: 1)); // 生成模拟数据 _challenges = [ ChallengeModel( id: '1', title: '30天健身挑战', description: '每天坚持30分钟有氧运动,塑造健康体魄', startDate: DateTime.now().subtract(const Duration(days: 5)), endDate: DateTime.now().add(const Duration(days: 25)), participants: 2541, completed: false, difficulty: '中等', ), ChallengeModel( id: '2', title: '每日阅读打卡', description: '连续21天每天阅读至少30分钟', startDate: DateTime.now().subtract(const Duration(days: 10)), endDate: DateTime.now().add(const Duration(days: 11)), participants: 4217, completed: false, difficulty: '简单', ), ChallengeModel( id: '3', title: '编程马拉松', description: '7天内完成一个完整的Flutter应用', startDate: DateTime.now().subtract(const Duration(days: 2)), endDate: DateTime.now().add(const Duration(days: 5)), participants: 876, completed: false, difficulty: '困难', ), ChallengeModel( id: '4', title: '素食30天挑战', description: '连续30天坚持素食饮食', startDate: DateTime.now().add(const Duration(days: 2)), endDate: DateTime.now().add(const Duration(days: 32)), participants: 1589, completed: false, difficulty: '中等', ), ]; _error = ''; } catch (e) { _error = '加载数据失败: $e'; } finally { _isLoading = false; notifyListeners(); } } }