Home > Blockchain >  Responsive flutter web page for mobile browser and desktop browser
Responsive flutter web page for mobile browser and desktop browser

Time:12-01

I want to build responsive webpage for mobile browser and webbrowser.

My problem is the webpage in desktop browser resolution looks good in that, but the same page is looking too small in mobile browser.

How to have responsive design for mobile and web browser

CodePudding user response:

There are multiple ways to achieve responsiveness in Flutter cross-plattform applications:

  1. Use a package on pub.dev, like the responsive_framework.
  2. Use the build-in MediaQuery class to get the screensize, then define custom breakpoints (e.g, 1200 px for desktop, 800px for tablet and 480 px for mobile). Learn more here.

In both options you can show your CustomLayout Widgets conditionally:

if (isMobile) {
    return MyMobileHomeScreen();
  } else if (isDesktop) {
    return MyDesktopHomeScreen();
  } else {
    return MyTabletHomeScreen();
  }

Packages can make your life a bit easier, but nonetheless you should checkout the official docs to learn how to tackle responsiveness on your own to get a better understanding!

CodePudding user response:

Acording to the oficial documentation: https://docs.flutter.dev/development/ui/layout/adaptive-responsive

Flutter allows you to create apps that self-adapt to the device’s screen size and orientation.

There are two basic approaches to creating Flutter apps with responsive design:

Use the LayoutBuilder class From its builder property, you get a BoxConstraints object. Examine the constraint’s properties to decide what to display. For example, if your maxWidth is greater than your width breakpoint, return a Scaffold object with a row that has a list on the left. If it’s narrower, return a Scaffold object with a drawer containing that list. You can also adjust your display based on the device’s height, the aspect ratio, or some other property. When the constraints change (for example, the user rotates the phone, or puts your app into a tile UI in Nougat), the build function runs.

Use the MediaQuery.of() method in your build functions This gives you the size, orientation, etc, of your current app. This is more useful if you want to make decisions based on the complete context rather than on just the size of your particular widget. Again, if you use this, then your build function automatically runs if the user somehow changes the app’s size.

  • Related