扑面按钮分页GridView Builder
我使用 gridview.builder ,每次按下按钮时都想加载五个项目。我尝试过,不明白该怎么做。
当按下所有按钮时,每次显示五个以上的产品。当列表没有更多类别时,所有按钮都会消失。
class WidgetTest extends StatefulWidget {
WidgetTest({Key? key,}) : super(key: key);
// final String title;
@override
State<WidgetTest> createState() => _WidgetTestState();
}
class _WidgetTestState extends State<WidgetTest> {
int present = 0;
int perPage = 5;
final originalItems = categoryData;
var items = <String>[];
@override
void initState() {
setState(() {
present = present+perPage;
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: GridView.builder(
itemCount: 10,
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemBuilder: (context, index) {
return Container(
child: Column(
children: [
Image.network(
"https://firebasestorage.googleapis.com/v0/b/ebuy-1ac5b.appspot.com/o/pngegg%201.png?alt=media&token=fb4dd43b-c537-4471-b81b-e325724f0919",
height:30,
width: 90,
fit: BoxFit.cover,
),
Text("Man",
overflow: TextOverflow.clip,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
)),
],
),
);;
}));
}
}
I used gridview.builder, and I want to load five items every time a button is pressed. I tried and don't understand how to do it.
When all buttons are pressed, every time it shows more than five products. When the list didn't have more categories, all buttons disappeared.
Design example exactly what to want I do. Please click here to see the picture
class WidgetTest extends StatefulWidget {
WidgetTest({Key? key,}) : super(key: key);
// final String title;
@override
State<WidgetTest> createState() => _WidgetTestState();
}
class _WidgetTestState extends State<WidgetTest> {
int present = 0;
int perPage = 5;
final originalItems = categoryData;
var items = <String>[];
@override
void initState() {
setState(() {
present = present+perPage;
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: GridView.builder(
itemCount: 10,
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
itemBuilder: (context, index) {
return Container(
child: Column(
children: [
Image.network(
"https://firebasestorage.googleapis.com/v0/b/ebuy-1ac5b.appspot.com/o/pngegg%201.png?alt=media&token=fb4dd43b-c537-4471-b81b-e325724f0919",
height:30,
width: 90,
fit: BoxFit.cover,
),
Text("Man",
overflow: TextOverflow.clip,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
)),
],
),
);;
}));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以维护一个物品列表的状态,并且可以操纵状态以增加列表的大小,以便网格的大小会自动增加。
以下是上述要求的示例:
You can maintain a state for list of items, and you can manipulate the state for increasing the size of list and so that the size of the grid will increase automatically.
Below is the example for the mentioned requirement: