Probé todo, desde cada modificación del archivo pubspec.yaml, flutter clean, actualizar flutter y mi IDE (Android Studio). Nada parece funcionar.

Creación de una aplicación de seguimiento de dinero en el caso de que no haya transacciones en la página que muestra la imagen.

Ruta del archivo de imagen:

lib/assets/images/waiting.png

Código:

return Container(
      height: 300,
      child: transactions.isEmpty
          ? Column(
              children: <Widget>[
                Text(
                  'No Transactions yet',
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 20.0,
                  ),
                ),
                Container(
                  height: 200,
                  child: Image.asset(
                    'assets/images/waiting.png',
                    fit: BoxFit.cover,
                  ),
                ),
              ],
            )
          : ListView.builder(
              itemBuilder: (context, index) {
                return Container(
                  margin: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
                  padding: EdgeInsets.all(3.0),
                  decoration: BoxDecoration(
                    gradient: LinearGradient(colors: _txColors),
                    border: Border.all(color: Colors.grey, width: 2.0),
                    borderRadius: BorderRadius.all(
                      Radius.circular(15.0),
                    ),
                    color: Colors.greenAccent,
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                    children: <Widget>[
                      Container(
                        child: Text(
                          '\$${transactions[index].amount.toStringAsFixed(2)}',
                          style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 20.0,
                            color: Colors.white,
//                    Color(0xffC5CED4),
                          ),
                        ),
                      ),

Pubspec.yaml:

flutter:
uses-material-design: true
assets:
  - assets/images/

Error:

I/flutter ( 5679): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter ( 5679): The following assertion was thrown resolving an image codec:
I/flutter ( 5679): Unable to load asset: assets/images/waiting.png
I/flutter ( 5679): 
I/flutter ( 5679): When the exception was thrown, this was the stack:
I/flutter ( 5679): #0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
I/flutter ( 5679): <asynchronous suspension>
I/flutter ( 5679): #1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:664:31)
I/flutter ( 5679): #2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:648:14)
I/flutter ( 5679): #3      ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:501:13)
I/flutter ( 5679): #4      ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:359:22)
I/flutter ( 5679): #5      ImageProvider.resolveStreamForKey (package:flutter/src/painting/image_provider.dart:499:80)
I/flutter ( 5679): #6      ScrollAwareImageProvider.resolveStreamForKey (package:flutter/src/widgets/scroll_aware_image_provider.dart:106:19)
I/flutter ( 5679): #7      ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:330:9)
I/flutter ( 5679): #8      ImageProvider._createErrorHandlerAndKey.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:460:26)
I/flutter ( 5679): (elided 13 frames from dart:async)
I/flutter ( 5679): 
I/flutter ( 5679): Image provider: AssetImage(bundle: null, name: "assets/images/waiting.png")
I/flutter ( 5679): Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#288b8(), name:
I/flutter ( 5679):   "assets/images/waiting.png", scale: 1.0)
I/flutter ( 5679): ════════════════════════════════════════════════════════════════════════════════════════════════════
0
Matt 8 oct. 2020 a las 05:55

2 respuestas

La mejor respuesta

Tuve que mover la carpeta de activos al mismo nivel de la carpeta lib. PERO también tuve que solucionar problemas de sangría para el archivo pubspec.yaml.

flutter:
  uses-material-design: true
  assets:
   - assets/
--------------------------------
flutter:
[space][space]uses-material-design: true
[space][space]assets:
[space][space][space]- assets/
0
Matt 8 oct. 2020 a las 12:03

Como dijo Omi Shah, mueva la carpeta de activos al mismo nivel que la carpeta lib.

O

Por favor intente cambiar pubspec.yaml y URL de recurso '

Image.asset(
                    'lib/assets/images/waiting.png',
                    fit: BoxFit.cover,
                  ),
flutter:
uses-material-design: true
assets:
  - lib/assets/images/
1
KuKu 8 oct. 2020 a las 05:23