LoginSignup
8
0

More than 3 years have passed since last update.

FlutterのGridViewをスクロールしないようにして親Containerをスクロールするようにする方法

Posted at

やりたいこと

Container の中に GridView があって、 GridView 内でスクロールするのではなく、 Container 全体をスクロールするようにする。

実装

GridView のプロパティーに

physics: NeverScrollableScrollPhysics()

これを設定しておけばスクロールしなくなる

以下、サンプルコード

    return Scaffold(
      appBar: AppBar(
        title: Text(
          "sample",
        ),
      ),
      body: SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.all(10),
          color: Theme.of(context).primaryColor,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            mainAxisSize: MainAxisSize.max,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text("テスト1",),
                  Text("テスト2",),
                ],
              ),
              GridView.count(
                shrinkWrap: true,
                primary: true,
                padding: const EdgeInsets.all(1.0),
                crossAxisCount: 4,
                childAspectRatio: 0.85,
                mainAxisSpacing: 1.0,
                crossAxisSpacing: 1.0,
                physics: NeverScrollableScrollPhysics(),    //これをいれておくとGridView内でスクロールしなくなる
                children: _sampleContainer(context),
              ),
            ],
          ),
        ),
      ),
    );

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