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

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

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

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

Darknet

Darknetは、C言語で記述されたオープンソースのニューラルネットフレームワークで簡単にインストールすることが可能です。学習済みモデルとアルゴリズムも配布しており、ダウンロードすれば容易に動かすこともできます。

Q&A

解決済

1回答

785閲覧

FlutterでListView.builderの中にListView.builderを入れたいです

9nahito

総合スコア45

Flutter

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

Darknet

Darknetは、C言語で記述されたオープンソースのニューラルネットフレームワークで簡単にインストールすることが可能です。学習済みモデルとアルゴリズムも配布しており、ダウンロードすれば容易に動かすこともできます。

0グッド

0クリップ

投稿2022/09/17 10:59

編集2022/09/18 09:48

実現したいこと

Flutterで ListView.builder の中に さらに、ListView.builder を入れたいです!
Flutterでカレンダーのようなシステムを作っています。
scrollDirection: Axis.horizontal,で横並びに指定したListView.builder のそれぞれの中に 縦並びのListView.builderを入れようと思っています!

追記: 解決しました!

ta.fu さんのコードをもとにして GridView の中に ListView を入れることで解決しました。
イメージ説明

dart

1import 'package:flutter/material.dart'; 2import 'package:flutter/rendering.dart'; 3 4void main() => runApp(const MyApp()); 5class MyApp extends StatelessWidget { 6 const MyApp({super.key}); 7 8 // This widget is the root of your application. 9 10 Widget build(BuildContext context) { 11 return MaterialApp(//return MaterialAppはアプリ内で1つ 12 home: calender() 13 ); 14 } 15 16} 17 18class calender extends StatefulWidget { 19 const calender({Key? key}) : super(key: key); 20 21 22 State<calender> createState() => calenderState(); 23} 24List<String> days = ["月","火","水","木","金","土","日"]; 25class calenderState extends State<calender> { 26 27 Widget build(BuildContext context) { 28 return Scaffold( 29 body:Column( 30 //Expandedの親はColumnかRow 31 children: [ 32 Expanded( 33 child: Row( 34 children: [ 35 const Text("Row"), 36 Expanded( 37 child: GridView.builder( 38 itemCount: 7, 39 itemBuilder: (context, index) { 40 String today = days[index]; 41 return Column( 42 children: [ 43 Text(today), 44 Expanded(child: ListView.builder( 45 itemCount: 24, 46 itemBuilder: (context,index){ 47 return Container( 48 child: Text("$index:00"), 49 ); 50 }),) 51 ], 52 ); 53 }, 54 gridDelegate: 55 const SliverGridDelegateWithFixedCrossAxisCount( 56 crossAxisCount: 7, 57 ), 58 ), 59 ), 60 ], 61 ), 62 ), 63 ], 64 ) 65 66 ); 67 68 } 69}

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

EDS-COMPOSITING-BITS-UPDATE //の後に以下の内容と同じ内容のエラーがいくつも出ています。そのため長すぎるエラーになるためその同じ中の一つを抜粋させてもらいます。 The following assertion was thrown during performLayout(): RenderBox was not laid out: RenderPointerListener#068ee relayoutBoundary=up15 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart': Failed assertion: line 2001 pos 12: 'hasSize' Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause. In either case, please report this assertion by filing a bug on GitHub: https://github.com/flutter/flutter/issues/new?template=2_bug.md The relevant error-causing widget was: ListView ListView:file:///C:/Users/inohi/StudioProjects/test6/lib/main.dart:41:42 When the exception was thrown, this was the stack: #2 RenderBox.size (package:flutter/src/rendering/box.dart:2001:12) #3 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:121:21) #4 RenderObject.layout (package:flutter/src/rendering/object.dart:2135:7) #5 RenderBox.layout (package:flutter/src/rendering/box.dart:2418:11) #6 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14) #7 RenderObject.layout (package:flutter/src/rendering/object.dart:2135:7) #8 RenderBox.layout (package:flutter/src/rendering/box.dart:2418:11) #9 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:120:14) #10 RenderObject.layout (package:flutter/src/rendering/object.dart:2135:7) ---# は省略させてもらいます。 (elided 6 frames from class _AssertionError, class _RawReceivePortImpl, class _Timer, and dart:async-patch) The following RenderObject was being processed when the exception was fired: RenderSemanticsGestureHandler#a73c0 relayoutBoundary=up14 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE ... parentData: <none> (can use size) ... constraints: BoxConstraints(0.0<=w<=Infinity, h=681.0) ... size: MISSING ... behavior: opaque ... gestures: <none> RenderObject: RenderSemanticsGestureHandler#a73c0 relayoutBoundary=up14 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE parentData: <none> (can use size) constraints: BoxConstraints(0.0<=w<=Infinity, h=681.0) size: MISSING behavior: opaque gestures: <none> ... child: RenderPointerListener#068ee relayoutBoundary=up15 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE ... parentData: <none> (can use size) ... constraints: BoxConstraints(0.0<=w<=Infinity, h=681.0) ... size: MISSING ... behavior: opaque ... listeners: down, panZoomStart ... child: RenderSemanticsAnnotations#f1cb4 relayoutBoundary=up16 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE ... parentData: <none> (can use size) ... constraints: BoxConstraints(0.0<=w<=Infinity, h=681.0) ... size: MISSING ... child: RenderIgnorePointer#dd22f relayoutBoundary=up17 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE ... parentData: <none> (can use size) ... constraints: BoxConstraints(0.0<=w<=Infinity, h=681.0) ... size: MISSING ... ignoring: false ... ignoringSemantics: false ... child: RenderViewport#b5460 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE ... needs compositing ... parentData: <none> (can use size) ... constraints: BoxConstraints(0.0<=w<=Infinity, h=681.0) ... size: MISSING ... axisDirection: down ... crossAxisDirection: right ... offset: ScrollPositionWithSingleContext#f1581(offset: 0.0, range: null..null, viewport: null, ScrollableState, AlwaysScrollableScrollPhysics -> ClampingScrollPhysics -> RangeMaintainingScrollPhysics, IdleScrollActivity#37b94, ScrollDirection.idle) ... anchor: 0.0

エラーが起きたソースコード

dart

1import 'package:flutter/material.dart'; 2import 'package:flutter/rendering.dart'; 3 4void main() => runApp(const MyApp()); 5class MyApp extends StatelessWidget { 6 const MyApp({super.key}); 7 8 // This widget is the root of your application. 9 10 Widget build(BuildContext context) { 11 return MaterialApp(//return MaterialAppはアプリ内で1つ 12 home: calender() 13 ); 14 } 15 16} 17 18class calender extends StatefulWidget { 19 const calender({Key? key}) : super(key: key); 20 21 22 State<calender> createState() => calenderState(); 23} 24 25class calenderState extends State<calender> { 26 27 Widget build(BuildContext context) { 28 return Scaffold( 29 body:Column(//Expandedの親はColumnかRow 30 children: [ 31 Expanded(child: Row( 32 children: [ 33 Text("Row"), 34 Expanded(child: 35 ListView.builder( 36 scrollDirection: Axis.horizontal, 37 itemCount: 7, 38 itemBuilder: (context,index){ 39 return Column(children: [ 40 Expanded( 41 child:ListView.builder( 42 itemCount:1, 43 itemBuilder: (context,index){ 44 return Container( 45 child:Text("縦の内容"), 46 ); 47 }) 48 ) 49 ],); 50 } 51 ),), 52 53 ], 54 ),), 55 ], 56 ) 57 58 ); 59 60 } 61}

試したこと

エラーにFailed assertion: line 2001 pos 12: 'hasSize'書いてあったので調べるとエラーの原因になっている要素をExpanded()で囲むと治ると書いてあったので、2つのListView.BuilderをExpanded()で囲んでみました。下の階層のほう(scrollDirection: Axis.horizontal,がない縦並び)のListView.Builderを削除し、横並びのListView.builderのみにするとエラーなく動作しています。

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

Flutter version 3.3.0 を使用しています。

回答よろしくお願いします!

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

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

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

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

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

guest

回答1

0

ベストアンサー

ListView.builderの中にListView.builderを配置する件の解決方法ではないですが、該当するような表示をするウィジェットとして代替案の提案です。

該当するような表示はGridView(格子状に表示する)になると思うので、そちらを使った方がいいと思います。
例としては以下の様な感じです。

dart

1 body: Column( 2 //Expandedの親はColumnかRow 3 children: [ 4 Expanded( 5 child: Row( 6 children: [ 7 const Text("Row"), 8 Expanded( 9 child: GridView.builder( 10 itemCount: 14, 11 itemBuilder: (context, index) { 12 return Text("縦の内容 $index"); 13 }, 14 gridDelegate: 15 const SliverGridDelegateWithFixedCrossAxisCount( 16 crossAxisCount: 7, 17 ), 18 ), 19 ), 20 ], 21 ), 22 ), 23 ], 24 )

似たようなものとしてSliverGridやTableというものもあります。
またカレンダー表示をしたいのであれば、pub.devでcalendarで検索されたパッケージを使った方が、独自にViewを作るよりもっと手間が省けると思います。

投稿2022/09/18 05:28

ta.fu

総合スコア1667

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問