ui细节优化
This commit is contained in:
@@ -6,6 +6,7 @@ import 'active/active_search_page.dart';
|
||||
import 'active/category_page.dart';
|
||||
import 'active/popular_page.dart';
|
||||
import 'active/rate.dart';
|
||||
import '../controllers/shared_preferences_storage_controller.dart';
|
||||
|
||||
/// 时间: 2025-03-21
|
||||
/// 功能: 发现页面
|
||||
@@ -21,26 +22,52 @@ class DiscoverPage extends StatefulWidget {
|
||||
|
||||
class _DiscoverPageState extends State<DiscoverPage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
final List<String> _categories = ['热门', '分类', '搜索', '活跃'];
|
||||
TabController? _tabController;
|
||||
List<String> _categories = ['分类', '热门', '搜索'];
|
||||
bool _showTips = true;
|
||||
bool _isDeveloperMode = false;
|
||||
bool _isInitialized = false;
|
||||
OverlayEntry? _infoOverlayEntry;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: _categories.length, vsync: this);
|
||||
// 添加标签切换监听,以便更新UI
|
||||
_tabController.addListener(() {
|
||||
_removeInfoOverlay();
|
||||
setState(() {});
|
||||
_loadDeveloperMode();
|
||||
}
|
||||
|
||||
Future<void> _loadDeveloperMode() async {
|
||||
final isEnabled = await SharedPreferencesStorageController.getBool(
|
||||
'developer_mode_enabled',
|
||||
defaultValue: false,
|
||||
);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isDeveloperMode = isEnabled;
|
||||
_updateCategories();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _updateCategories() {
|
||||
setState(() {
|
||||
_categories = ['分类', '热门', '搜索'];
|
||||
if (_isDeveloperMode) {
|
||||
_categories.add('活跃');
|
||||
}
|
||||
_tabController?.dispose();
|
||||
_tabController = TabController(length: _categories.length, vsync: this);
|
||||
_tabController!.addListener(() {
|
||||
_removeInfoOverlay();
|
||||
setState(() {});
|
||||
});
|
||||
_isInitialized = true;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_removeInfoOverlay();
|
||||
_tabController.dispose();
|
||||
_tabController?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -51,12 +78,16 @@ class _DiscoverPageState extends State<DiscoverPage>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isHotTab = _categories[_tabController.index] == '热门';
|
||||
if (!_isInitialized) {
|
||||
return const Scaffold(body: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
|
||||
final isHotTab = _categories[_tabController!.index] == '热门';
|
||||
|
||||
return Scaffold(
|
||||
appBar: TabbedNavAppBar.build(
|
||||
title: '发现',
|
||||
tabController: _tabController,
|
||||
tabController: _tabController!,
|
||||
tabLabels: _categories,
|
||||
leading: isHotTab ? _buildInfoButton(context) : null,
|
||||
actions: [
|
||||
@@ -66,7 +97,7 @@ class _DiscoverPageState extends State<DiscoverPage>
|
||||
body: Column(
|
||||
children: [
|
||||
// 只有非搜索标签时才显示话题chips
|
||||
if (_categories[_tabController.index] != '搜索' && _showTips)
|
||||
if (_categories[_tabController!.index] != '搜索' && _showTips)
|
||||
_buildTopicChips(),
|
||||
Expanded(
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
@@ -77,14 +108,10 @@ class _DiscoverPageState extends State<DiscoverPage>
|
||||
return false;
|
||||
},
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
controller: _tabController!,
|
||||
children: _categories.asMap().entries.map((entry) {
|
||||
final category = entry.value;
|
||||
// 搜索标签显示 ActiveSearchPage
|
||||
if (category == '搜索') {
|
||||
return const ActiveSearchPage();
|
||||
}
|
||||
// 分类标签跳转到分类页面
|
||||
// 分类标签显示分类页面
|
||||
if (category == '分类') {
|
||||
return const CategoryPage();
|
||||
}
|
||||
@@ -92,6 +119,10 @@ class _DiscoverPageState extends State<DiscoverPage>
|
||||
if (category == '热门') {
|
||||
return const PopularPage();
|
||||
}
|
||||
// 搜索标签显示 ActiveSearchPage
|
||||
if (category == '搜索') {
|
||||
return const ActiveSearchPage();
|
||||
}
|
||||
// 活跃标签显示活跃统计页面
|
||||
if (category == '活跃') {
|
||||
return const RatePage();
|
||||
@@ -283,9 +314,11 @@ class _DiscoverPageState extends State<DiscoverPage>
|
||||
|
||||
Future<void> _refreshContent() async {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('内容已刷新')));
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('内容已刷新')));
|
||||
}
|
||||
}
|
||||
|
||||
void _showSearch() {
|
||||
|
||||
Reference in New Issue
Block a user