-
Notifications
You must be signed in to change notification settings - Fork 723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't use one refreshController to multiple SmartRefresher,It will cause some unexpected bugs mostly in TabBarView #649
Comments
这个问题,怎么解决啊 |
Hello @Asmewill class Example extends StatefulWidget {
const Example({super.key});
@override
State<Example> createState() =>
_ExampleState();
}
class _ExampleState
extends State<Example>
with SingleTickerProviderStateMixin {
late final TabController _tabController;
@override
void initState() {
super.initState();
_tabController = TabController(length: 2, vsync: this);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
bottom: TabBar(
controller: _tabController,
tabs: const [
Tab(
text: 'Tab 1',
),
Tab(
text: 'Tab 2',
),
],
),
),
body: TabBarView(
controller: _tabController,
children: const [
_TabOne(),
_TabTwo(),
],
),
);
}
}
class _TabOne extends StatefulWidget {
const _TabOne();
@override
State<_TabOne> createState() => _TabOneState();
}
class _TabOneState extends State<_TabOne> {
final RefreshController _refreshController = RefreshController();
Future<void> testRefresh() async {
_refreshController.requestRefresh();
await Future.delayed(Durations.extralong4);
_refreshController.refreshCompleted();
}
Future<void> testLoadMore() async {
_refreshController.requestLoading();
await Future.delayed(Durations.extralong4);
_refreshController.loadComplete();
}
@override
Widget build(BuildContext context) {
return SmartRefresher(
enablePullDown: true,
enablePullUp: true,
onRefresh: () async {
testRefresh();
},
onLoading: () {
testLoadMore();
},
header: const ClassicHeader(),
controller: _refreshController,
child: CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: [
SliverList.builder(
itemCount: 32,
itemBuilder: (_, i) => ListTile(
title: Text('list index - $i'),
),
),
],
),
);
}
}
class _TabTwo extends StatefulWidget {
const _TabTwo();
@override
State<_TabTwo> createState() => _TabTwoState();
}
class _TabTwoState extends State<_TabTwo> {
final RefreshController _refreshController = RefreshController();
Future<void> testRefresh() async {
_refreshController.requestRefresh();
await Future.delayed(Durations.extralong4);
_refreshController.refreshCompleted();
}
Future<void> testLoadMore() async {
_refreshController.requestLoading();
await Future.delayed(Durations.extralong4);
_refreshController.loadComplete();
}
@override
Widget build(BuildContext context) {
return SmartRefresher(
enablePullDown: true,
enablePullUp: true,
onRefresh: () async {
testRefresh();
},
onLoading: () {
testLoadMore();
},
header: const ClassicHeader(),
controller: _refreshController,
child: ListView.builder(
itemCount: 32,
itemBuilder: (_, i) => ListTile(
title: Text('list index - $i'),
),
),
);
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: