无法从文件中获取图像

时间:2020-07-02 06:38:56

标签: flutter dart flutter-dependencies dart-pub

pubspec.yaml

google_sign_in: ^4.1.4
apple_sign_in:
    path: /home/Desktop/temp/apps/Apple/flutter_apple_sign_in/

PUB of flutter_apple_sign_in
# The following section is specific to Flutter.
flutter:
  uses-material-design: true
  plugin:
     androidPackage: dev.gilder.tom.apple_sign_in
     pluginClass: AppleSignInPlugin
  assets:
     -  images/


//Following is code

class _AppleSignInButtonState extends State<AppleSignInButton> {
  bool _isTapDown = false;

  @override
  Widget build(BuildContext context) {
    final bgColor =
        widget.style == ButtonStyle.black ? Colors.black : Colors.white;
    final textColor =
        widget.style == ButtonStyle.black ? Colors.white : Colors.black;
    final borderColor =
        widget.style == ButtonStyle.white ? Colors.white : Colors.black;

    return GestureDetector(
      onTapDown: (_) => setState(() => _isTapDown = true),
      onTapUp: (_) {
        setState(() => _isTapDown = false);
        widget?.onPressed();
      },
      onTapCancel: () => setState(() => _isTapDown = false),
      child: AnimatedContainer(
        duration: Duration(milliseconds: 100),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.all(
            Radius.circular(widget.cornerRadius),
          ),
        ),
        child: Container(
          child: widget.type == ButtonType.continueButton
              ? Image.asset("images/white_outlined.png")
              : Image.asset("images/getapple.jpg") //Here I am using jpg
        ),
        width: double.infinity,
      ),
    );
  }
}


Error
══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter (32764): The following assertion was thrown resolving an image codec:
I/flutter (32764): Unable to load asset: images/getapple.jpg
I/flutter (32764): 
I/flutter (32764): When the exception was thrown, this was the stack:
I/flutter (32764): #0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
I/flutter (32764): <asynchronous suspension>
I/flutter (32764): #1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:664:31)
I/flutter (32764): #2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:648:14)

**这里我在本地目录中使用flutter_apple_sign_in软件包, 我正在使用ubuntu, 我想修改该软件包的用户界面, 所以我分叉了 而且,当我访问该程序包时,我无法访问图像并出现上​​述错误。

我已附上以下屏幕截图。

** enter image description here

1 个答案:

答案 0 :(得分:2)

pubspec.yaml

您需要声明图像资产

flutter:
  assets:
    - images/getapple.jpg

或将所有图像文件包含在文件夹中

flutter:
  assets:
    - images/

如果未显示,请尝试停止并再次运行程序。