Unlocking design adaptability, the size_setter package for Flutter elegantly recalibrates pixels into responsive percentages, revolutionizing cross-device aesthetics with minimal effort. To learn more about this, please visit the following article size_setter
- It converts pixel sizes to percentages, utilizing the source device size as a reference
- The result is layouts that seamlessly adapt to various devices.
- Based on the device, convert your numerical numbers to percentages.
- A streamlined solution for the Space between the widgets.
Add to pubspec.yaml.
dependencies:
...
size_setter: ^1.0.8
.h
- It Converts pixels into dynamic percentage based on source device height.w
- It Converts pixels into dynamic percentage based on source device width.ph
- Returns a percentage value of screen height.pw
- Returns a percentage value of screen width.px
- Returns a calculated pixel based on the device for fonts.sp
- Returns a calculated sp based on the device for fonts.heightBox
- Returns a calculated SizedBox with height.widthBox
- Returns a calculated SizedBox with width.pWidthBox
- Returns a calculated SizedBox with percentage of screenSize Width.pHeightBox
- Returns a calculated SizedBox with percentage of screenSize Height
import 'package:size_setter/size_setter.dart';
SizeSetter(
child:MaterialApp(),
)
If you're developing your application using designs created in tools like Figma,Convert your pixels into percenage based on source device size,
SizeSetter(
sourceWidth:430,
sourceHeight:840,
child:MaterialApp(),
)
Convert Your MaterialApp to Stateful Widget Add following code
@override
void didChangeDependencies() {
SizeSetterUtils.setSourceDeviceSize(
context: context,);
super.didChangeDependencies();
}
@override
void didChangeDependencies() {
SizeSetterUtils.setSourceDeviceSize(
context: context,sourceWidth: 300, sourceHeight: 700);
super.didChangeDependencies();
}
Container(
width: 20.pw, //It will take a 20% of screen width
height:30.ph //It will take a 30% of screen height
)
SizedBox(
width: 200.w, //It will convert pixels into responsive percentage based on source device width
height:300.h //It will convert pixels into responsive percentage based on source device width
)
.pWidthBox
- it returns a gap with a percentage of the screen width size
SizedBox(
width:MediaQuery.of(context).size.screenWidth*0.7
)
//or
70.pWidthBox
.pHeigthBox
- it returns a gap with a percentage of the screen width size
SizedBox(
width:MediaQuery.of(context).size.screenHeight*0.7
)
//or
70.pHeightBox
.heightBox
- it returns a gap with a dynamic size height, mainly used to make it responsive.
SizedBox(
height:200.h
)
//or
200.heightBox
.widthBox
- it returns a gap with a dynamic size width, mainly used to make it responsive.
SizedBox(
width:200.w
)
//or
200.widthBox
Text(
'Hello World',style: TextStyle(fontSize: 15.sp),
);
//or
Text(
'Hello World',style: TextStyle(fontSize: 15.px),
);
If you have any suggestion for including a feature or if something doesn't work, feel free to open a Github issue for us to have a discussion on it.