0

Error

Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
Running Gradle task 'assembleDebug'...
E/flutter ( 6095): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Unable to load asset: assets/

This started happening out of nowhere, after the exception is thrown, the task still runs and when the app eventually launches, it's just a blank screen. The path in the error doesn't exist, I don't think I have any mention of said path in my code as the app ran just fine yesterday.

I've tried running flutter clean and flutter pub get, flutter pub upgrade to no avail.

The only code that reads the file in the error output is this and it only runs once in the entire program, in the main function.

class NiveisComida{
  static final NiveisComida _singleton = NiveisComida._internal();
  static Map<String,bool> nivel1 = {},nivel2 = {},nivel3 = {};

  static void _readNiveis() async {
    for(int i = 1;i<=3;i++){
      List<String> content = (await rootBundle.loadString('_ficheiros_extra/nivel$i.comida')).split('\n');
      Map<String,bool> aux ={};
      for(String linha in content){
        bool val = true;
        if(linha.contains(';bad')) val = false;
        aux.putIfAbsent(linha, () => val);
      }
      switch(i){
        case 1:
          nivel1 = aux;
          break;
        case 2:
          nivel2 = aux;
          break;
        case 3:
          nivel3 = aux;
          break;

      }
    }
  }

  factory NiveisComida() {
    _readNiveis();
    return _singleton;
  }

  NiveisComida._internal();
}

main.dart


void main() {
  WidgetsFlutterBinding.ensureInitialized();
  //NiveisComida(); //inicializar lista de niveis de comida
  Intl.defaultLocale = 'pt_PT';
  if(kIsWeb){
    runApp(funcaoMain());
  }else{
    initializeDateFormatting().then((_)=>runApp(funcaoMain()));
  }
}

pubspec.yaml:

flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true
  assets:
    - _ficheiros_extra/nivel1.comida
    - _ficheiros_extra/nivel2.comida
    - _ficheiros_extra/nivel3.comida
    - _ficheiros_extra/comidas.csv
    - _ficheiros_extra/
    - _ficheiros_extra/app_store_badges/

_ficheiros_extra/ file structure:

.
├── README.md
├── _ficheiros_extra
│   ├── alcool.csv
│   ├── app_store_badges
│   │   ├── apple-badge-tamanho-igual.png
│   │   ├── apple-badge.png
│   │   └── google-play-badge.png
│   ├── comidas.csv
│   ├── nivel1.comida
│   ├── nivel2.comida
│   └── nivel3.comida
├── analysis_options.yaml
├── android
│   ├── app

If it helps I'm running on a M1 Mac

2 Answers 2

1

Solved it by simply rebooting the emulator.

Sign up to request clarification or add additional context in comments.

Comments

0

Your error said that your code try to load assets/nivel1.comida that not exists. Because the right path is _ficheiros_extra/nivel1.comida. Make sure the path in your code contains _ficheiros_extra. You can print your path before loading to make sure it.

11 Comments

but there's no assets folder. the code does indeed use _ficheiros_extra/ and nothing more
Ok, so you need to load path _ficheiros_extra/nivel1.comida and your error said that your code try to load assets/nivel1.comida.
@MartinhoTavares, can you print the file path before you load it? Is the path is _ficheiros_extra/nivel1.comida?
I updated the post with a more complete path. I've also tried to search for the assets/nivel1.comida string in the entire directory and there is no occurrence of it. Also tried creating a new project and copying over pubspec, lib/ and _ficheiros_extra/ and it still gave me the error. It's weird since it's reading the file even though I've commented the code that reads such file and also removed the files from pubspec
I mean the problem wouldn't be the file extension, it's just a regular text file, it was to make them standout. But I just solved it lol, it was the android emulator, tried a different one, and the error was gone, just need to reboot the first emulator
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.