34
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Flutter でデバイスの画面サイズを得る MediaQuery

Posted at

Flutter で、デバイスの画面サイズを得るには MediaQuery という Widget を使います。

@override
Widget build(BuildContext context) {
  final Size size = MediaQuery.of(context).size;
  
  // sizeを使って何かする
  return new Container(
    width: size.width,
    ...
  );
}

※画面に表示されるようなものではないですが、こういうのも含めて「みんなWidget」です

また、前提としてコンテキストの先祖に WidgetsAppMaterialApp が存在していることが必要です。

34
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?