0

estou criando um aplicativo em flutter para treinar mas esta apresentando o seguinte erro:

Launching lib\main.dart on motorola one vision in debug mode... Running Gradle task 'assembleDebug'... Error: Cannot run with sound null safety, because the following dependencies don't support null safety:

  • package:path_provider
  • package:path_provider_linux
  • package:path_provider_windows
  • package:path_provider_platform_interface
  • package:xdg_directories
  • package:plugin_platform_interface

For solutions, see https://dart.dev/go/unsound-null-safety

FAILURE: Build failed with an exception.

  • Where: Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1035

  • 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 34s Exception: Gradle task assembleDebug failed with exit code 1

o código é esse:

import 'dart:convert';
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
// ignore: import_of_legacy_library_into_null_safe
import "package:path_provider/path_provider.dart";
import 'dart:async';

void main() {
  runApp(MaterialApp(
    home: Home(),
  ));
}

class Home extends StatefulWidget {

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {

  List _toDoList= ["daniel","Marcos"];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Lista de Tarefas"),
        backgroundColor: Colors.blueAccent,
        centerTitle: true,
      ),
      body: Column(
        children: <Widget>[
          Container(
            padding: EdgeInsets.fromLTRB(17.0, 1.0, 7.0, 1.0),
            child: Row(
              children: <Widget>[
                Expanded
                  (child: TextField(
                  decoration: InputDecoration(
                    labelText: "Nova Tarefe",
                    labelStyle: TextStyle(color: Colors.blueAccent),
                  ),
                ),
                ),
                RaisedButton(
                  color: Colors.blueAccent,
                  child: Text("ADD"),
                  textColor: Colors.white,
                  onPressed: (){},
                ),
              ],
            ),
          ),
          Expanded(
              child: ListView.builder(
                padding: EdgeInsets.only(top: 10.0),
                itemCount: _toDoList.length,
                itemBuilder: (context, index){
                  return ListTile(
                    title: Text(_toDoList[index]),
                  );
                },
              ),
          ),
        ],
      ),
    );
  }
 Future<File> _getFile() async{
    final directory = await getApplicationDocumentsDirectory();
    return File("${directory.path}/data.json");
  }
  Future<File> _saveData() async{
    String data = json.encode(_toDoList);
    final file = await _getFile();
    return file.writeAsString(data);
  }
  Future<String> _readData() async{
    try{
      final file = await _getFile();

      return file.readAsString();
    }catch (e){
      return null;
    }

  }
}

1 Resposta 1

0

RaisedButton está depreciado, agora é utilizado o ElevatedButton.

Na parte: Future _readData() async{ try{ final file = await _getFile();

  return file.readAsString();
}catch (e){
  return null;
}

Pelas atualizações do Flutter, agora foi implementado a biblioteca null safety, então para mandar o return null, é necessário colocar String? , como abaixo:

Future<String?> _readData() async{
    try{
      final file = await _getFile();

      return file.readAsString();
    }catch (e){
      return null;
    }

E se vc estiver testando o app em um telefone físico, é necessário habilitá-lo em modo desenvolvedor nas configurações.

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .