Home > Software engineering >  Error flutter run : Execution failed for task ':app:compileFlutterBuildDebug'
Error flutter run : Execution failed for task ':app:compileFlutterBuildDebug'

Time:04-16

i get these erros when i run my code.Please any ideas how could i fix these? I upgraded the flutter , and pubspeck.lock.I mention that the code was old and i tried to upgrade

lib/screens/search/createnewfood.dart:147:30: Error: The argument type 'void Function(String)' can't be assigned to the parameter type 'void Function(String?)?' because 'String?' is nullable and 'String' isn't.
                  onChanged: (String unit) {
                             ^
lib/screens/search/createnewfood.dart:184:27: Error: Property 'isEmpty' cannot be accessed on 'String?' because it is potentially null.
Try accessing using ?. instead.
                    value.isEmpty ? 'Please enter a number' : null,
                          ^^^^^^^
lib/screens/search/foodpage.dart:24:28: Error: Can't use the default List constructor.
Try using List.filled instead.
  var dropDownValues = new List<String>();
                           ^
lib/screens/search/foodpage.dart:85:41: Error: The argument type 'Color?' can't be assigned to the parameter type 'Color' because 'Color?' is nullable and 'Color' isn't.
 - 'Color' is from 'dart:ui'.
                      color: Colors.grey[200],
                                        ^
lib/screens/search/foodpage.dart:116:43: Error: The argument type 'Color?' can't be assigned to the parameter type 'Color' because 'Color?' is nullable and 'Color' isn't.
 - 'Color' is from 'dart:ui'.
                        color: Colors.grey[200],
                                          ^
lib/screens/search/foodpage.dart:177:46: Error: The argument type 'Color?' can't be assigned to the parameter type 'Color' because 'Color?' is nullable and 'Color' isn't.
 - 'Color' is from 'dart:ui'.
        border: Border.all(color: Colors.grey[200]),
                                             ^
lib/screens/search/foodpage.dart:265:16: Error: The getter 'Provider' isn't defined for the class '_FoodPageState'.      
 - '_FoodPageState' is from 'package:fitnessapp/screens/search/foodpage.dart' ('lib/screens/search/foodpage.dart').      
Try correcting the name to the name of an existing getter, or defining a getter or field named 'Provider'.
    var user = Provider.of<User>(context);
               ^^^^^^^^
lib/screens/search/foodpage.dart:340:34: Error: The argument type 'void Function(String)' can't be assigned to the parameter type 'void Function(String?)?' because 'String?' is nullable and 'String' isn't.
                      onChanged: (String unit) {
                                 ^
lib/screens/search/foodpage.dart:368:51: Error: Method 'validate' cannot be called on 'FormState?' because it is potentially null.
 - 'FormState' is from 'package:flutter/src/widgets/form.dart' ('/C:/Users/valen/Downloads/flutter5/flutter/packages/flutter/lib/src/widgets/form.dart').
Try calling using ?. instead.
                    if (_foodFormKey.currentState.validate()) {
                                                  ^^^^^^^^
lib/services/client.dart:12:31: Error: Method not found: 'get'.
    var response = await http.get(url);
                              ^^^
lib/services/client.dart:33:31: Error: Method not found: 'get'.
    var response = await http.get(url);
                              ^^^
Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:package:provider/provider.dart; message=StandardFileSystem only supports file:* and data:* URIs)
#0      StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:34:7)
#1      asFileUri (package:vm/kernel_front_end.dart:623:37)
#2      writeDepfile (package:vm/kernel_front_end.dart:763:21)
<asynchronous suspension>
#3      FrontendCompiler.compile (package:frontend_server/frontend_server.dart:586:9)
<asynchronous suspension>
#4      starter (package:flutter_frontend_server/server.dart:85:12)
<asynchronous suspension>
#5      main (file:///C:/b/s/w/ir/cache/builder/src/flutter/flutter_frontend_server/bin/starter.dart:13:24)
<asynchronous suspension>



FAILURE: Build failed with an exception.

* Where:
Script 'C:\Users\valen\Downloads\flutter5\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1102

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\Users\valen\Downloads\flutter5\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 enter image description here

    CodePudding user response:

    I updated the imports and when i run enter image description here

    CodePudding user response:

    looks like its a code from 2 years before the null safety was introduced. I suggest that you should go one by one to resolve each error.

    the first one: you should write String? unit
    the second one: it should be value!.isEmpty because it might be null
    the third one: List<String> dropDownValues = [ ];
    the fourth one: (Colors.grey[200])!
    the provider error is an import issue, prob ably you didnt import the package in the file.(same for the http get error)
    last: (_foodFormKey.currentState.validate()) should be (_foodFormKey.currentState!.validate())

    Update for your new issue:
    you are using an old versions of cloud_firestore and firebase_auth, you should upgrade to the last versions from your pubspec.yaml
    last versions numbers can be found here:
    https://pub.dev/packages/firebase_auth
    https://pub.dev/packages/cloud_firestore

  • Related