注意:无特殊说明,flutter版本及dart版本如下:
flutter版本: 1.12.13+hotfix.5
dart版本: 2.7.0
draggable系列组件可以让我们拖动组件。
draggable
draggable组件有2个必须填写的参数,child参数是子控件,feedback参数是拖动时跟随移动的组件,用法如下:
draggable(
child: container(
height: 100,
width: 100,
alignment: alignment.center,
decoration: boxdecoration(
color: colors.red,
borderradius: borderradius.circular(10)
),
child: text('孟',style: textstyle(color: colors.white,fontsize: 18),),
),
feedback: container(
height: 100,
width: 100,
alignment: alignment.center,
decoration: boxdecoration(
color: colors.blue,
borderradius: borderradius.circular(10)
),
child: text('孟',style: textstyle(color: colors.white,fontsize: 18),),
),
)
效果如下:
蓝色的组件是feedback,如果想在拖动的时候子组件显示其他样式可以使用childwhendragging参数,用法如下:
draggable(
childwhendragging: container(
height: 100,