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
CodePudding user response:
Solved it by simply rebooting the emulator.
CodePudding user response:
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.