Flutter使⽤官⽅CustomScrollView实现复杂页⾯下拉刷新和加
载更多
class ScrollableDemoState extends State<ScrollableDemo> {
ScrollController _controller;
int _count = 10;
bool _isLoding = false;
bool _isRefreshing = false;
String loadingText = "加载中.....";
@override
void initState() {
super.initState();
_controller = ScrollController();
}
@override
void dispose() {
长寿花怎么养super.dispose();
_controller.dispose();
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: Scaffold(
body: new Container(
child: new NotificationListener(
onNotification: (notification) {
if (notification is ScrollUpdateNotification &&
notification.depth == 0 &&
!_isLoding &&
!_isRefreshing) {
空工资if (ics.pixels ==
setState(() {
_isLoding = true;
loadingText = "加载中.....";
_count += 10;
});
_RrefreshPull().then((value) {
print('加载成功.............');
setState(() {
_isLoding = false;
});
}).catchError((error) {
print('failed');
setState(() {
_isLoding = true;
loadingText = "加载失败.....";
});
});
}
}
},
child: RefreshIndicator(
child: CustomScrollView(
controller: _controller,
physics: ScrollPhysics(),
slivers: <Widget>[
const SliverAppBar(
pinned: true,
title: const Text('复杂布局'),
// expandedHeight: 150.0,
// expandedHeight: 150.0,
// flexibleSpace: FlexibleSpaceBar(
// collapseMode: CollapseMode.parallax,
// title: Text(
// '复杂布局',
/
/ style: TextStyle(fontSize: 16),
// ),
// ),
elevation: 10,黄小蕾个人资料
leading: Icon(Icons.arrow_back),
),
SliverToBoxAdapter(
child: Container(
height: 200,
child: new Swiper(
itemBuilder: (BuildContext context, int index) {
return new Imagework(
"pic37.nipic/20140113/8800276_184927469000_2.png", fit: BoxFit.fill,
);
},
itemCount: 3,
pagination: new SwiperPagination(),
),
蛋白粉品牌),
),
new SliverToBoxAdapter(
child: new Container(
padding: ly(top: 10, bottom: 10),
child: new Column(
children: <Widget>[
new SizedBox(
child: new Text(
'SliverGrid',
style: new TextStyle(fontSize: 16),
)),
new Divider(
color: ,
height: 20,
)
],
),
),
),
SliverGrid(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 200.0,
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0,
childAspectRatio: 4.0,
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
alignment: ,
color: al[100 * (index % 9)],
child: Text('SliverGrid item $index'),
);
},
childCount: _count,
尤字组词),
),
new SliverToBoxAdapter(
child: new Container(
padding: ly(top: 10, bottom: 10),
color: ,
child: new SizedBox(
child: new Text(
'SliverFixedExtentList',
style: new TextStyle(fontSize: 16),
)),
)),
SliverFixedExtentList(
SliverFixedExtentList(
itemExtent: 50.0,
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
alignment: ,
color: Colors.lightBlue[100 * (index % 9)],
child: Text('SliverFixedExtentList item $index'),
);
},
childCount: _count + 20,
)
,
),
new SliverToBoxAdapter(
child: new Container(
padding: ly(top: 10, bottom: 10),
color: ,
child: new SizedBox(
child: new Text(
'SliverGrid',
style: new TextStyle(fontSize: 16),
)),
)
),
SliverGrid(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent( maxCrossAxisExtent: 200.0,
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0,
childAspectRatio: 4.0,
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
alignment: ,
color: al[100 * (index % 9)],
child: Text('SliverGrid item2 $index'),
);
},
childCount: _count + 10,
),
),
new SliverToBoxAdapter(
child: new Visibility(
child: new Container(
padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
child: new Center(
child: new Text(loadingText),
),
),
visible: _isLoding,
),
),
],
),
onRefresh: () {
超越极限1.9攻略if (_isLoding) return null;
return _RrefreshPull().then((value) {
print('success');
setState(() {
_count += 10;
});
}).catchError((error) {
print('failed');
});
},
),
),
)
,
),
);
}
Future<String> _RrefreshPull() async {
await Future.delayed(new Duration(seconds: 3));
发布评论