JYHJYH
JYHJYH

Reputation: 15

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.

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.

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.

Also I need to send building and lecture room data to the reservaion view.

Upvotes: 1

Views: 8836

Answers (2)

Ellix4u
Ellix4u

Reputation: 586

Run

flutter run --no-sound-null-safety

If you want to run your applications with no sound null safety, For VSCode user, add below to settings.json

"dart.flutterRunAdditionalArgs": [
    "--no-sound-null-safety"
],

Upvotes: 0

Nisanth Reddy
Nisanth Reddy

Reputation: 6405

This is because you are using an older version of the get flutter package.

  1. Open your pubsec.yaml.
  2. Change your get: xxxxx line to get: ^4.1.4 (The xxxxx is probably something lesser than 4.1.4)
  3. Refetch your pub dependencies or run flutter pub upgrade.
  4. Then rebuild your app.

This should fix it.

Upvotes: 1

Related Questions