[SOLVED] Is there a way to apply media query to padding top in flutter?

Issue

This Content is from Stack Overflow. Question asked by signature

Is there a way to apply media query to padding top in flutter? The location of top, left, right, bottom is different for each device, so how do I solve it?

import 'package:flutter/material.dart';

class menuwidget3 extends StatelessWidget {
  const menuwidget3({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xfff9f9f9),
      body: SafeArea(
        child: Stack(
          children: [
            Padding(
              padding: const EdgeInsets.only(top: 20, left: 15),
              child: Row(
                children: const [
                  Padding(
                    padding: EdgeInsets.only(left: 5),
                    child: Text(
                      'first',
                      style: TextStyle(
                          color: Colors.black,
                          fontFamily: 'Pretendard',
                          fontWeight: FontWeight.w600,
                          fontSize: 20),
                    ),
                  ),
                ],
              ),
            ),



Solution

Remove const and you should be good to go.

padding:  EdgeInsets.only(top: MediaQuery.of(context).size.width * 0.2, left: MediaQuery.of(context).size.width *0.1),


This Question was asked in StackOverflow by signature and Answered by Akhil George It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?