Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
14
Help us understand the problem. What is going on with this article?
@Idenon

Flutter ちょっと Tips 〜要素サイズいっぱいに表示する〜

More than 1 year has passed since last update.

画面いっぱいに何かを表示したい

Container の constraints: BoxConstrains.expand() で、expand メソッドに何も渡さなければ要素のサイズいっぱいに表示してくれる。
この手の実装としては必要最低限だけど、取っ掛かりとしてここから考えると良さそうな感じ。

    return Container(
      constraints: BoxConstraints.expand(),
      child: 【表示したいもの】
    );

とりあえず動かしたい人向け
コピペすれば動く

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: Text(_title)),
        body: ImageWidget(),
      ),
    );
  }
}

class ImageWidget extends StatelessWidget {
  ImageWidget({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      constraints: BoxConstraints.expand(),
      child: Image.network(
          "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=369577&type=card",
          fit: BoxFit.contain),
    );
  }
}

fit: BoxFit.contain のところが、「画面サイズに合わせて画像が全部表示されるギリギリの大きさまで拡大する」の意味みたい。

公式ドキュメント

Container
https://api.flutter.dev/flutter/widgets/Container-class.html

BoxConstraints.expand constructor
https://api.flutter.dev/flutter/rendering/BoxConstraints/BoxConstraints.expand.html

Image.network
https://api.flutter.dev/flutter/widgets/Image/Image.network.html

BoxFit enum
https://api.flutter.dev/flutter/painting/BoxFit-class.html

14
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Idenon
記憶を無くした未来のオレへのメモを書く
cloudpack
Amazon Web Services (AWS) の導入設計、環境構築、運用・保守をサポートするマネジドホスティングサービス

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
14
Help us understand the problem. What is going on with this article?