發表日期:2018-07 文章編輯:小燈 瀏覽次數:3257
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 瀏覽次數:7525
日期:2018-12 瀏覽次數:4598
日期:2018-07 瀏覽次數:5115
日期:2018-12 瀏覽次數:4402
日期:2018-09 瀏覽次數:5756
日期:2018-12 瀏覽次數:10181
日期:2018-11 瀏覽次數:5091
日期:2018-07 瀏覽次數:4845
日期:2018-05 瀏覽次數:5098
日期:2018-12 瀏覽次數:4562
日期:2018-10 瀏覽次數:5377
日期:2018-12 瀏覽次數:6438
日期:2018-11 瀏覽次數:4705
日期:2018-08 瀏覽次數:4850
日期:2018-11 瀏覽次數:12938
日期:2018-09 瀏覽次數:5858
日期:2018-12 瀏覽次數:5084
日期:2018-10 瀏覽次數:4423
日期:2018-11 瀏覽次數:4769
日期:2018-12 瀏覽次數:6299
日期:2018-06 瀏覽次數:4249
日期:2018-08 瀏覽次數:5697
日期:2018-10 瀏覽次數:4681
日期:2018-12 瀏覽次數:4792
日期:2018-07 瀏覽次數:4614
日期:2018-12 瀏覽次數:4783
日期:2018-06 瀏覽次數:4623
日期:2018-11 瀏覽次數:4603
日期:2018-12 瀏覽次數:4526
日期:2018-12 瀏覽次數:5507
Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.