col method
-
This function is use to make responsive ui
-
Parameter sizes values should have spaces like 'col-sm-1 col-md-2'
-
Supported values are col-, col-sm-, col-md-, col-lg-, col-xl-*
-
* star represent 1 to 12
Implementation
Widget col(String sizes){
// order of sizes col-*, col-sm-*, col-md-*, col-lg-*, col-xl-*
// Print.p1(sizes.trim());
// int indexOfCurrentDevice = deviceTyeList.indexOf(deviceType);
// int indexOfTargetDevice = deviceTyeList.indexOf(targetDevice);
// trim extra spaces
String sizesTrim = sizes.trim();
List<String> sizesArray = sizesTrim.split(" ");
List sizesDevicesArray = []; //['_','_sm','_md','_lg','_xl'];
List sizesValuesArray = []; //[0, 1, 2, 3, 4, 5];
// sizesArray.forEach((String size) {
for(int i = 0; i < sizesArray.length; ++i) {
String size = sizesArray[i];
// print(size);
List<String> partsArray = size.split("-");
// print(partsArray);
// print(partsArray[0]); // ignore
String sizeDevices = partsArray.length == 2
? ""
: partsArray[1]; // device sm, md, lg, xl
int sizeValues = int.parse(partsArray.length == 3
? partsArray[2]
: partsArray[1]); // sizes 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12
sizesDevicesArray.add(sizeDevices);
sizesValuesArray.add(sizeValues);
}
// });
int checkDeviceExistsInSizes = sizesDevicesArray.indexOf(deviceType);
int? intGetSizeToApply;
if(checkDeviceExistsInSizes > 0){
// exists
intGetSizeToApply = sizesValuesArray[checkDeviceExistsInSizes];
}else{
// not exists
// now find below of target
// String s = "_" + deviceType;
int checkDeviceNotExistsInSizes = deviceTyeList.indexOf(deviceType);
// print(sizesDevicesArray.toString());
// print(checkDeviceNotExistsInSizes);
for(int loopI = checkDeviceNotExistsInSizes; loopI >= 0; --loopI){
String findinBelowOfTargetString = deviceTyeList[loopI];
// print(findinBelowOfTargetString);
int findinBelowOfTargetInt = sizesDevicesArray.indexOf(findinBelowOfTargetString);
if(findinBelowOfTargetInt != -1){
intGetSizeToApply = sizesValuesArray[findinBelowOfTargetInt];
break;
}
}
}
child = FractionallySizedBox(
key:key,
widthFactor: 0.0833 * intGetSizeToApply!.toDouble(), // 0.0833 width of 1 one col
// heightFactor: val,
child: child
);
// Print.p1(intGetSizeToApply.toString());
// col-sm-* col-md-* col-lg-* col-xl-*
// if(deviceType == 'xl'){
// // deviceType type lg activate +
// }
//
// if(deviceType == 'sm'){
// // device sms activate
// }
// if(deviceType == 'md'){
//
// }
// if(deviceType == 'lg'){
//
// }
return this;
}