mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-19 01:56:53 +08:00
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||
import 'package:PiliPlus/pages/setting/models/extra_settings.dart';
|
||||
import 'package:PiliPlus/pages/setting/models/model.dart';
|
||||
@@ -7,9 +9,9 @@ import 'package:PiliPlus/pages/setting/models/recommend_settings.dart';
|
||||
import 'package:PiliPlus/pages/setting/models/style_settings.dart';
|
||||
import 'package:PiliPlus/pages/setting/models/video_settings.dart';
|
||||
import 'package:PiliPlus/utils/grid.dart';
|
||||
import 'package:easy_debounce/easy_throttle.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:stream_transform/stream_transform.dart';
|
||||
import 'package:waterfall_flow/waterfall_flow.dart';
|
||||
|
||||
class SettingsSearchPage extends StatefulWidget {
|
||||
@@ -30,9 +32,35 @@ class _SettingsSearchPageState extends State<SettingsSearchPage> {
|
||||
...playSettings,
|
||||
...styleSettings,
|
||||
];
|
||||
late StreamController<String> _ctr;
|
||||
late StreamSubscription<String> _sub;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_ctr = StreamController<String>();
|
||||
_sub = _ctr.stream
|
||||
.debounce(const Duration(milliseconds: 200), trailing: true)
|
||||
.listen((value) {
|
||||
if (value.isEmpty) {
|
||||
_list.clear();
|
||||
} else {
|
||||
value = value.toLowerCase();
|
||||
_list.value = _settings
|
||||
.where((item) =>
|
||||
(item.title ?? item.getTitle?.call())
|
||||
?.toLowerCase()
|
||||
.contains(value) ||
|
||||
item.subtitle?.toLowerCase().contains(value) == true)
|
||||
.toList();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_sub.cancel();
|
||||
_ctr.close();
|
||||
_textEditingController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -59,23 +87,7 @@ class _SettingsSearchPageState extends State<SettingsSearchPage> {
|
||||
autofocus: true,
|
||||
controller: _textEditingController,
|
||||
textAlignVertical: TextAlignVertical.center,
|
||||
onChanged: (value) {
|
||||
EasyThrottle.throttle(
|
||||
'searchSettings', const Duration(milliseconds: 200), () {
|
||||
if (value.isEmpty) {
|
||||
_list.clear();
|
||||
} else {
|
||||
value = value.toLowerCase();
|
||||
_list.value = _settings
|
||||
.where((item) =>
|
||||
(item.title ?? item.getTitle?.call())
|
||||
?.toLowerCase()
|
||||
.contains(value) ||
|
||||
item.subtitle?.toLowerCase().contains(value) == true)
|
||||
.toList();
|
||||
}
|
||||
});
|
||||
},
|
||||
onChanged: _ctr.add,
|
||||
decoration: const InputDecoration(
|
||||
isDense: true,
|
||||
hintText: '搜索',
|
||||
|
||||
Reference in New Issue
Block a user