0

I want my app to remain similar as it is in mobile . I want to add white spaces from left and right in tablet so that it doesnot create any mess and look similar to the mobile . I have tried layout builder to do that but in that case i need to edit every screen and every class of my project i am searching for something else which can be applied on one place only leading to add white space margins from left and right in the tablet so that the screen size remains same as to that of mobile .

5
  • use Padding widget: Padding(child: MaterialApp(...), ...) Commented May 12, 2023 at 6:31
  • Maybe I misunderstood you.. but when you say: "...same as to that of mobile..". Which mobile with which resolution? And if you don't select the smallest screen size that your app can run on, what do you want to happen when a smaller size is used than the one you have as your "mobile" definition? Commented May 12, 2023 at 6:33
  • a mobile of 6.3 inches , i have handled all the cases for lower than this screen size but for tablets i need help Commented May 12, 2023 at 6:40
  • for tablet , i want to use something like layout builder buddy Commented May 12, 2023 at 6:58
  • i need to apply layout builder at every place of my project and my project is very large in size i want something which i apply on one place and the change happens Commented May 12, 2023 at 8:49

1 Answer 1

0

You can achieve that with LayoutBuilder. The MainContentWidget is the main content widget. You render the main content widget if the screen width is less than 600 otherwise you specify the content width which by the sample code provided below is 60% of the screen then position it at the center.

Container(
    constraints: BoxConstraints.expand(),
    color: Theme.of(context).scaffoldBackgroundColor,
    child: LayoutBuilder(
      builder: (BuildContext context, BoxConstraints constraints) {
        if (constraints.maxWidth < 600) {
          return MainContentWidget();
        }

        return Center(
          child: SizedBox(
            width: MediaQuery.of(context).size.width * 0.60,
            child: MainContentWidget(),
          ),
        );
      },
    ),
  )
Sign up to request clarification or add additional context in comments.

3 Comments

i dont want to use layout builder anything else?
@VIADISHWARSHARMA That's what the Flutter team recommend for this use case.
can i do this in my main file?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.