我在数据库中有一个列表,我可以在StreamBuilder的页面中显示整个列表,但是当记录太多时,我想创建一个分页解决方案。它不会像滚动类型,我在底部的栏中有一个导航图标,就像“
到目前为止,我尝试了以下类似方法,但仍无法实现。
StreamBuilder<dynamic>(
stream: listDao.findAllItemsAsStream(),
builder: (context, snapshot) {
if (snapshot.hasError)
return new Scaffold(...)
else return SafeArea(
child: Scaffold(
body: Container(
padding: EdgeInsets.all(4),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: mediaQueryData.orientation == 1,
childAspectRatio: mediaQueryData.orientation == 1/2,
),
var page = 1
itemcount: snapshot.data.length > 10 ? 10 : snapshot.data.length
var totalPages = snapshot.data.length/10.toInt()+1
page == 1 ? indexP = index : indexP = index + page*10
itemBuilder: (context, index) {
return Text(snapshot.data[indexP].title)
}
),
),
bottomNavigationBar:
new BottomAppBar(
child: Row (
children: <Widget> [
InkWell(
onTap () {
if (page > 1){page = page - 1;}
else {}},
child: Icon(Icons.arrow_back_ios, size: 35,)),),
Text(page + "/" + totalPage),
InkWell(
onTap () {
if (page < totalPages){page = page + 1;}
else {},
child: Icon(Icons.arrow_forward_ios, size: 35,)),
),]
),
);
})