Comments (2)
The method of approach would differ from person to person. There is no specific guideline that should follow. Since devices come in different screen sizes, screen resolutions, and screen densities, it is impossible to perfectly mimic the same figma design across multiple devices. For example, comparing two phones with the same physical height but with slightly different physical widths, the same figma design may look a little bit more squeezed in the narrow phone than the one in the wider phone.
The standard and complex approach is the web approach, which is to have set breakpoints that dictate how big the container should be. (Eg: 10px for mobile, 15px for tablet, and 20px for desktop) This approach is something that I would recommend if you have a complex flutter project and it needs to support a wide range of screens. (Mobile
, Tablet
, and Desktop
sizes)
Note that this is time-consuming since you'd have to make 3 different layouts for each screen. See what I mean here.
Another approach that is simple would be to use percentages (which is what ResponsiveSizer
helps you do). If I set my container to take 20% of a device's width, it will always take 20% of its width regardless of the device's size. We could use ratios (intended size / max size
) to make similarly shaped mobile devices closely follow your figma design.
Here's an example with your 60 x 60
container. Our intended size
is 60.
We start by choosing the lower value of your device frame 480 x 320
and use it (320)
as our max size
. Take note that the lower value here is the device's width. Since the device's width is the lower value, we will be setting the container's sizes to (intended size / max size).w
.
The end result would look something like this:
Container(
width: (60/320).w
height: (60/320).w
)
Since this could get ugly, you could create a function or extension similar to this:
double calculateRatio(num intendedSize) => (intendedSize / maxSize).w;
from responsive_sizer.
Thanks for the detailed answer. I'll stick to the default percentages approach.
from responsive_sizer.
Related Issues (20)
- The application works badly when you compile it HOT 11
- Why 100.sp != (50.sp)*2 HOT 2
- LateInitializationError: Field 'height' has not been initialized. HOT 16
- How can I make rebuild the screen again when I change the orientation? HOT 3
- Can not use it with provider package.
- tree rebuilds when keyboard shows HOT 1
- How to use responsive sizer when using routes and initialroute instead of home in MaterialApp? HOT 2
- Sizes do not appear to be updating correctly on Windows maximise or restore using WidgetsBindingObserver HOT 1
- ../../../development/tools/flutter/.pub-cache/hosted/pub.dartlang.org/responsive_sizer-3.0.6+1/lib/src/helper.dart:56:33: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null. HOT 3
- App doesn't run correctly when I compile it to Android HOT 12
- Add Desktop ScreenType HOT 5
- two ResponsiveSizer HOT 2
- Sp and Dp way different than with sizer and are not interchangable HOT 7
- Error using any method HOT 1
- Does not reload the screen when the device changes from Portrait to Landscape HOT 2
- The Device Class variables apsectRatio, width, and height all Resize when Textfieldforms are used. HOT 2
- unfocus in flutter 3.10 HOT 1
- Changing the device text size setting affects the outputted UI. HOT 3
- ScreenType.desktop Issue HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from responsive_sizer.