我用了 * gridview.builder *,我想在每次按下按钮时加载五个项目。我试过了,但不知道怎么做。
当所有按钮都被按下时,每次显示的商品都超过5个,当列表中没有更多的类别时,所有按钮都消失了。
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,
)),
],
),
);;
}));
}
}
1条答案
按热度按时间nnvyjq4y1#
您可以维护项目列表的状态,并且可以操作该状态以增加列表的大小,以便网格的大小自动增加。
以下是上述要求的示例: