项目下载下来有问题,运行不了
xhcui2008 opened this issue · comments
`Compiler message:
lib/widgets/touchinteractions/dragtarget.dart:73:28: Error: The argument type 'Null Function(double)' can't be assigned to the parameter type 'void Function(Object)'.
- 'Object' is from 'dart:core'.
onLeave: (double value) {
^
Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
build failed.
FAILURE: Build failed with an exception.
-
Where:
Script 'D:\Flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 801 -
What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
Process 'command 'D:\Flutter\flutter\bin\flutter.bat'' finished with non-zero exit value 1
- Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.`
flutter doctor 跑一下看看,我这里是好的,编译没问题
项目编译环境是Flutter stable分支
`class DragTargetWidget extends StatefulWidget {
@OverRide
_DragTargetWidgetState createState() => _DragTargetWidgetState();
}
class _DragTargetWidgetState extends State {
String status = '';
@OverRide
Widget build(BuildContext context) {
return Column(
children: [
MainTitleWidget('DragTarget基本使用'),
Container(
margin: EdgeInsets.only(top: 20),
width: 300,
height: 200,
child: Stack(
children: [
Positioned(
top: 0,
left: 0,
child: Draggable(
onDraggableCanceled: (v, f) {
setState(() => status = 'onDraggableCanceled');
},
data: 1.0,
child: Container(
width: 50,
height: 50,
alignment: Alignment.center,
color: Colors.blue,
child: Text('Drag'),
),
feedback: Opacity(
opacity: 0.5,
child: Container(
width: 50,
height: 50,
alignment: Alignment.center,
color: Colors.blue,
child: Text(
'Drag',
style: Theme.of(context).textTheme.body1,
),
),
),
),
),
Positioned(
bottom: 0,
right: 0,
child: DragTarget(
builder: (BuildContext context, List candidateData, List rejectedData) {
return Container(
width: 80,
height: 80,
alignment: Alignment.center,
color: Colors.red,
child: Text('Target'),
);
},
onWillAccept: (double value) {
setState(() => status = 'onWillAccept: $value');
return true;
},
onAccept: (double value) {
setState(() => status = 'onAccept: $value');
},
onLeave: (double value) {
setState(() => status = 'onLeave: $value');
},
),
),
Positioned(
bottom: 0,
left: 0,
child: Text(status),
)
],
),
),
],
);
}
}
奇怪了,把把这这三行代码删除以后就可以成功运行了,不知道什么原因
onLeave: (double value) {
setState(() => status = 'onLeave: $value');
},`
dev版本,参数改了导致的