I am having a problem with my project, there are no errors in my code but when I try to run main.dart it fails to build. The errors it throws are the following:
../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/syncfusion_flutter_gauges-20.1.52/lib/src/linear_gauge/gauge/linear_gauge_scope.dart:40:10:错误:不能将'Widget‘类型的值分配给'InheritedWidget’类型的变量。
失败:生成失败,出现异常。
进程‘命令’C:\src\flutter\bin\flutter.bat‘以非零出口值1完成
这是使用径向量规包的代码:
enter code here
// @dart=2.9
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_gauges/gauges.dart';
import 'package:http/http.dart' as http;
import 'Readings.dart';
class DashBoardPage extends StatefulWidget {
const DashBoardPage({Key key}) : super(key: key);
@override
State<DashBoardPage> createState() => _DashBoardPageState();
}
class _DashBoardPageState extends State<DashBoardPage> {
final String url = "http://mushroomdroid.online/dbscript-1.php";
List<Readings> AllData = [];
@override
void initState() {
super.initState();
loadData();
}
loadData() async {
var response =
await http.get(Uri.parse(url), headers: {"Accept": "application/json"});
if (response.statusCode == 200) {
String responseBody = response.body;
var jsonBody = json.decode(responseBody);
for (var data in jsonBody) {
AllData.add(Readings(
int.parse(data['id']),
double.parse(data['temperature']),
double.parse(data['humidity']),
data['FanStatus'],
data['MistStatus'],
DateTime.parse(data['Time'])));
}
setState(() {});
//AllData.forEach((someData) => print("temperature: ${someData.temperature}"));
} else {
print('Something went wrong');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: AllData.isEmpty
? Center(
child: CircularProgressIndicator(),
)
: showMyUI(),
));
}
Widget showMyUI() {
return ListView.builder(
itemCount: 1,
itemBuilder: (_, index) {
return Card(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/whitelast.jpg'),
fit: BoxFit.cover,
)),
padding: EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Dashboard",
style: TextStyle(fontFamily: 'OpenSans', fontSize: 25)),
Text("Latest reading for today,\n${AllData.first.petsa}"),
SfRadialGauge(axes: <RadialAxis>[
RadialAxis(
startAngle: 180,
endAngle: 360,
showTicks: false,
showLabels: false,
radiusFactor: 0.8,
pointers: <GaugePointer>[
RangePointer(
value: AllData.last.temperature,
cornerStyle: CornerStyle.bothCurve,
width: 10,
sizeUnit: GaugeSizeUnit.logicalPixel,
gradient: const SweepGradient(colors: <Color>[
Color(0xFFffd800),
Color(0xFFffba00)
], stops: <double>[
0.25,
0.75
])),
],
annotations: <GaugeAnnotation>[
GaugeAnnotation(
positionFactor: 0.7,
angle: 90,
widget: Column(
children: <Widget>[
Container(
width: 100.00,
height: 100.00,
decoration: BoxDecoration(
image: DecorationImage(
image: ExactAssetImage(
'assets/qwe.png'),
),
)),
Padding(
padding: EdgeInsets.fromLTRB(0, 2, 0, 0),
child: Text(
' ${AllData.first.temperature}\n Temperature',
style: TextStyle(
fontFamily: 'OpenSans',
fontWeight: FontWeight.normal,
fontSize: 25)),
)
],
),
)
])
]),
SfRadialGauge(axes: <RadialAxis>[
RadialAxis(
startAngle: 180,
endAngle: 360,
annotations: <GaugeAnnotation>[
GaugeAnnotation(
positionFactor: 0.7,
angle: 90,
widget: Column(
children: <Widget>[
Container(
width: 70.00,
height: 70.00,
decoration: BoxDecoration(
image: DecorationImage(
image:
AssetImage('assets/images(2).jpg'),
))),
Padding(
padding: EdgeInsets.fromLTRB(0, 2, 0, 0),
child: Text(
' ${AllData.first.humidity}\n Humidity',
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 25)),
)
],
))
],
radiusFactor: 0.8,
showLabels: false,
showTicks: false,
pointers: <GaugePointer>[
RangePointer(
value: AllData[index].humidity,
cornerStyle: CornerStyle.bothCurve,
width: 10,
sizeUnit: GaugeSizeUnit.logicalPixel,
gradient: const SweepGradient(colors: <Color>[
Color(0xFF00FFFF),
Color(0xFF6495ED)
], stops: <double>[
0.25,
0.75
])),
],
)
])
],
),
),
);
});
}
}
发布于 2022-05-06 10:23:22
这是由于颤振框架发生了剧烈变化。具体来说,InheritedElement.widget
现在返回一个Widget而不是一个InheritedWidget,在需要的地方调用站点会出现下传。量规库将其分配给不进行转换的InheritedWidget变量,这将导致编译时错误。
这一变化是在此承诺中引入的,从2.12.0-4.1.pre开始在beta通道上的所有版本中都有。
您的选项是将颤振降级到早期版本,分叉库以删除不必要的InheritedWidget类型注释,或者希望以后会更改Flutter框架或量规库。最简单的选择可能是切换到颤振稳定通道,此时版本为2.10.5。
> flutter channel stable
https://stackoverflow.com/questions/72145278
复制