首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >参数类型'AssetGenImage‘不能分配给参数类型'ImageProvider’

参数类型'AssetGenImage‘不能分配给参数类型'ImageProvider’
EN

Stack Overflow用户
提问于 2022-08-15 19:19:29
回答 2查看 198关注 0票数 0

我正在使用颤振gen软件包来初始化图像。

代码语言:javascript
复制
    Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Image(image: Assets.images.logo, height: 64),//error is here
              const SizedBox(
                height: 32,
              ),
              const SpinKitFadingCube(
                color: Solidcolors.primaryColor,
                size: 32.0,
              )
            ],
          ),
        ),
      ),
    );
  }
}

这是一个错误:

参数类型'AssetGenImage‘不能分配给参数类型'ImageProvider’

下面是我生成的文件:

代码语言:javascript
复制
import 'package:flutter/widgets.dart';

    class $AssetsImagesGen {
    const $AssetsImagesGen();

    /// File path: assets/images/logo.png
     AssetGenImage get logo => const 
     AssetGenImage('assets/images/logo.png');
     }

     class Assets {
      Assets._();

      static const $AssetsImagesGen images = 
      $AssetsImagesGen();
      }``
EN

Stack Overflow用户

发布于 2022-08-15 19:52:43

只需作为Assets.logo.image()使用,它本身就能提供图像。

代码语言:javascript
复制
 children: [
       Assets.logo.image(height:64),

右侧部分将生成。

代码语言:javascript
复制
/// GENERATED CODE - DO NOT MODIFY BY HAND
/// *****************************************************
///  FlutterGen
/// *****************************************************

// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: directives_ordering,unnecessary_import

import 'package:flutter/widgets.dart';

class Assets {
  Assets._();
  static const AssetGenImage logo = AssetGenImage('assets/logo.jpg');

}

class AssetGenImage {
  const AssetGenImage(this._assetName);

  final String _assetName;

  Image image({
    Key? key,
    AssetBundle? bundle,
    ImageFrameBuilder? frameBuilder,
    ImageErrorWidgetBuilder? errorBuilder,
    String? semanticLabel,
    bool excludeFromSemantics = false,
    double? scale,
    double? width,
    double? height,
    Color? color,
    Animation<double>? opacity,
    BlendMode? colorBlendMode,
    BoxFit? fit,
    AlignmentGeometry alignment = Alignment.center,
    ImageRepeat repeat = ImageRepeat.noRepeat,
    Rect? centerSlice,
    bool matchTextDirection = false,
    bool gaplessPlayback = false,
    bool isAntiAlias = false,
    String? package,
    FilterQuality filterQuality = FilterQuality.low,
    int? cacheWidth,
    int? cacheHeight,
  }) {
    return Image.asset(
      _assetName,
      key: key,
      bundle: bundle,
      frameBuilder: frameBuilder,
      errorBuilder: errorBuilder,
      semanticLabel: semanticLabel,
      excludeFromSemantics: excludeFromSemantics,
      scale: scale,
      width: width,
      height: height,
      color: color,
      opacity: opacity,
      colorBlendMode: colorBlendMode,
      fit: fit,
      alignment: alignment,
      repeat: repeat,
      centerSlice: centerSlice,
      matchTextDirection: matchTextDirection,
      gaplessPlayback: gaplessPlayback,
      isAntiAlias: isAntiAlias,
      package: package,
      filterQuality: filterQuality,
      cacheWidth: cacheWidth,
      cacheHeight: cacheHeight,
    );
  }

  String get path => _assetName;

  String get keyName => _assetName;
}
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73365537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档