5
0

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 1 year has passed since last update.

【flutter】横スクロールをするには?

5
Last updated at Posted at 2023-09-05

こんにちは。
今回は、横スクロールを実装する方法を紹介します。

方法

スクリーンショット 2023-08-13 20.18.51.png

Rowの要素を横スクロールするには、SingleChildScrollViewを使います。

まず、RowをSingleChildScrollViewでラップします。

そして、SingleChildScrollViewの引数「scrollDirection」にAxis.horizontalを指定します。

使用例

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.pink, //背景の色を選択
        title: const Text("Flutter!!!!"), //タイトルを表示
      ),
      body: SingleChildScrollView(//スクロール
        scrollDirection: Axis.horizontal,//スクロールの方向、水平
        child: Row(
          children: [
            Container(
              height: 200,
              width: 200,
              decoration: const BoxDecoration(
                color: Colors.blue,
                shape: BoxShape.circle,
              ),
            ),
            Container(
              height: 200,
              width: 200,
              decoration: const BoxDecoration(
                color: Colors.yellow,
                shape: BoxShape.circle,
              ),
            ),
            Container(
              height: 200,
              width: 200,
              decoration: const BoxDecoration(
                color: Colors.black,
                shape: BoxShape.circle,
              ),
            ),
            Container(
              height: 200,
              width: 200,
              decoration: const BoxDecoration(
                color: Colors.green,
                shape: BoxShape.circle,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

実行例

qiita_gif.gif

5
0
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
5
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?