如何为颤动中的图像设置图像数据类型的参数

时间:2018-08-03 11:40:24

标签: android ios flutter

大家好,我是新手,但无法设置图像数据类型。  我有两个框,我需要将其中一个拖到另一个框上(自动调整)。但是我在声明图像参数时遇到了错误。我可以拖动带有图像的项目框,但是被拖动的项目不被其中存在的dragTarget对象接受。 预先感谢。

这是我的代码和屏幕截图:

import 'package:flutter/material.dart';
class Episode3 extends StatelessWidget {
  var accpeptedData = Image.asset("");
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          DraggableWidget(
            offset: Offset(50.0, 80.0),
          ),
          Positioned(
            top: 100.0,
            left: 100.0,
            child: DragTarget(
              builder: (BuildContext context, List<dynamic> accepted,
                      List<dynamic> rejected) =>
                  Container(
                    height: 200.0,
                    width: 200.0,
                    decoration: BoxDecoration(color: Colors.cyan),
                    child: Center(
                      child: Image.file(accpeptedData.toString()),
                    ),
                  ),
              onAccept: (Image data) {
                accpeptedData = data;
              },
            ),
          )
        ],
      ),
    );
  }
}

class DraggableWidget extends StatefulWidget {
  final Offset offset;

  DraggableWidget({Key key, this.offset}) : super(key: key);

  @override
  _DraggableWidgetState createState() => _DraggableWidgetState();
}
class _DraggableWidgetState extends State<DraggableWidget> {
  Offset offset = Offset(0.0, 0.0);
  @override
  void initState() {
    super.initState();
    offset = widget.offset;
  }
  @override
  Widget build(BuildContext context) {
    return Positioned(
      bottom: offset.dy,
      left: offset.dx,
      child: Draggable(
        data: Image.asset("ss/camera-icon.png"),
        child: Container(
          width: 200.0,
          height: 200.0,
          color: Colors.blue,
          child: Center(
            child: Image.asset("ss/camera-icon.png")
          ),
        ),
        feedback: Container(
          width: 200.0,
          height: 200.0,
          color: Colors.blue.withOpacity(0.3),
          child: Center(
            child: Image.asset("ss/camera-icon.png")
          ),
        ),
        onDraggableCanceled: (v, o) {`enter code here`
          setState(() {
            offset = o;
          });
        },
      ),
    );
  }
}

enter image description here

0 个答案:

没有答案