How to develop different screen sizes? - flutter

I have a private problem and a more general problem.
I have a container with some Text widgets and I set he's height to
height: MediaQuery.of(context).size.height*0.26,
If i'm in big screen(I'm not talking about Landscape mode/Portait mode) the container looks fine, but if I am at small screen I have error that there is no space for the text.
How do I get over it?
And more general question, I've also problem with the space between widgets(big screen there is too much space, small screen there is no space etc)
What is the best solution for this problem(Develop for different screen sizes)

Related

Flutter Responsive Layout

I am working on building a mobile application using flutter and am stuck on building a resposive login screen layout. To be precise, I am using the MediaQuery to find the screen size and to find the safe area and based on that I am spacing and building containers based on percentage of screen height. I would like to know if this is the best way or if I am unnecessarily complicating the entire process. I did come across a few youtube videos where most of them give random numbers but when I try doing that, my layout most often than not ends of overflowing!
So far, I have mostly done this with just mathematical calculations. i.e. I have stuck to calculating the available height (total height - safe area) and then built all my containers based on this height (including their spacing). But, I am struggling with getting the right font size and this constant struggle to balance the UI in both android and iOS setup is eating up most of my time.
I built hundreds of screens in Flutter. It is very rare that you need to use exact screen height for a layout. Most screens fall into one of the three categories:
There are too many elements to fit into a screen of any size.
In this case you wrap your layout in SingleChildScrollView widget that has a Column child, and then put all other widgets in that Column. Users scroll down to see all visible elements they need to see.
There are too many elements to fit into smaller screen sizes, but they fit into larger screens.
In this case you still wrap your layout in SingleChildScrollView widget. Then you make your layout look nice on larger screens, but users on smaller screens still have to scroll down. This is not ideal, but sometimes it's the right solution. Making design elements smaller on a small screen often makes it hard to use or even totally unusable. Plus, having various calculations related to a screen size in your layout logic makes it a nightmare to test your app: you have to test it on all sorts of screen sizes.
All design elements can fit into a small screen.
In this case you should use Flex widgets (like Column, Row, Spacer, Center, etc.) to create your layout. These widgets already have a logic for spacing their children in the available space (for example, using mainAxisAlignment and crossAxisAlignment properties in Column and Row).
There are also widgets that can take a specified percentage of a screen (or their parent widget), but I never use them. I can imagine situations where these widgets can be useful, but for the vast majority of designs using Flex layout is a better option that results in better looking screens.
If you post your design and the layout you came up with, we can point if there are ways to optimize it.

Flutter Responsive Grid with Cards (screenshots)

I am very new to flutter and modern programming languages at all. At the moment I am working together with someone in order to create an app.
We are having problems with the layout of the grid and cards with different screen sizes and orientations.
Vertical Screen Screenshot
Horizontal Screen Screenshot
As you can see, the cards are messed up as soon as the screen width is too high. I don't have access to the source code right now, as the person programming it, is not available at the moment.
I read a lot about different techniques to build a card grid like that in a responsive way.
My guess the problem is, that the cards are not in containers with a fixed size. If they were, the pictures / buttons and texts inside that container would always look the same. Is that assumption correct?
Then my other idea was to use ResponsiveGridListBuilder to solve the problem that too few cards are shown in horizontal mode.
But as I said ... I am a newbie in flutter, so if any of you could make suggestions, I would be happy!
If possible, some code as an example would also help a bunch.
So far the programmer only tried different calculations of the cards in comparison to the screensize, but this didn't help as you can see.
Cheers!
I think it's better you use Wrap to fill the Row even in horizontal or vertical screens. but if i was in your shoes i would develop the items that are suitable and has const size for vertical and horizontal sizes, and let them to fill theirselves in the row depends on the width screen size that it has.
if you didn't understand what i mean i can explain it more my friend :)
happy coding...

How to make Flutter responsive for Web? Not working: MediaQuerys, fixed pixels, and BoxConstraints, etc

I am coding a website with Flutter. My layout uses "blocks" of vertical content laid within a SingleChildScrollView. They look like rectangles of content (with images, text, buttons, etc in them), taking up the whole screen horizontally, and the whole screen vertically.
Currently, whenever I move the screen size around (drag the web window to be different sizes) the website breaks. If I move it to be really small horizontally, I cannot fit in the content I need, if I move it to be small vertically I get overflow errors (and vice versa). This is because I am using MediaQuery.of(context).size.height/width to layout my website.
My rectangular blocks of "content" all have their same respective parent: Container(width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height) so they completely adjust everytime I move the window. Is there a better way to implement responsive web? Would it be better to just specify (for example) 620 pixels height for the Container and double.infinity for the width? And then somehow make everything fit inside not overflow/look weird? Also, when I drag the bottom of the web window nothing expands/grows properly because at that same time all my "content blocks" are all resizing their height because I am technically resizing the screen.
Finally, I've tried using BoxConstraints's minHeight, maxHeight, minWidth, and maxWidth, yet they don't seem to work and still produce the yellow/black overflow lines when testing in a webview. Huh?
Also, how would I get a bottom scrollbar to appear horizontally once my webview window is fully dragged close horizontally and half my content is cut off, but I still would like to see it. Would this be necessary? Or would another solution not need this? I'm not sure...
How are other people working around this and achieving this? I feel like I am doing this completely wrong. It shouldn't be this difficult.
(Also, using LayoutBuilder I have 2 additional builds for mobile/tablet when the screen width reaches less than 1100px)

How do I make my label in Unity size to fit its text?

I am working on the credits for my mobile game and I have a license attribution thing at the end that is relatively long. On normal phone screen sizes it fits properly, but on notched phones, a big chunk of the end gets cut off and on tablets, there is a lot of empty space at the top and bottom. I had both the label and the content panel of the ScrollView for the credits set to the anchor preset which is anchored to the top of the parent but stretches horizontally and I tried changing it so that they stretch vertically too and that did nothing. I also tried moving the label's anchors to its own corners (but didn't do that with the content panel's anchors because that's not possible), but that also did nothing. I asked this on Unity Answers earlier this week and they haven't been very helpful. How do I make the text not get cut off or have a lot of extra space?
I eventually just clicked "Best Fit" on the text and now it fits properly. I was worried that it would look bad if it was a different size on different screens, but it doesn't seem to be a huge problem.

Is iPhone's Safari resolution treated differently than the rest of the device?

I have an image that is 480x270. In theory this should occupy all the space between the battery bar on top and the navigation bar at the bottom when the phone is rotated on to its side. However, inexplicably the image is displayed shrunken to where it barely occupies 1/2 the screen horizontally.
I thought perhaps the phone is shrinking the image for some reason, so I just created a div that has its dimensions set to the same size as the image and nothing in it but a background color. The phone displays this rectangle of color in exactly the same dimensions as the graphic.
So, the question is, is Safari compensating in some way and displaying things in a reduced ratio, and if so, WHAT is that ratio?! (or am I just totally out of my mind?)
Check out viewport.