mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
mod: replace stream
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:PiliPlus/common/widgets/custom_sliver_persistent_header_delegate.dart';
|
import 'package:PiliPlus/common/widgets/custom_sliver_persistent_header_delegate.dart';
|
||||||
@@ -41,8 +40,7 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
|||||||
with TickerProviderStateMixin {
|
with TickerProviderStateMixin {
|
||||||
late DynamicDetailController _dynamicDetailController;
|
late DynamicDetailController _dynamicDetailController;
|
||||||
AnimationController? _fabAnimationCtr;
|
AnimationController? _fabAnimationCtr;
|
||||||
late StreamController<bool> _titleStreamC; // appBar title
|
final RxBool _visibleTitle = false.obs;
|
||||||
bool _visibleTitle = false;
|
|
||||||
// String? action;
|
// String? action;
|
||||||
// 回复类型
|
// 回复类型
|
||||||
late int replyType;
|
late int replyType;
|
||||||
@@ -105,7 +103,6 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
|||||||
super.initState();
|
super.initState();
|
||||||
// floor 1原创 2转发
|
// floor 1原创 2转发
|
||||||
init();
|
init();
|
||||||
_titleStreamC = StreamController<bool>();
|
|
||||||
// if (action == 'comment') {
|
// if (action == 'comment') {
|
||||||
// _visibleTitle = true;
|
// _visibleTitle = true;
|
||||||
// _titleStreamC.add(true);
|
// _titleStreamC.add(true);
|
||||||
@@ -240,15 +237,8 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
|||||||
void listener() {
|
void listener() {
|
||||||
// 标题
|
// 标题
|
||||||
if (_dynamicDetailController.scrollController.positions.length == 1) {
|
if (_dynamicDetailController.scrollController.positions.length == 1) {
|
||||||
if (_dynamicDetailController.scrollController.offset > 55 &&
|
_visibleTitle.value =
|
||||||
!_visibleTitle) {
|
_dynamicDetailController.scrollController.offset > 55;
|
||||||
_visibleTitle = true;
|
|
||||||
_titleStreamC.add(true);
|
|
||||||
} else if (_dynamicDetailController.scrollController.offset <= 55 &&
|
|
||||||
_visibleTitle) {
|
|
||||||
_visibleTitle = false;
|
|
||||||
_titleStreamC.add(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fab按钮
|
// fab按钮
|
||||||
@@ -281,7 +271,6 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_titleStreamC.close();
|
|
||||||
_fabAnimationCtr?.dispose();
|
_fabAnimationCtr?.dispose();
|
||||||
_fabAnimationCtr = null;
|
_fabAnimationCtr = null;
|
||||||
_dynamicDetailController.scrollController.removeListener(listener);
|
_dynamicDetailController.scrollController.removeListener(listener);
|
||||||
@@ -293,12 +282,10 @@ class _DynamicDetailPageState extends State<DynamicDetailPage>
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
resizeToAvoidBottomInset: false,
|
resizeToAvoidBottomInset: false,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: StreamBuilder(
|
title: Obx(
|
||||||
stream: _titleStreamC.stream.distinct(),
|
() {
|
||||||
initialData: false,
|
|
||||||
builder: (context, AsyncSnapshot snapshot) {
|
|
||||||
return AnimatedOpacity(
|
return AnimatedOpacity(
|
||||||
opacity: snapshot.data ? 1 : 0,
|
opacity: _visibleTitle.value ? 1 : 0,
|
||||||
duration: const Duration(milliseconds: 300),
|
duration: const Duration(milliseconds: 300),
|
||||||
child: AuthorPanel(
|
child: AuthorPanel(
|
||||||
item: _dynamicDetailController.item,
|
item: _dynamicDetailController.item,
|
||||||
|
|||||||
@@ -26,23 +26,18 @@ class _SubDetailPageState extends State<SubDetailPage> {
|
|||||||
late final SubDetailController _subDetailController = Get.put(
|
late final SubDetailController _subDetailController = Get.put(
|
||||||
SubDetailController(),
|
SubDetailController(),
|
||||||
tag: Utils.makeHeroTag(Get.parameters['id']));
|
tag: Utils.makeHeroTag(Get.parameters['id']));
|
||||||
late StreamController<bool> titleStreamC;
|
final RxBool showTitle = false.obs;
|
||||||
late Future _futureBuilderFuture;
|
late Future _futureBuilderFuture;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_futureBuilderFuture = _subDetailController.queryUserSubFolderDetail();
|
_futureBuilderFuture = _subDetailController.queryUserSubFolderDetail();
|
||||||
titleStreamC = StreamController<bool>();
|
|
||||||
_controller.addListener(listener);
|
_controller.addListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
void listener() {
|
void listener() {
|
||||||
if (_controller.offset > 160) {
|
showTitle.value = _controller.offset > 160;
|
||||||
titleStreamC.add(true);
|
|
||||||
} else if (_controller.offset <= 160) {
|
|
||||||
titleStreamC.add(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_controller.position.pixels >=
|
if (_controller.position.pixels >=
|
||||||
_controller.position.maxScrollExtent - 200) {
|
_controller.position.maxScrollExtent - 200) {
|
||||||
@@ -54,7 +49,6 @@ class _SubDetailPageState extends State<SubDetailPage> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
titleStreamC.close();
|
|
||||||
_controller.removeListener(listener);
|
_controller.removeListener(listener);
|
||||||
_controller.dispose();
|
_controller.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
@@ -70,12 +64,10 @@ class _SubDetailPageState extends State<SubDetailPage> {
|
|||||||
SliverAppBar(
|
SliverAppBar(
|
||||||
expandedHeight: 215 - MediaQuery.of(context).padding.top,
|
expandedHeight: 215 - MediaQuery.of(context).padding.top,
|
||||||
pinned: true,
|
pinned: true,
|
||||||
title: StreamBuilder(
|
title: Obx(
|
||||||
stream: titleStreamC.stream.distinct(),
|
() {
|
||||||
initialData: false,
|
|
||||||
builder: (context, AsyncSnapshot snapshot) {
|
|
||||||
return AnimatedOpacity(
|
return AnimatedOpacity(
|
||||||
opacity: snapshot.data ? 1 : 0,
|
opacity: showTitle.value ? 1 : 0,
|
||||||
curve: Curves.easeOut,
|
curve: Curves.easeOut,
|
||||||
duration: const Duration(milliseconds: 500),
|
duration: const Duration(milliseconds: 500),
|
||||||
child: Row(
|
child: Row(
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:PiliPlus/http/init.dart';
|
import 'package:PiliPlus/http/init.dart';
|
||||||
@@ -50,8 +49,8 @@ class WebviewPageNew extends StatefulWidget {
|
|||||||
class _WebviewPageNewState extends State<WebviewPageNew> {
|
class _WebviewPageNewState extends State<WebviewPageNew> {
|
||||||
late final String _url = widget.url ?? Get.parameters['url'] ?? '';
|
late final String _url = widget.url ?? Get.parameters['url'] ?? '';
|
||||||
late final uaType = widget.uaType ?? Get.parameters['uaType'] ?? 'mob';
|
late final uaType = widget.uaType ?? Get.parameters['uaType'] ?? 'mob';
|
||||||
final _titleStream = StreamController<String?>();
|
final RxString title = ''.obs;
|
||||||
final _progressStream = StreamController<double>();
|
final RxDouble progress = 1.0.obs;
|
||||||
bool? _inApp;
|
bool? _inApp;
|
||||||
bool? _off;
|
bool? _off;
|
||||||
|
|
||||||
@@ -68,8 +67,6 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_titleStream.close();
|
|
||||||
_progressStream.close();
|
|
||||||
_webViewController = null;
|
_webViewController = null;
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
@@ -80,24 +77,18 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
|||||||
appBar: widget.url != null
|
appBar: widget.url != null
|
||||||
? null
|
? null
|
||||||
: AppBar(
|
: AppBar(
|
||||||
title: StreamBuilder(
|
title: Obx(
|
||||||
initialData: null,
|
() => Text(
|
||||||
stream: _titleStream.stream.distinct(),
|
title.value.isNotEmpty ? title.value : _url,
|
||||||
builder: (context, snapshot) => Text(
|
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
snapshot.hasData ? snapshot.data! : _url,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
bottom: PreferredSize(
|
bottom: PreferredSize(
|
||||||
preferredSize: Size.zero,
|
preferredSize: Size.zero,
|
||||||
child: StreamBuilder(
|
child: Obx(
|
||||||
initialData: 0.0,
|
() => progress.value < 1
|
||||||
stream: _progressStream.stream.distinct(),
|
? LinearProgressIndicator(value: progress.value)
|
||||||
builder: (context, snapshot) => snapshot.data as double < 1
|
|
||||||
? LinearProgressIndicator(
|
|
||||||
value: snapshot.data as double,
|
|
||||||
)
|
|
||||||
: const SizedBox.shrink(),
|
: const SizedBox.shrink(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -207,10 +198,10 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
onProgressChanged: (controller, progress) {
|
onProgressChanged: (controller, progress) {
|
||||||
_progressStream.add(progress / 100);
|
this.progress.value = progress / 100;
|
||||||
},
|
},
|
||||||
onTitleChanged: (controller, title) {
|
onTitleChanged: (controller, title) {
|
||||||
_titleStream.add(title);
|
this.title.value = title ?? '';
|
||||||
},
|
},
|
||||||
onCloseWindow: (controller) => Get.back(),
|
onCloseWindow: (controller) => Get.back(),
|
||||||
onLoadStop: (controller, url) {
|
onLoadStop: (controller, url) {
|
||||||
@@ -277,7 +268,7 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
_progressStream.add(1);
|
progress.value = 1;
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
shouldInterceptAjaxRequest: (controller, ajaxRequest) async {
|
shouldInterceptAjaxRequest: (controller, ajaxRequest) async {
|
||||||
@@ -311,7 +302,7 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
|||||||
);
|
);
|
||||||
// debugPrint('webview: [$url], [$hasMatch]');
|
// debugPrint('webview: [$url], [$hasMatch]');
|
||||||
if (hasMatch) {
|
if (hasMatch) {
|
||||||
_progressStream.add(1.0);
|
progress.value = 1;
|
||||||
return NavigationActionPolicy.CANCEL;
|
return NavigationActionPolicy.CANCEL;
|
||||||
} else if (RegExp(r'^(?!(https?://))\S+://', caseSensitive: false)
|
} else if (RegExp(r'^(?!(https?://))\S+://', caseSensitive: false)
|
||||||
.hasMatch(url)) {
|
.hasMatch(url)) {
|
||||||
@@ -326,7 +317,7 @@ class _WebviewPageNewState extends State<WebviewPageNew> {
|
|||||||
);
|
);
|
||||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||||
}
|
}
|
||||||
_progressStream.add(1.0);
|
progress.value = 1;
|
||||||
return NavigationActionPolicy.CANCEL;
|
return NavigationActionPolicy.CANCEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user