Last active
November 22, 2024 00:45
-
-
Save ChrisBP-Dev/66ce08ea4790e2a3f78da45ad6ed6762 to your computer and use it in GitHub Desktop.
Resize Extension - Fluter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Layout breakpoints used in the app. | |
class Breakpoint { | |
static const double desktop = 900; | |
static const double tablet = 600; | |
static const double mobile = 450; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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