what I am trying to do is generate a GridView with flutter with the index which is defined above, but it said "Undefined name index" for some reason, can you help me with that please.
Here is the code:
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,),);
))
)
);
}
}
The result I expect is generating 1000 rows of gridview using the index I have already defined.