You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter项目中upi_payment_qrcode_generator包缺少fileName字段报错

问题

在Flutter项目中添加upi_payment_qrcode_generator: ^1.1.2包后,出现错误提示:该插件在pubspec.yaml中缺少必填字段fileName。以下是项目的pubspec.yaml内容:

name: my_office
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.1.0+9

environment:
  sdk: '>=2.18.6 <3.0.0'

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  auto_size_text: ^3.0.0
  slide_to_confirm: ^1.1.0
  percent_indicator: ^3.4.0
  flutter_neumorphic: ^3.2.0
  dropdown_button2: ^1.0.0
  timelines: ^0.1.0
  firebase_core: ^2.5.0
  firebase_auth: ^4.2.6
  firebase_database: ^10.0.10
  shared_preferences: ^2.0.17
  after_layout: ^1.2.0
  intl: ^0.17.0
  hive_flutter: ^1.1.0
  iconsax: ^0.0.8
  flutter_animate: ^1.0.0
  widget_circular_animator: ^1.0.0
  delayed_display: ^2.0.0
  awesome_dialog: ^3.0.0
  internet_connection_checker: ^1.0.0+1
  connectivity_plus: ^2.3.5
  lottie: ^2.2.0
  image_picker: ^0.8.6+2
  flutter_local_notifications: ^12.0.4
  timezone: ^0.9.1
  firebase_storage: ^11.0.14
  external_app_launcher: ^3.1.0
  url_launcher: ^6.1.10
  image: ^4.0.15
  cached_network_image: ^3.2.3
  pdf: ^3.9.0
  open_file: ^3.2.1
  upi_payment_qrcode_generator: ^1.1.2
  dropdown_textfield: ^1.0.8
  provider: ^6.0.5
  path_provider: ^2.0.13
  cloud_firestore: ^4.4.3


dev_dependencies:
  flutter_test:
    sdk: flutter
  build_runner:
  hive_generator:

  # The "flutter_lints" package below contains a set of recommended lints to
  # encourage good coding practices. The lint set provided by the package is
  # activated in the `analysis_options.yaml` file located at the root of your
  # package. See that file for information about deactivating specific lint
  # rules and activating additional ones.
  flutter_lints: ^2.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
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

  # To add assets to your application, add an assets section, like this:
  assets:
    - assets/
    - assets/animations/
    - assets/visit/

  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  fonts:
    - family: PoppinsRegular
      fonts:
        - asset: assets/fonts/poppins/Poppins-Regular.ttf

    - family: PoppinsMedium
      fonts:
        - asset: assets/fonts/poppins/Poppins-Medium.ttf

    - family: PoppinsSemibold
      fonts:
        - asset: assets/fonts/poppins/Poppins-SemiBold.ttf

    - family: PoppinsBold
      fonts:
        - asset: assets/fonts/poppins/Poppins-Bold.ttf

  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

解决方案

这个错误提示存在误导,fileName并非需要在pubspec.yaml中配置的字段,而是调用该包生成二维码时必须传入的参数。

正确调用方式

使用upi_payment_qrcode_generator生成UPI支付二维码时,必须在generateQRCode方法中传入fileName参数,示例代码如下:

import 'package:upi_payment_qrcode_generator/upi_payment_qrcode_generator.dart';

void generateUPIQRCode() {
  UPIPaymentQRCodeGenerator.generateQRCode(
    upiId: 'your_upi_id@examplebank', // 替换为实际的UPI ID
    payeeName: '收款人姓名',
    amount: '50.00', // 付款金额
    fileName: 'upi_payment_qr', // 必填参数,指定二维码图片的保存文件名
  );
}

额外排查步骤

如果执行上述操作后仍有问题,可尝试清理项目缓存并重新获取依赖:

  • 运行命令:flutter clean
  • 重新获取依赖:flutter pub get

内容的提问来源于stack exchange,提问作者Devendiran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 04:32:05