Skip to content

Instantly share code, notes, and snippets.

@ChrisBP-Dev
Last active November 22, 2024 00:45
Show Gist options
  • Save ChrisBP-Dev/66ce08ea4790e2a3f78da45ad6ed6762 to your computer and use it in GitHub Desktop.
Save ChrisBP-Dev/66ce08ea4790e2a3f78da45ad6ed6762 to your computer and use it in GitHub Desktop.
Resize Extension - Fluter
/// Layout breakpoints used in the app.
class Breakpoint {
static const double desktop = 900;
static const double tablet = 600;
static const double mobile = 450;
}
import 'package:portfolio/src/constants/breakpoints.dart';
extension DoubleX on double {
double sizeScaled(
double screenWidth, {
required double minSize,
}) {
const minBP = Breakpoint.mobile;
const maxBP = Breakpoint.desktop;
final maxSize = this;
double scaledSize;
if (screenWidth <= minBP) {
// Para pantallas menores al breakpoint mínimo
scaledSize = minSize;
} else if (screenWidth >= maxBP) {
// Para pantallas mayores al breakpoint máximo
scaledSize = maxSize;
} else {
// Para pantallas entre los breakpoints
final proportion = (screenWidth - minBP) / (maxBP - minBP);
final calculatedResize = minSize + (maxSize - minSize) * proportion;
scaledSize = calculatedResize.clamp(minSize, maxSize);
}
return scaledSize;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment