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

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

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

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

Dart

Dartは、Googleによって開発されたJavaScriptの代替となることを目的に作られた、ウェブ向けのプログラミング言語である。

Q&A

解決済

2回答

4053閲覧

FlutterでListView内でテキストの折返しがしたい

sengoku38

総合スコア27

Flutter

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

Dart

Dartは、Googleによって開発されたJavaScriptの代替となることを目的に作られた、ウェブ向けのプログラミング言語である。

1グッド

0クリップ

投稿2022/05/11 14:19

Flutterの勉強がてらTwitterのアプリもどきを作っています。
Flutterのリストビューの中で長過ぎるテキストの場合、折返しまたは...にしたいです。

添付の画像で黄色い警告になってる箇所はtweetObject['full_text'] の表示箇所です。
添付の画像のソースは一部除いてますが以下の通りです。

Dart

1class _HomeTimelineState extends State<HomeTimeline> 2{ 3 final List<Widget> _tweets = []; 4 // initState()から呼ばれる関数 5 Future<void> _displayHomeTimeline() async 6 { 7 // DBからツィートを読み込む 8 final List<Map<String, dynamic>> tweets = await database.rawQuery(sql); 9 setState(() { 10 for (int i = 0; i < tweets.length; ++i) { 11 // webからユーザ画像を取る関数.ローカルに保存したパスを返す 12 Imager.load(userObject['profile_image_url_https'] as String, (String path) { 13 Card( 14 child: Row( 15 children: [ 16 // アイコン 17 Image.file(File(path)), 18 Column( 19 children: <Widget>[ 20 // ツィート本文 21 Text(tweetObject['full_text'] as String), 22 ] 23 ) 24 ] 25 ) 26 ) 27 }); 28 } 29 }); 30 } 31 32 Widget build(BuildContext context) 33 { 34 return Scaffold( 35 appBar: const EmptyAppBar(), 36 body: NotificationListener<ScrollNotification> ( 37 child: ListView.builder( 38 shrinkWrap: true, 39 itemCount: _tweets.length, 40 itemBuilder: (context, index) { 41 return _tweets[index]; 42 }, 43 ), 44 onNotification: (ScrollNotification notification) { 45 if (notification is OverscrollNotification) { 46 _logger.e(notification); 47 } 48 return true; 49 } 50 ), 51 floatingActionButton: FloatingActionButton( 52 onPressed: () async { 53 }, 54 child: const Icon(Icons.add) 55 ) 56 ); 57 }

以下のような表示になります。
Twitterの表示結果

やってみたこととして、折り返したい箇所をFlexibleで囲めばいいと記事をみたので、
Text(tweetObject['full_text'] as String)を以下のようにFlexibleで囲ってみたのですが、
エラーがでて真っ白になってしまいました。

Dart

1Flexible(child: Text(tweetObject['full_text'] as String))

エラーメッセージの抜粋

When a column is in a parent that does not provide a finite height constraint, for example if it is in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining space in the vertical direction. These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child cannot simultaneously expand to fit its parent.

ListViewでテキストを折り返す方法と...にする方法を教えて頂けないでしょうか。

84d010m08👍を押しています

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

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

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

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

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

guest

回答2

0

自己解決

以下の箇所をFlexibleで囲うことで解決しました。
どうも直接Textを囲ってしまうと駄目みたいです。
理由を知りたいですがそれはわかりませんでした。

Dart

1 Column( 2 children: <Widget>[ 3 // ツィート本文 4 Text(tweetObject['full_text'] as String), 5 ] 6 )

投稿2022/05/13 06:27

sengoku38

総合スコア27

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

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

0

とりあえずFlexible(とColumnもかな)を外し、TextにoverflowやmaxLinesのパラメータを設定し調整してみてはどうでしょうか。

投稿2022/05/12 00:06

ta.fu

総合スコア1667

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問