Flutter responsiveness desing - android

i am a new flutter developer. I have problem with application responsiveness, I have worked with layout widgets such as column rows etc but the results in different screens differ.
I need help on how to achieve responsiveness with less dependencies help please.

You haven't provided any code which makes it difficult to answer. So I am going to take a very generic approach here. Checkout the below points and try to use them wherever you can:
Expanded Widget - Can make its child/children grow/shrink based on available screen space
Flexible Widget - Similar as above but with slight difference
MediaQuery - Can give the exact screen height and width of the physical device. This information you can use to define different screens/layouts for mobile/tab/desktop
Visibility Widget - Can hide/show based on certain condition. Use MediaQuery to get screen size and then based that hide/show sections of your screen
LayoutBuilder - provides the parent widget's constraints at layout time.
And finally, checkout this official blog from flutter team on Responssive UI Design.

Related

Responsive Layout in XML

Which is the best option to create a responsive layout design? The first question is what should be the height and width of every view (it should be in percentage, match constraint or wrap content using constraint layout).
If we use wrap content I think there is no way to create a responsive design with help of wrap content because if content increase the view will take all the space of the screen either vertically or horizontally
If we use match constraint then, in that case, it's good, but sometimes it is looking awesome on Android Studio but when we run it on a real device it doesn't look the same
The last option is to use percentage, in that case, I think first we have to check our item list vertically and horizontally and provide them space according to their content priority and usage
So what will be the best case to create a responsive layout in XML for Android?
It depends on UI.generaly people use the 2nd and 3rd methods because by using constraints and percentages you can get responsive UI.
sometimes it depends on your requirement.
if you are using the percentage method and you set the imageView at 10 % it's looking proper on your device but sometimes it happened that in a small device that imageView is not looked proper
So the moral is all your three methods can be applied as per UI you can not make all designs responsive using 1 method

can flutter adjust widget size automatically in different device?

I'm new in flutter and haven't used android before. When I complete pages, I simply set the width and height of a widget according to the XD designed by UI designers. As I know UI designers usually set the size according to some one phone type. My question is: If the flutter program run in different devices, how can I change widgets' size automatically to adapt to the phone(or ipad). As we can imagine, if my program is based on ipad mini(1024x768), the designed widget size will be a little big, then some error maybe occur if I run the program in a samller device(like modbile phone) I think. Thanks for any help.
If all widget's are placed static and have proportional size, then you can use https://pub.dev/packages/flutter_screenutil, this library or MediaQuery widget.
Or design have ratio size, then you can use Flexible and Expandable widgets as you need.

Android, why is there no way to set size proportional to parent

I have looked for question on this website and through google but there are no easy ways to set the size of the a View proportional to the parent.
Since android is a language that runs on devices of many screen densities and sizes it would make sense to have an easy to use method to set the size of views based upon the parent such as: 0.5*match_parent
I found some solutions but none of them are simple single lines that you would expect would be built into android, since every android app needs to support many screen sizes.
Is there some restriction because of the way activities are built? Is it inefficient to have to retrieve the size of the parent?
Now it is possible to set size proportional to parent. The Constraint Layout
allows to do it.
Check this answer for more details

what is the iOS equivalence of Android RelativeLayout/LinearLayout?

How do I control the relative position of views, especially I wish my app to run on 3.5 inch display and 4 inch display seamlessly?
As of iOS 9 you can use UIStackView, which works very similarly to LinearLayout: you add views and the stack view arranges them as needed based on your sizing option – if you're using Interface Builder you can experiment with each of the options to see which one suits your needs. You can also set spacing between views in the stack view, adding some padding.
WARNING: When adding stack view child views in code you should always use addArrangedSubview() like this:
stackView.addArrangedSubview(someView)
If you try to use plain old addSubview() it won't work correctly, because the stack view won't know to arrange it.
As for removing, you need to be careful to use stackView.removeArrangedSubview(someView) and someView.removeFromSuperview() otherwise the view won't be removed correctly.
You might find my UIStackView tutorial useful.
There is no equivalent or relative and linear layouts. The UI elements have autoresizing masks which define how will they be moved/stretched when their superview is resized (e.g. screen rotation). You can also use layout constraints for positioning if you intend to build your app for iOS 6+. If you can't solve the repositioning using these tools, you should change the frames of the UI elements in your code.
Check out this: iOS 6 apps - how to deal with iPhone 5 screen size? and How to add iPhone 5 large screen support to iOS apps in Xcode?
But it's done for you for the most part with auto layout. Click on your project in Xcode and go to the Summary tab to add the different screen size launch screen for your app.
Auto-Layout system ≫ RelativeLayout
UIStackView ≈ LinearLayout
IMO. UIStackView was not well designed
can't easily add extra constraints between subviews/subview and superview
it's too often to produce conflicts of constraints
x. iOS 9+ only
So i wrote AutoLinearLayoutView, a replacement of UIStackView.
Demo screenshot
Checkout from Github AutoLinearLayoutView

Android UI based on top and left property

I was working with Android UI in Eclipse and found it to be bit hectic. Designing layout using layout managers is bit time consuming. So i was wondering whether it is possible to specify the position of the UI elements based on (x,y) system i.e top and left property which is widely used in Visual Studio IDE for VB,C# etc ?
Positioning element based on top and left property would provide much flexibility.
How would that be flexible? Yes, doing layout correctly takes time, but if you do it right, it will scale properly to any screen size. If you're using X/Y coordinates, you will be hardcoding to a specific screen size, which is an especially bad idea on Android (as there are a multitude of screen sizes available).
If you need x, y positioning, you can use a FrameLayout with foregroundGravity set to top|left, and use layout_marginLeft for the x value, and layout_marginTop for the y value.
You can use AbsoluteLayout and suppress deprecation warnings in your code, but think of how will it look on different screen sizes?
I would advise to use RelativeLayout in your case.
As far as I know, there is no built-in layout that is based on (x, y) coordinates. You might be able to find 3rd party libraries that can do this for you. However, I'm skeptical that they will provide satisfactory results. Remember that Android is deployed on a wide variety of devices which include a range of different screen sizes and resolutions. This means that you can make the UI look pretty on one device using specific coordinates but it won't look very good on other devices.
Personally, I edit my UI layouts directly in the XML files. I find that this provides me better control than using the Eclipse UI editor. You still have to learn how the layout managers themselves work.
Android tries to ensure that your layout components are arranged nicely so that they:
don't overlap with each other
don't go off the screen space
look similar on different screen sizes
etc
It gives you nice XML Attributes to help you arrange your layout. I would recommend you use RelativeLayout for this application, because it allows you to put your layout components in positions RELATIVE to each other.
Some XML attributes you can specify are given here: Android Reference, RelativeLayout.LayoutParams

Categories

Resources