I have created a model class named tags but not able to use that in GridView, and what is the best way to do so like creating a Conatiner from below tags variable for every tags and put those containers in gridview.
my tag class looks like,
import 'package:flutter/material.dart';
class Tag {
final String tag;
final Color color;
final String desc;
final String title;
Tag(
{required this.color,
required this.title,
required this.desc,
required this.tag});
}
var tags = [
Tag(
color: Colors.blue,
desc: 'A tag includes all the python posts',
title: 'the title of python',
tag: '#python'),
Tag(
color: Colors.red,
desc: 'A tag includes all the java posts',
title: 'the title of java',
tag: '#java'),
];
I tried to put tags variable in list in order to create container and put that in GridView but still not able to achieve it, please suggest some suitable and best practices which I can do to create this...
I want to make responsive GridView Just like this
Below is the code for responsive design for my GridView this works fine I dont want any changes in this, I just want to know how we can create a List of widgets from a List which have model class data in it.
import 'package:flutter/material.dart';
EdgeInsetsGeometry responsivePadding(MediaQueryData mediaQuery) {
double deviceWidth = mediaQuery.size.width;
if (deviceWidth < 700) {
return EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0);
} else if (deviceWidth < 1200) {
return EdgeInsets.symmetric(horizontal: 50.0, vertical: 25.0);
} else if (deviceWidth < 1650) {
return EdgeInsets.symmetric(horizontal: 80.0, vertical: 40.0);
}
return EdgeInsets.symmetric(horizontal: 100.0, vertical: 50.0);
}
int responsiveNumGridTiles(MediaQueryData mediaQuery) {
double deviceWidth = mediaQuery.size.width;
if (deviceWidth < 700) {
return 1;
} else if (deviceWidth < 1200) {
return 2;
} else if (deviceWidth < 1650) {
return 3;
}
return 4;
}
double responsiveImageHeight(MediaQueryData mediaQuery) {
double deviceWidth = mediaQuery.size.width;
if (deviceWidth < 700) {
return 250.0;
} else if (deviceWidth < 1200) {
return mediaQuery.size.width * 0.25;
} else if (deviceWidth < 1650) {
return mediaQuery.size.width * 0.2;
}
return mediaQuery.size.width * 0.15;
}
double responsiveTitleHeight(MediaQueryData mediaQuery) {
double deviceWidth = mediaQuery.size.width;
if (deviceWidth < 700) {
return 120.0;
} else if (deviceWidth < 1200) {
return mediaQuery.size.width * 0.1;
} else if (deviceWidth < 1650) {
return mediaQuery.size.width * 0.07;
}
return mediaQuery.size.width * 0.05;
}