发表日期:2018-07 文章编辑:小灯 浏览次数:2974
return Positioned( left: pos.dx, top: pos.dy, child: Draggable( data: widget.dragModel, child: Container( width: drag_item_height, height: drag_item_height, color: widget.dragModel.itemBgColor, child: Center( child: Text( widget.dragModel.itemName, style: TextStyle( color: Colors.white, decoration: TextDecoration.none, fontSize: 12.0, ), ), ), ), onDraggableCanceled: (velocity, offset) { if (!mounted) return; setState(() { //坐标是根据全屏算的,需要计算appbar和statusBar的高度double dx = offset.dx; double dy = offset.dy - appBarHeight - statusBarHeight;//临界点判断 if (dx < 0) { dx = 0.0; }if (dx > screenWidth - drag_item_height) { dx = screenWidth - drag_item_height; }if (dy < 0) { dy = 0.0; }if (offset.dy + drag_item_height > screenHeight) { dy = screenHeight - drag_item_height - appBarHeight - statusBarHeight; }pos = new Offset(dx, dy);}); }, feedback: Container( width: drag_item_height, height: drag_item_height, color: widget.dragModel.itemBgColor.withOpacity(0.5), child: Center( child: Text( widget.dragModel.itemName, style: TextStyle( color: Colors.white, decoration: TextDecoration.none, fontSize: 14.0, ), ), ), ), ));
@override Widget build(BuildContext context) { return Positioned( right: 0.0, child: DragTarget( onAccept: (DragModel model) { if (model.itemBgColor == _curRandomColor) { _score++; } }, builder: ( BuildContext context, List<dynamic> accepted, List<dynamic> rejected, ) { return Container( width: 200.0, height: 200.0, decoration: BoxDecoration( color: _curRandomColor, ), child: Center( child: Text( "放入正确的颜色\n您的得分:$_score", style: new TextStyle(fontSize: 16.0, color: Colors.white), ), ), ); }, ), ); }
@overrideWidget build(BuildContext context) {return new Scaffold(appBar: _buildAppbar(),body: new Stack(children: <Widget>[new DragItem(new DragModel(Offset(0.0, 0.0), '红', Colors.red)),new DragItem(new DragModel(Offset(0.0, 1 * drag_item_height), '橙', Colors.orange)),new DragItem(new DragModel(Offset(0.0, 2 * drag_item_height), '黄', Colors.yellow)),new DragItem(new DragModel(Offset(0.0, 3 * drag_item_height), '绿', Colors.green)),new DragItem(new DragModel(Offset(0.0, 4 * drag_item_height), '青', Colors.indigoAccent)),new DragItem(new DragModel(Offset(0.0, 5 * drag_item_height), '蓝', Colors.blue)),new DragItem(new DragModel(Offset(0.0, 6 * drag_item_height), '紫', Colors.purple)),new DragDestination(),],),);}
日期:2018-10 浏览次数:7246
日期:2018-12 浏览次数:4319
日期:2018-07 浏览次数:4868
日期:2018-12 浏览次数:4168
日期:2018-09 浏览次数:5490
日期:2018-12 浏览次数:9915
日期:2018-11 浏览次数:4797
日期:2018-07 浏览次数:4573
日期:2018-05 浏览次数:4851
日期:2018-12 浏览次数:4315
日期:2018-10 浏览次数:5132
日期:2018-12 浏览次数:6206
日期:2018-11 浏览次数:4453
日期:2018-08 浏览次数:4585
日期:2018-11 浏览次数:12622
日期:2018-09 浏览次数:5570
日期:2018-12 浏览次数:4823
日期:2018-10 浏览次数:4178
日期:2018-11 浏览次数:4522
日期:2018-12 浏览次数:6057
日期:2018-06 浏览次数:4002
日期:2018-08 浏览次数:5427
日期:2018-10 浏览次数:4452
日期:2018-12 浏览次数:4516
日期:2018-07 浏览次数:4355
日期:2018-12 浏览次数:4493
日期:2018-06 浏览次数:4375
日期:2018-11 浏览次数:4369
日期:2018-12 浏览次数:4242
日期:2018-12 浏览次数:5275
Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.