flutter_screen_scaler 3.0.0
flutter_screen_scaler: ^3.0.0 copied to clipboard
A package to scale widgets and font sizes based on screen percentages, with convenient extension methods (e.g., `50.h`, `30.w`, `16.sp`).
Changelog #
3.0.0 YYYY-MM-DD #
Breaking Changes #
- Refactored
ScreenScalerto use a singleton pattern.- Access the instance via
ScreenScaler.I. - Initialization is now done via a static method:
ScreenScaler.init(context). - The constructor
ScreenScaler()is no longer public; direct instantiation is replaced by the singleton.
- Access the instance via
- Simplified Core Scaling Logic for
getWidthandgetHeight.- These methods now consistently return a direct percentage of the screen width/height.
- The previous complex scaling logic based on
_fixedWidthand_fixedHeight(which involvedlogand screen ratio adjustments) has been removed to ensure straightforward percentage scaling. - The constants
_fixedWidthand_fixedHeighthave been removed as they are no longer used by the primary scaling methods.
- Removed Nullable Parameters.
- Methods like
getWidth(double? percentage),getHeight(double? percentage), andgetTextSize(double? percentage)now require non-nullabledoubleparameters.
- Methods like
Added #
- Extension Methods for Concise Scaling.
- Added extension methods on
numfor convenient scaling (afterScreenScaler.init(context)has been called):.h: Scales the number as a percentage of the screen height (e.g.,50.h)..w: Scales the number as a percentage of the screen width (e.g.,30.w)..sp: Scales the number as a responsive font size, linearly based on screen width relative to a reference width (e.g.,16.sp).
- Added extension methods on
- New Responsive Font Scaling Method.
- Added
ScreenScaler.I.getResponsiveFontSize(double fontSize)for linear font scaling. This is used by the.spextension. - A reference screen width (
_kReferenceScreenWidthForText) is used for this scaling.
- Added
- Parent-Relative Scaling Methods.
- Added
ScreenScaler.I.scaleWidthFrom(Size parentSize, double percentage)to scale based on a percentage of the parent widget's width. - Added
ScreenScaler.I.scaleHeightFrom(Size parentSize, double percentage)to scale based on a percentage of the parent widget's height.
- Added
Changed #
- Improved Documentation.
- Updated all Dartdoc comments for clarity, conciseness, and to reflect the new API and scaling logic.
- Clarified the behavior of
getTextSize(and its aliasgetFullScreen), noting its quadratic scaling behavior due to its formula.
- Code Quality.
- Improved variable naming and use of
finalfor local variables. - Introduced
_kDefaultDecimalPlacesconstant for rounding precision. - Added a debug warning if screen-dependent scaling methods are called before
ScreenScaler.init(context).
- Improved variable naming and use of
Updated #
- Example App.
- The example in
example/lib/main.darthas been updated to demonstrate the new singleton initialization, extension methods (.h,.w,.sp), and API usage.
- The example in
- Unit Tests.
- Tests in
test/flutter_screen_scaler_test.darthave been updated to reflect all API changes, cover new extension methods, and test new functionalities like parent-relative scaling and responsive font scaling. Invalid null-check tests were removed due to non-nullable parameters.
- Tests in
1.0.0 17/06/2019 #
- Added support for getting the width dynamically using percentages.
- Added support for getting the height dynamically using percentages.
- Added support for getting the text size dynamically using percentages.
2.0.0 08/10/2019 #
- Completely rewrote the screen scaling methods.
- Added support for getting the padding dynamically using percentages.
- Added support for getting the margin dynamically using percentages.
- Added support for getting the a size dynamically using percentages.
2.1.0 18/12/2021 #
- Null Safety