flutterで、ページ内に枠を表示させ、その枠内に画像を並べて表示させる

# やりたいこと

緑色の枠内に、画像を並べて表示させる。
画像は緑色の枠内からはみ出すことなく自動で改行する。
画像の枚数が増えれば、比例して緑枠の縦サイズが長くなる。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/75451/cb6f1c6c-a081-3c4c-2f14-8620d086bb3c.png)

# 枠の表示

```dart

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Container(
        width: 200,
        decoration: BoxDecoration(border: Border.all(color: Colors.green, width: 9.0,)),
      ),
    );
  }
}

```


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/75451/9cf9a537-bf5e-28ad-7829-df0fae262856.png)



# 画像の表示

```dart
        child: Wrap(
        children: <Widget>[
          Image.network('https://www.10wallpaper.com/wallpaper/1366x768/2005/Mountains_Rocks_Lake_2020_Landscape_High_Quality_Photo_1366x768.jpg', width: 125,),
          Image.network('https://www.10wallpaper.com/wallpaper/1366x768/1711/Cute_Small_Chicken_2017_Animal_HD_Wallpaper_1366x768.jpg', width: 125,),
          Image.network('https://www.10wallpaper.com/wallpaper/1366x768/1501/Fighter_Jets-Military_HD_Wallpaper_1366x768.jpg', width: 125,),
          Image.network('https://www.10wallpaper.com/wallpaper/1366x768/1806/FIFA_World_Cup_2018_Peru_Christian_Cueva_1366x768.jpg', width: 125,),
          Image.network('https://www.10wallpaper.com/wallpaper/1366x768/1501/lufthansa_airport-Military_HD_Wallpaper_1366x768.jpg', width: 125,),
          Image.network('https://www.10wallpaper.com/wallpaper/1366x768/1901/2019_Resident_Evil_2_Game_HD_Poster_1366x768.jpg', width: 125,),
          Image.network('https://www.10wallpaper.com/wallpaper/1366x768/2003/African_Safari_Elephants_2020_Animals_HD_Photo_1366x768.jpg', width: 125,),
        ],
        )
```

を追加する。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/75451/cb6f1c6c-a081-3c4c-2f14-8620d086bb3c.png)



# 完成形 main.dart

```dart
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Container(
        width: 200,
        decoration: BoxDecoration(border: Border.all(color: Colors.green, width: 9.0,)),
        child: Wrap(
        children: <Widget>[
          Image.network('https://www.10wallpaper.com/wallpaper/1366x768/2005/Mountains_Rocks_Lake_2020_Landscape_High_Quality_Photo_1366x768.jpg', width: 125,),
          Image.network('https://www.10wallpaper.com/wallpaper/1366x768/1711/Cute_Small_Chicken_2017_Animal_HD_Wallpaper_1366x768.jpg', width: 125,),
          Image.network('https://www.10wallpaper.com/wallpaper/1366x768/1501/Fighter_Jets-Military_HD_Wallpaper_1366x768.jpg', width: 125,),
          Image.network('https://www.10wallpaper.com/wallpaper/1366x768/1806/FIFA_World_Cup_2018_Peru_Christian_Cueva_1366x768.jpg', width: 125,),
          Image.network('https://www.10wallpaper.com/wallpaper/1366x768/1501/lufthansa_airport-Military_HD_Wallpaper_1366x768.jpg', width: 125,),
          Image.network('https://www.10wallpaper.com/wallpaper/1366x768/1901/2019_Resident_Evil_2_Game_HD_Poster_1366x768.jpg', width: 125,),
          Image.network('https://www.10wallpaper.com/wallpaper/1366x768/2003/African_Safari_Elephants_2020_Animals_HD_Photo_1366x768.jpg', width: 125,),
        ],
        )
      ),
    );
  }
}

```