1
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 3 years have passed since last update.

flutterのDraggableウィジェット内のテキストにエラーが表示されてしまう時の対処法

Last updated at Posted at 2020-03-21

flutterのDraggable Widget内のfeedback無いでテキストウィジェットを使用しようとしたら、ドラッグしてfeedbackが表示される時にwidget内にエラーが表示されてしまった。

参考コード

return Draggable(
  onDragStarted: () {
    //何らかの関数
  },
  child: Padding(
    padding: EdgeInsets.all(4.0),
    child: Container(
      color: flag == "true" ? Colors.blue : Colors.grey,
      child: Center(
        child: Text(
          "何らかの文字",
          style: TextStyle(
            fontSize: 28,
          ),
        ),
      ),
    ),
  ),
  childWhenDragging: Container(),
// ここの部分
  feedback: Container(
      width: 200,
      height: 70,
      child: Center(
        child: Text(
          name,
          style: TextStyle(
            fontSize: 28,
          ),
        ),
      ),
      color: Colors.yellow,
   ),
);

解決策

feedback内をmaterialで囲むとエラーが表示されなくなります。

参考例

// Material Widgetで囲む!!
feedback: Material(
  child: Container(
    width: 200,
    height: 70,
    child: Center(
      child: Text(
        name,
        style: TextStyle(
          fontSize: 28,
        ),
      ),
    ),
    color: Colors.yellow,
  ),
),

参考サイト
https://github.com/flutter/flutter/issues/9304

1
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
1
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?