当我拖动视图时,文本会更改其样式。我猜想正在进行一些重建工作。知道如何使文本在拖动时保持不变吗?
Positioned(
left: _textPosition.dx,
top: _textPosition.dy,
child: Draggable(
feedback: Container(
color: black_transparent_light,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Some Text Here",
style: const TextStyle( // Preserve original style
color: Colors.white, // Adjust as needed
fontSize: 16, // Adjust as needed
fontStyle: FontStyle.normal,
decoration: TextDecoration.none
),
),
)
),
childWhenDragging: Container(),
onDragEnd: (details)
{
final RenderBox renderBox = _mainContainerKey.currentContext!.findRenderObject() as RenderBox;
final Offset position = renderBox.localToGlobal(Offset.zero); // This is the absolute position
setState(() {
_textPosition = Offset(
details.offset.dx-position.dx - mainContainerStartMargin,
details.offset.dy-position.dy-mainContainerTopMargin);
});
},
child: Container(
color: black_transparent_light,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Some Text Here",
style: const TextStyle( // Preserve original style
color: Colors.white, // Adjust as needed
fontSize: 16, // Adjust as needed
fontStyle: FontStyle.normal,
decoration: TextDecoration.none
),
),
),
),
),
),
要解决此问题,我所要做的就是使用 Material Widget 将容器包装在反馈中:
feedback: Material(
color: Colors.transparent,
child: Container(
color: black_transparent_light,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Some Text Here",
style: const TextStyle( // Preserve original style
color: Colors.white, // Adjust as needed
fontSize: 16, // Adjust as needed
fontStyle: FontStyle.normal,
decoration: TextDecoration.none
),
),
)
),
)