質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Flutter

Flutterは、iOSとAndroidのアプリを同じコードで開発するためのフレームワークです。オープンソースで開発言語はDart。双方のプラットフォームにおける高度な実行パフォーマンスと開発効率を提供することを目的としています。

Q&A

解決済

1回答

3390閲覧

ColumnからListViewに変更時のエラー

Inete6Q

総合スコア18

Flutter

Flutterは、iOSとAndroidのアプリを同じコードで開発するためのフレームワークです。オープンソースで開発言語はDart。双方のプラットフォームにおける高度な実行パフォーマンスと開発効率を提供することを目的としています。

0グッド

0クリップ

投稿2020/09/30 16:47

前提・実現したいこと

Columnを使ったレイアウトをListViewに置き換え、スクロール可能にしたい。
Columnでは問題なく動いていた状態でした。
項目が増えた場合にスクロール可能にしたいと思い、ColumnウィジェットをListViewウィジェットに置き換えたらエラーが発生しました。

発生している問題・エラーメッセージ

════════ Exception caught by rendering library ═════════════════════════════════════════════════════ RenderBox was not laid out: _RenderScrollSemantics#1af73 relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart': Failed assertion: line 1702 pos 12: 'hasSize' The relevant error-causing widget was: Column file:///Users/to/AndroidStudioProjects/test_app/lib/main.dart:71:16 ════════════════════════════════════════════════════════════════════════════════════════════════════ ════════ Exception caught by rendering library ═════════════════════════════════════════════════════ RenderBox was not laid out: RenderViewport#458c4 NEEDS-PAINT 'package:flutter/src/rendering/box.dart': Failed assertion: line 1702 pos 12: 'hasSize' The relevant error-causing widget was: ListView file:///Users/to/AndroidStudioProjects/test_app/lib/main.dart:93:13 ════════════════════════════════════════════════════════════════════════════════════════════════════ ════════ Exception caught by scheduler library ═════════════════════════════════════════════════════ The getter 'visible' was called on null. Receiver: null Tried calling: visible ════════════════════════════════════════════════════════════════════════════════════════════════════

該当のソースコード

flutter

1import 'package:flutter/material.dart'; 2import 'package:test_app/forth_screen.dart'; 3import 'second_screen.dart'; 4import 'third_screen.dart'; 5import 'forth_screen.dart'; 6import 'fifth_screen.dart'; 7import 'sixth_screen.dart'; 8import 'seventh_screen.dart'; 9import 'eighth_screen.dart'; 10import 'nineth_screen.dart'; 11import 'package:flutter/rendering.dart'; 12 13void main() { 14 debugPaintSizeEnabled = false; 15 runApp(MyApp()); 16} 17 18class MyApp extends StatelessWidget { 19 @override 20 Widget build(BuildContext context) { 21 return MaterialApp( 22 title: 'Flutter Demo', 23 theme: ThemeData( 24 primarySwatch: Colors.blue, 25 visualDensity: VisualDensity.adaptivePlatformDensity, 26 ), 27 home: MyHomePage(title: '1st Screen'), 28 ); 29 } 30} 31 32class MyHomePage extends StatefulWidget { 33 MyHomePage({Key key, this.title}) : super(key: key); 34 final String title; 35 @override 36 _MyHomePageState createState() => _MyHomePageState(); 37} 38 39class MakeButton extends StatelessWidget { 40 MakeButton(this.title); 41 final String title; 42 @override 43 Widget build(BuildContext context) { 44 return Container( 45 height: 50, 46 width: 120, 47 alignment: Alignment.center, 48 decoration: BoxDecoration( 49 color: Colors.lightBlue, 50 borderRadius: BorderRadius.all(Radius.circular(5.0)), 51 ), 52 child: Text( 53 this.title, 54 style: TextStyle( 55 color: Colors.white, 56 fontWeight: FontWeight.bold, 57 ), 58 ), 59 ); 60 } 61} 62 63class _MyHomePageState extends State<MyHomePage> { 64 @override 65 Widget build(BuildContext context) { 66 return Scaffold( 67 appBar: AppBar( 68 title: Text(widget.title), 69 ), 70 body: Center( 71 child: Column( 72 children: [ 73 Padding( 74 padding: const EdgeInsets.only(top: 30), 75 child: Hero( 76 tag: 'tag', 77 child: ClipRRect( 78 borderRadius: BorderRadius.all(Radius.circular(30)), 79 child: Container( 80 height: 250, 81 width: 250, 82 decoration: BoxDecoration( 83 gradient: LinearGradient( 84 colors: [Colors.lightBlue, Colors.indigo]), 85 ), 86 ), 87 ), 88 ), 89 ), 90 SizedBox( 91 height: 30, 92 ), 93//下の行のWidgetをColumnからListViewへ変更時にエラー発生 94 **ListView**( 95 children: [ 96 Row( 97 mainAxisSize: MainAxisSize.min, 98 children: [ 99 MaterialButton( 100 padding: EdgeInsets.all(0), 101 onPressed: () { 102 Navigator.push( 103 context, 104 MaterialPageRoute( 105 builder: (context) => SecondScreen()), 106 ); 107 }, 108 child: MakeButton('2nd Screen'), 109 ), 110 SizedBox( 111 width: 15, 112 ), 113 MaterialButton( 114 padding: EdgeInsets.all(0), 115 onPressed: () { 116 Navigator.push( 117 context, 118 MaterialPageRoute( 119 builder: (context) => ThirdScreen()), 120 ); 121 }, 122 child: MakeButton('3rd Screen'), 123 ), 124 ], 125 ), 126 SizedBox( 127 height: 15, 128 ), 129 Row( 130 mainAxisSize: MainAxisSize.min, 131 children: [ 132 MaterialButton( 133 padding: EdgeInsets.all(0), 134 onPressed: () { 135 Navigator.push( 136 context, 137 MaterialPageRoute( 138 builder: (context) => ForthScreen()), 139 ); 140 }, 141 child: MakeButton('4th Screen'), 142 ), 143 SizedBox( 144 width: 15, 145 ), 146 MaterialButton( 147 padding: EdgeInsets.all(0), 148 onPressed: () { 149 Navigator.push( 150 context, 151 MaterialPageRoute( 152 builder: (context) => FifthScreen()), 153 ); 154 }, 155 child: MakeButton('5th Screen'), 156 ), 157 ], 158 ), 159 SizedBox( 160 height: 15, 161 ), 162 Row( 163 mainAxisSize: MainAxisSize.min, 164 children: [ 165 MaterialButton( 166 padding: EdgeInsets.all(0), 167 onPressed: () { 168 Navigator.push( 169 context, 170 MaterialPageRoute( 171 builder: (context) => SixthScreen()), 172 ); 173 }, 174 child: MakeButton('6th Screen'), 175 ), 176 SizedBox( 177 width: 15, 178 ), 179 MaterialButton( 180 padding: EdgeInsets.all(0), 181 onPressed: () { 182 Navigator.push( 183 context, 184 MaterialPageRoute( 185 builder: (context) => SeventhScreen()), 186 ); 187 }, 188 child: MakeButton('7th Screen'), 189 ), 190 ], 191 ), 192 SizedBox( 193 height: 15, 194 ), 195 Row( 196 mainAxisSize: MainAxisSize.min, 197 children: [ 198 MaterialButton( 199 padding: EdgeInsets.all(0), 200 onPressed: () { 201 Navigator.push( 202 context, 203 MaterialPageRoute( 204 builder: (context) => EighthScreen()), 205 ); 206 }, 207 child: MakeButton('8th Screen'), 208 ), 209 SizedBox( 210 width: 15, 211 ), 212 MaterialButton( 213 padding: EdgeInsets.all(0), 214 onPressed: () { 215 Navigator.push( 216 context, 217 MaterialPageRoute( 218 builder: (context) => NinethScreen()), 219 ); 220 }, 221 child: MakeButton('9th Screen'), 222 ), 223 ], 224 ), 225 ], 226 ), 227 ], 228 ), 229 ), 230 ); 231 } 232}

補足情報(FW/ツールのバージョンなど)

省略。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

shrinkWraptrueに設定することで、解決すると思います。

dart

1ListView( 2 shrinkWrap: true, 3 children: ... 4),

もしくは、こんな感じでListView自体に高さを設定するという方法もあります。

dart

1Container( 2 height: 300, 3 child: ListView( 4 children: ... 5),

投稿2020/09/30 22:02

nskhei

総合スコア704

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Inete6Q

2020/10/01 00:31

どちらでもうまく動きました!ありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問