Releases: akassharjun/flutter-screen-scaler
Releases · akassharjun/flutter-screen-scaler
v3.0.0
[3.0.0] - 05/06/2025
Breaking Changes
- Refactored
ScreenScaler
to 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
getWidth
andgetHeight
.- These methods now consistently return a direct percentage of the screen width/height.
- The previous complex scaling logic based on
_fixedWidth
and_fixedHeight
(which involvedlog
and screen ratio adjustments) has been removed to ensure straightforward percentage scaling. - The constants
_fixedWidth
and_fixedHeight
have 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-nullabledouble
parameters.
- Methods like
Added
- Extension Methods for Concise Scaling.
- Added extension methods on
num
for 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.sp
extension. - 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
final
for local variables. - Introduced
_kDefaultDecimalPlaces
constant 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.dart
has 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.dart
have 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