重构
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../constants/app_constants.dart';
|
||||
import '../../services/network_listener_service.dart';
|
||||
import 'guide/tongji.dart';
|
||||
|
||||
/// 时间: 2026-03-25
|
||||
/// 功能: 个人信息卡片组件
|
||||
@@ -28,20 +29,42 @@ class PersonalCard extends StatefulWidget {
|
||||
});
|
||||
|
||||
@override
|
||||
State<PersonalCard> createState() => _PersonalCardState();
|
||||
State<PersonalCard> createState() => PersonalCardState();
|
||||
}
|
||||
|
||||
class _PersonalCardState extends State<PersonalCard> {
|
||||
class PersonalCardState extends State<PersonalCard> {
|
||||
late bool _isExpanded;
|
||||
late String _currentTip;
|
||||
bool _isOnline = true;
|
||||
|
||||
// 累计数据
|
||||
int _totalViews = 0;
|
||||
int _totalLikes = 0;
|
||||
int _totalQuestions = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_isExpanded = widget.isExpanded ?? false;
|
||||
_currentTip = _getRandomTip();
|
||||
_loadOnlineStatus();
|
||||
_loadTotalStats();
|
||||
}
|
||||
|
||||
Future<void> _loadTotalStats() async {
|
||||
final views = await StatisticsManager().getTotalViews();
|
||||
final likes = await StatisticsManager().getTotalLikes();
|
||||
final questions = await StatisticsManager().getTotalQuestions();
|
||||
setState(() {
|
||||
_totalViews = views;
|
||||
_totalLikes = likes;
|
||||
_totalQuestions = questions;
|
||||
});
|
||||
}
|
||||
|
||||
// 刷新数据(公共方法,供外部调用)
|
||||
Future<void> refreshData() async {
|
||||
await _loadTotalStats();
|
||||
}
|
||||
|
||||
Future<void> _loadOnlineStatus() async {
|
||||
@@ -378,15 +401,38 @@ class _PersonalCardState extends State<PersonalCard> {
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// 统计信息
|
||||
Row(
|
||||
children: [
|
||||
_buildStatItem('收藏', widget.userData['favorites'] ?? 0),
|
||||
const SizedBox(width: 12),
|
||||
_buildStatItem('点赞', widget.userData['likes'] ?? 0),
|
||||
const SizedBox(width: 12),
|
||||
_buildStatItem('浏览', widget.userData['views'] ?? 0),
|
||||
],
|
||||
// 累计统计卡片
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 10,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.15),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
'累计',
|
||||
style: const TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildStatItem('浏览', _totalViews),
|
||||
const SizedBox(width: 16),
|
||||
_buildStatItem('点赞', _totalLikes),
|
||||
const SizedBox(width: 16),
|
||||
_buildStatItem('答题', _totalQuestions),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user