mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-23 10:36:24 +08:00
opt pgc index
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -4,7 +4,8 @@ import 'package:PiliPlus/common/widgets/loading_widget/loading_widget.dart';
|
||||
import 'package:PiliPlus/common/widgets/self_sized_horizontal_list.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models_new/pgc/pgc_index_condition/data.dart';
|
||||
import 'package:PiliPlus/models_new/pgc/pgc_index_condition/order.dart';
|
||||
import 'package:PiliPlus/models_new/pgc/pgc_index_condition/sort.dart';
|
||||
import 'package:PiliPlus/models_new/pgc/pgc_index_condition/value.dart';
|
||||
import 'package:PiliPlus/models_new/pgc/pgc_index_result/list.dart';
|
||||
import 'package:PiliPlus/pages/pgc_index/controller.dart';
|
||||
import 'package:PiliPlus/pages/pgc_index/widgets/pgc_card_v_pgc_index.dart';
|
||||
@@ -71,8 +72,8 @@ class _PgcIndexPageState extends State<PgcIndexPage>
|
||||
alignment: Alignment.topCenter,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: count > 5
|
||||
? Obx(() => _buildSortWidget(theme, count, response))
|
||||
: _buildSortWidget(theme, count, response),
|
||||
? Obx(() => _buildSortsWidget(theme, count, response))
|
||||
: _buildSortsWidget(theme, count, response),
|
||||
),
|
||||
),
|
||||
SliverPadding(
|
||||
@@ -99,6 +100,64 @@ class _PgcIndexPageState extends State<PgcIndexPage>
|
||||
}
|
||||
|
||||
Widget _buildSortWidget(
|
||||
ThemeData theme,
|
||||
int index,
|
||||
PgcIndexConditionData data,
|
||||
item,
|
||||
) {
|
||||
if (item case PgcConditionOrder e) {
|
||||
return Obx(
|
||||
() {
|
||||
final isCurr = _ctr.indexParams['order'] == e.field;
|
||||
return SearchText(
|
||||
bgColor: isCurr
|
||||
? theme.colorScheme.secondaryContainer
|
||||
: Colors.transparent,
|
||||
textColor: isCurr
|
||||
? theme.colorScheme.onSecondaryContainer
|
||||
: theme.colorScheme.onSurfaceVariant,
|
||||
text: e.name!,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
vertical: 3,
|
||||
),
|
||||
onTap: (_) => _ctr
|
||||
..indexParams['order'] = e.field
|
||||
..onReload(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
if (item case PgcConditionValue e) {
|
||||
final hasOrder = data.order?.isNotEmpty == true;
|
||||
if (hasOrder) index -= 1;
|
||||
final key = data.filter![index].field!;
|
||||
return Obx(
|
||||
() {
|
||||
final isCurr = _ctr.indexParams[key] == e.keyword;
|
||||
return SearchText(
|
||||
bgColor: isCurr
|
||||
? theme.colorScheme.secondaryContainer
|
||||
: Colors.transparent,
|
||||
textColor: isCurr
|
||||
? theme.colorScheme.onSecondaryContainer
|
||||
: theme.colorScheme.onSurfaceVariant,
|
||||
text: e.name!,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
vertical: 3,
|
||||
),
|
||||
onTap: (_) => _ctr
|
||||
..indexParams[key] = e.keyword
|
||||
..onReload(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
throw UnsupportedError('${item.runtimeType}');
|
||||
}
|
||||
|
||||
Widget _buildSortsWidget(
|
||||
ThemeData theme,
|
||||
int count,
|
||||
PgcIndexConditionData data,
|
||||
@@ -127,52 +186,11 @@ class _PgcIndexPageState extends State<PgcIndexPage>
|
||||
gapSize: 12,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
childBuilder: (childIndex) {
|
||||
final e = item[childIndex];
|
||||
return Obx(
|
||||
() => SearchText(
|
||||
bgColor:
|
||||
(e is PgcConditionOrder
|
||||
? _ctr.indexParams['order']
|
||||
: _ctr.indexParams[data
|
||||
.filter![data.order?.isNotEmpty ==
|
||||
true
|
||||
? index - 1
|
||||
: index]
|
||||
.field]) ==
|
||||
(e is PgcConditionOrder ? e.field : e.keyword)
|
||||
? theme.colorScheme.secondaryContainer
|
||||
: Colors.transparent,
|
||||
textColor:
|
||||
(e is PgcConditionOrder
|
||||
? _ctr.indexParams['order']
|
||||
: _ctr.indexParams[data
|
||||
.filter![data.order?.isNotEmpty ==
|
||||
true
|
||||
? index - 1
|
||||
: index]
|
||||
.field]) ==
|
||||
(e is PgcConditionOrder ? e.field : e.keyword)
|
||||
? theme.colorScheme.onSecondaryContainer
|
||||
: theme.colorScheme.onSurfaceVariant,
|
||||
text: e.name,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
vertical: 3,
|
||||
),
|
||||
onTap: (_) {
|
||||
String name = e is PgcConditionOrder
|
||||
? 'order'
|
||||
: data
|
||||
.filter![data.order?.isNotEmpty == true
|
||||
? index - 1
|
||||
: index]
|
||||
.field!;
|
||||
_ctr.indexParams[name] = (e is PgcConditionOrder
|
||||
? e.field
|
||||
: e.keyword);
|
||||
_ctr.onReload();
|
||||
},
|
||||
),
|
||||
return _buildSortWidget(
|
||||
theme,
|
||||
index,
|
||||
data,
|
||||
item[childIndex],
|
||||
);
|
||||
},
|
||||
itemCount: item!.length,
|
||||
|
||||
Reference in New Issue
Block a user