mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
opt: bottomnav/searchbar stream debounce
Closes #590 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -114,4 +114,10 @@ class HomeController extends GetxController
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
searchBarStream.close();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:PiliPlus/models/common/dynamic_badge_mode.dart';
|
||||
import 'package:PiliPlus/pages/main/index.dart';
|
||||
import 'package:PiliPlus/pages/mine/controller.dart';
|
||||
@@ -11,6 +9,7 @@ import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
||||
import './controller.dart';
|
||||
import 'package:PiliPlus/common/widgets/spring_physics.dart';
|
||||
import 'package:stream_transform/stream_transform.dart';
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({super.key});
|
||||
@@ -22,18 +21,11 @@ class HomePage extends StatefulWidget {
|
||||
class _HomePageState extends State<HomePage>
|
||||
with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
|
||||
final HomeController _homeController = Get.put(HomeController());
|
||||
late Stream<bool> stream;
|
||||
final MainController _mainController = Get.put(MainController());
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
stream = _homeController.searchBarStream.stream;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
@@ -162,8 +154,9 @@ class _HomePageState extends State<HomePage>
|
||||
Widget get customAppBar {
|
||||
return StreamBuilder(
|
||||
stream: _homeController.hideSearchBar
|
||||
? stream
|
||||
: StreamController<bool>.broadcast().stream,
|
||||
? _homeController.searchBarStream.stream
|
||||
.throttle(const Duration(milliseconds: 500))
|
||||
: null,
|
||||
initialData: true,
|
||||
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
||||
return AnimatedOpacity(
|
||||
|
||||
@@ -213,4 +213,10 @@ class MainController extends GetxController {
|
||||
})
|
||||
.toList();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
bottomBarStream.close();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
@@ -19,6 +18,7 @@ import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
||||
import './controller.dart';
|
||||
import 'package:stream_transform/stream_transform.dart';
|
||||
|
||||
class MainApp extends StatefulWidget {
|
||||
const MainApp({super.key});
|
||||
@@ -265,7 +265,8 @@ class _MainAppState extends State<MainApp>
|
||||
: StreamBuilder(
|
||||
stream: _mainController.hideTabBar
|
||||
? _mainController.bottomBarStream.stream
|
||||
: StreamController<bool>.broadcast().stream,
|
||||
.throttle(const Duration(milliseconds: 500))
|
||||
: null,
|
||||
initialData: true,
|
||||
builder: (context, AsyncSnapshot snapshot) {
|
||||
return AnimatedSlide(
|
||||
|
||||
Reference in New Issue
Block a user