Padding(
padding: EdgeInsets.all(10),
child: InkWell(
onTap: (){},
child: Container(
width: 130,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: MyTheme.creamColor,
),
child: Center(
child: Column(
children: [
Container(
margin: EdgeInsets.only(top: 15),
child: Image(image: AssetImage("assets/images/icons.png"))
),
// SizedBox(height: 7,),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Neurology"),
)
],
),
)
),
),
)
List of Names List<String>name = ["Neurogy","Dentist","Eye","Ear"];
Images in folder with name
cat1.png, cat2.png, cat3.png, cat4.png
enter image description here This is the output which I’m Expecting
Name length is not only 4 and same for image its total 24,
Complete code: https://github.com/reyaz-mra/flutter-firebase/blob/main/category.dart
How can i make it using Gridview builder in flutter??
2
Answers
It seems like category name and asset path are the only two things that are changing. I’d recommend creating two lists:
List<String> categories
List<String> assetPaths
and using them in GridView like this:
you can achieve it with
List.generate(length, (index)=> )
or usingname.map( (element) => )
here how your code will look like
or you can achieve it like this with
List.map
which is not recommended as it costs performance