bootStrapValueBasedOnSize function

dynamic bootStrapValueBasedOnSize({
  1. required Map<String, dynamic> sizes,
  2. required BuildContext context,
})

Returns "something" based on the current dimensions everything is related to browser window

Example: something = bootStrapValueBasedOnSize( { "xl": "value for xl", "lg": "value for lg", "md": "value for md", "sm": "value for sm", "": "value for xs", }, context: context, )

If the sizes does not contain the corresponding browser prefix, returns the nearest (upper first)

Implementation

dynamic bootStrapValueBasedOnSize({
  required Map<String, dynamic> sizes,
  required BuildContext context,
}) {
  //
  // Get the prefix for the definition, based on the available width
  //
  String pfx = bootstrapPrefixBasedOnWidth(MediaQuery.of(context).size.width);

  final int nbPrefixes = _prefixes.length;
  dynamic value;

  //
  // As there might be holes, we need to re-adapt
  //
  value = sizes[pfx];

  if (value == null) {
    //
    // No definition was found for this prefix
    //
    int i;
    int idx = _prefixes.indexOf(pfx);

    //
    // Look for the nearest value in higher resolutions
    //
    for (i = idx + 1; i < nbPrefixes; i++) {
      String pfx2 = _prefixesReversed[i];
      if (sizes[pfx2] != null) {
        value = sizes[pfx2];
        break;
      }
    }

    if (value == null) {
      //
      // Look for the nearest value in lower resolutions
      //
      for (int j = i - 1; j > -1; j--) {
        String pfx3 = _prefixesReversed[j];
        if (sizes[pfx3] != null) {
          value = sizes[pfx3];
          break;
        }
      }
    }
  }

  return value;
}