You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class NestedRefreshList extends StatefulWidget {
const NestedRefreshList({super.key, required this.tabIndex});
final int tabIndex; @OverRide
State createState() => _NestedRefreshListState();
}
class _NestedRefreshListState extends State {
int _listCount = 20;
late EasyRefreshController _controller;
设置了 refreshOnStart 为true,首次进入页面不刷新。代码取自您这边的example 中nested_scroll_view.dart,您可以在nested_scroll_view.dart 中做如下尝试:
`import 'dart:async';
import 'package:example/widget/skeleton_item.dart';
import 'package:flutter/material.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:extended_nested_scroll_view/extended_nested_scroll_view.dart';
class NestedScrollViewPage extends StatefulWidget {
const NestedScrollViewPage({super.key});
@OverRide
NestedScrollViewPageState createState() {
return NestedScrollViewPageState();
}
}
class NestedScrollViewPageState extends State
with SingleTickerProviderStateMixin {
late TabController _tabController;
@OverRide
void initState() {
super.initState();
_tabController = TabController(length: 3, vsync: this);
}
@OverRide
void dispose() {
super.dispose();
_tabController.dispose();
}
@OverRide
Widget build(BuildContext context) {
final themeData = Theme.of(context);
return Scaffold(
body: ExtendedNestedScrollView(
onlyOneScrollInBody: true,
pinnedHeaderSliverHeightBuilder: () {
return MediaQuery.of(context).padding.top + kToolbarHeight;
},
headerSliverBuilder: (context, innerBoxIsScrolled) {
return [
SliverAppBar(
expandedHeight: 120,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
title: Text(
'NestedScrollView',
style: TextStyle(color: Theme.of(context).textTheme.titleLarge?.color),
),
centerTitle: false,
),
),
SliverPersistentHeader(
pinned: true,
delegate: SliverStickHeaderDelegate(
height: 44,
child: Container(
color: Theme.of(context).secondaryHeaderColor,
child: TabBar(
controller: _tabController,
labelColor: themeData.colorScheme.primary,
indicatorColor: themeData.colorScheme.primary,
tabs: const [
Tab(text: 'List 1'),
Tab(text: 'List 2'),
Tab(text: 'List 3'),
],
),
),
),
),
];
},
body: TabBarView(controller: _tabController, children: const [
AutoKeepAliveWrapper(child: NestedRefreshList(tabIndex: 1)),
AutoKeepAliveWrapper(child: NestedRefreshList(tabIndex: 1)),
AutoKeepAliveWrapper(child: NestedRefreshList(tabIndex: 2)),
]),
),
);
}
}
class NestedRefreshList extends StatefulWidget {
const NestedRefreshList({super.key, required this.tabIndex});
final int tabIndex;
@OverRide
State createState() => _NestedRefreshListState();
}
class _NestedRefreshListState extends State {
int _listCount = 20;
late EasyRefreshController _controller;
@OverRide
void initState() {
_controller = EasyRefreshController();
///尝试手动刷新,未生效
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
_controller.callRefresh();
});
super.initState();
}
@OverRide
Widget build(BuildContext context) {
return ExtendedVisibilityDetector(
uniqueKey: const Key('Tab0'),
child: EasyRefresh(
controller: _controller,
refreshOnStart: true, //首次进入页面也无法刷新
header: const MaterialHeader(
position: IndicatorPosition.locator,
),
footer: const MaterialFooter(
position: IndicatorPosition.locator,
),
child: CustomScrollView(
slivers: [
const HeaderLocator.sliver(clearExtent: false),
SliverToBoxAdapter(child: Text('${widget.tabIndex}')),
SliverList(
delegate: SliverChildBuilderDelegate((context, index) {
return const SkeletonItem();
}, childCount: _listCount)),
const FooterLocator.sliver(clearExtent: false),
],
),
onRefresh: () async {
await Future.delayed(const Duration(seconds: 2), () {
if (mounted) {
setState(() {
_listCount = 20;
});
}
});
},
onLoad: () async {
await Future.delayed(const Duration(seconds: 2), () {
if (mounted) {
setState(() {
_listCount += 10;
});
}
});
},
),
);
}
}
class AutoKeepAliveWrapper extends StatefulWidget {
const AutoKeepAliveWrapper({
super.key,
this.keepAlive = true,
required this.child,
});
final bool keepAlive;
final Widget child;
@OverRide
State createState() => _AutoKeepAliveWrapperState();
}
class _AutoKeepAliveWrapperState extends State
with AutomaticKeepAliveClientMixin {
@OverRide
Widget build(final BuildContext context) {
super.build(context);
return widget.child;
}
@OverRide
void didUpdateWidget(covariant final AutoKeepAliveWrapper oldWidget) {
if (oldWidget.keepAlive != widget.keepAlive) {
updateKeepAlive();
}
super.didUpdateWidget(oldWidget);
}
@OverRide
bool get wantKeepAlive => widget.keepAlive;
}
class SliverStickHeaderDelegate extends SliverPersistentHeaderDelegate {
SliverStickHeaderDelegate({required this.child, this.height});
final double? height;
final Widget child;
@OverRide
Widget build(final BuildContext context, final double shrinkOffset, final bool overlapsContent) {
return Container(
alignment: Alignment.topCenter,
child: child,
);
}
@OverRide
double get maxExtent => height ?? 45;
@OverRide
double get minExtent => height ?? 45;
@OverRide
bool shouldRebuild(final SliverPersistentHeaderDelegate oldDelegate) {
return true;
}
}
`
The text was updated successfully, but these errors were encountered: