简体   繁体   English

错误:无法以健全的 null 安全运行,因为以下依赖项不支持 null 安全:

[英]Error: Cannot run with sound null safety, because the following dependencies don't support null safety:

I'm making lecture room reservation system.我正在制作教室预订系统。

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])),
          );
        },
      ),
    );
  }
}

I want to move data[index] to other view.我想将 data[index] 移动到其他视图。

This is second view.这是第二种观点。

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])),
          );
        },
      ),
    );
  }
}

But null safety error occurs.但是出现 null 安全错误。

Maybe the data didn't save.也许数据没有保存。

Where should I fix the code?我应该在哪里修复代码?

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

This is the error when I run the app.这是我运行应用程序时的错误。

I need to move data[index] to use next API.我需要移动 data[index] 以使用下一个 API。

Also I need to send building and lecture room data to the reservaion view.我还需要将建筑和演讲室数据发送到预订视图。

This is because you are using an older version of the get flutter package.这是因为您使用的是旧版本的get flutter package。

  1. Open your pubsec.yaml .打开您的pubsec.yaml
  2. Change your get: xxxxx line to get: ^4.1.4 (The xxxxx is probably something lesser than 4.1.4 )将您的get: xxxxx行更改为get: ^4.1.4 (xxxxx 可能小于4.1.4
  3. Refetch your pub dependencies or run flutter pub upgrade .重新获取您的 pub 依赖项或运行flutter pub upgrade
  4. Then rebuild your app.然后重建您的应用程序。

This should fix it.这应该解决它。

Go to Your Main.dart and start with ` Go 到您的 Main.dart 并以`开头

GetMaterialApp

Here is the Demo.这是演示。 It will Work.它会工作。

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getxpro/view/cartPage.dart';
import 'package:getxpro/view/home.dart';

    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return GetMaterialApp( //for navigation dont forget to use GetMaterialApp
          title: 'getXpro',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          initialRoute: '/',
          routes: {
            '/': (context) => HomePage(),
            '/cart': (context) => CartPage(),
          },
        );
      }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:无法以健全的 null 安全运行,因为以下依赖项不支持 null 安全; 在 flutter - Error: Cannot run with sound null safety, because the following dependencies don't support null safety; in flutter 无法以健全的 null 安全运行,因为以下依赖项不支持 null 安全 - Cannot run with sound null safety, because the following dependencies don't support null safety Flutter 不能以空安全运行,因为以下依赖不支持空安全 - Flutter Cannot run with sound null safety, because the following dependencies don't support null safety "无法以可靠的 null 安全性运行,因为以下依赖项不支持 null 安全性:" - Cannot run with sound null safety, because the following dependencies don't support null safety: 无法以声音 null 安全运行,因为依赖项不支持 null 安全 - Cannot run with sound null safety because dependencies don't support null safety 无法以声音 null 安全运行,因为依赖项不支持 null 安全 - Cannot run with sound null safety because dependencies doesnot support null safety 错误:无法以声音空安全运行,因为以下依赖项(flutter_absolute_path) - Error: Cannot run with sound null safety, because the following dependencies (flutter_absolute_path) 无法正常运行 null 安全,因为以下依赖项 [build\windows\flutter\flutter_assemble.vcxproj] - Cannot run with sound null safety, because the following dependencies [build\windows\flutter\flutter_assemble.vcxproj] Flutter 2.0 以下依赖不支持 null 安全 - Flutter 2.0 following dependencies don't support null safety 以下包不支持空安全 - The following packages don't support null safety
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM