我正在制作教室预订系统。
class _SearchViewState extends State<SearchView> {
List data = [];
Future<String> getData() async {
http.Response res = await http
.get(Uri.parse("https://gcse.doky.space/api/schedule/buildings"));
this.setState(() {
data = jsonDecode(res.body)["result"];
});
return "success";
}
@override
void initState() {
super.initState();
this.getData();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('건물 선택')),
body: new ListView.builder(
itemCount: data == null ? 0 : data.length,
itemBuilder: (BuildContext context, int index) {
return new Card(
child: ListTile(
onTap: () {
Get.to(() => SearchView2(), arguments: data[index]);
},
title: Text(data[index])),
);
},
),
);
}
}
我想将数据[索引]移动到其他视图。
这是第二个视图。
class SearchView2 extends StatefulWidget {
@override
_SearchViewState2 createState() => _SearchViewState2();
}
class _SearchViewState2 extends State<SearchView2> {
String building = Get.arguments;
List data = [];
Future<String> getData() async {
http.Response res = await http.get(Uri.parse(
"https://gcse.doky.space/api/schedule/classrooms?bd=$building"));
this.setState(() {
data = jsonDecode(res.body)["result"];
});
return "success";
}
void _itemtapped() {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ReservationView()), //route here
);
}
@override
void initState() {
super.initState();
this.getData();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('강의실 선택')),
body: new ListView.builder(
itemCount: data == null ? 0 : data.length,
itemBuilder: (BuildContext context, int index) {
return new Card(
child: ListTile(onTap: _itemtapped, title: Text(data[index])),
);
},
),
);
}
}
但发生空安全错误。
可能数据没有保存。
我应该在哪里修复代码?
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:
- package:get
For solutions, see https://dart.dev/go/unsound-null-safety
2
FAILURE: Build failed with an exception.
* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\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.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
Exception: Gradle task assembleDebug failed with exit code 1
这是我运行应用程序时的错误。
我需要移动 data[index] 以使用下一个 API。
我还需要将建筑物和教室数据发送到预订视图。
答案 0 :(得分:0)
这是因为您使用的是旧版本的 get
flutter 包。
pubsec.yaml
。get: xxxxx
行更改为 get: ^4.1.4
(xxxxx 可能小于 4.1.4
)flutter pub upgrade
。这应该可以解决它。
答案 1 :(得分:0)
转到您的 Main.dart 并以 `
开头 <块引用>q1=round(100*(t.shape[0]-t.isna().sum())/t.shape[0],1).squeeze()
# ^^^^^^^^^^
这是演示。它会工作。
GetMaterialApp