【发布时间】:2019-10-09 16:07:03
【问题描述】:
我想要做的是生成一个带有上面定义的索引的 GridView,但由于某种原因它说“未定义的名称索引”,请你帮我解决这个问题。
代码如下:
import 'package:flutter/material.dart';
void main() => runApp(MyApp(items: List<String>.generate(1000, (index) => "Item $index")));
class MyApp extends StatelessWidget {
final List<String> items;
MyApp({Key key, @required this.items}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar:
AppBar(title:
Text('List View Vertical'),),
body:
GridView.count(
crossAxisCount: 2,
children: List.generate(100, index)(
return Center(child: Text('Items $index',
style: Theme.of(context).textTheme.headline,),);
))
)
);
}
}
我期望的结果是使用我已经定义的索引生成 1000 行 gridview。
【问题讨论】: