因为来自 sdk 的 flutter_test 的每个版本都依赖于路径 1.8.1,而 easy_localization 3.0.0 依赖于路径 >=1.8.0-nullsafety

因为来自 sdk 的 flutter_test 的每个版本都依赖于路径 1.8.1,而 easy_localization 3.0.0 依赖于路径 >=1.8.0-nullsafety <=1.8.0,所以来自 sdk 的 flutter_test 与 easy_localization 3.0.0 不兼容。并且因为没有任何版本的easy_localization 匹配>3.0.0 <4.0.0,所以来自sdk 的flutter_test 与easy_localization ^3.0.0 不兼容。所以,因为 zcart 依赖于来自 sdk 的 easy_localization ^3.0.0 和 flutter_test,所以版本求解失败了。在 zcart 中运行“flutter pub get”... pub get failed (1; 所以,因为 zcart 依赖于来自 sdk 的 easy_localization ^3.0.0 和 flutter_test,版本求解失败。) ----------- -----------------main.dart------------------------------ ---

import 'package:easy_dynamic_theme/easy_dynamic_theme.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:nb_utils/nb_utils.dart';
import 'package:zcart/Theme/theme.dart';
import 'package:zcart/config/config.dart';
import 'package:zcart/data/network/api.dart';
import 'package:zcart/helper/constants.dart';
import 'package:zcart/riverpod/providers/logger_provider.dart';
import 'package:zcart/translations/codegen_loader.g.dart';
import 'package:zcart/translations/supported_locales.dart';
import 'views/screens/startup/loading_screen.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Initialize the localizations
  await EasyLocalization.ensureInitialized();

  //Shared Pref Initialization
  await initialize();

  //Hive Initialization
  await Hive.initFlutter();
  await Hive.openBox(hiveBox);

  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);

  //Run the app
  runApp(
    EasyDynamicThemeWidget(
      child: EasyLocalization(
        path: "assets/translations",
        supportedLocales: supportedLocales,
        fallbackLocale: const Locale("en"),
        assetLoader: const CodegenLoader(),
        child: ProviderScope(
          observers: [Logger()],
          child: const MyApp(),
        ),
      ),
    ),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      supportedLocales: context.supportedLocales,
      localizationsDelegates: context.localizationDelegates,
      locale: context.locale,
      debugShowCheckedModeBanner: false,
      title: API.appName,
      themeMode: MyConfig.isDynamicThemeActive
          ? EasyDynamicTheme.of(context).themeMode == ThemeMode.system
              ? ThemeMode.light
              : EasyDynamicTheme.of(context).themeMode
          : ThemeMode.light,
      theme: AppTheme.light(context),
      darkTheme: AppTheme.dark(context),
      home: const LoadingScreen(),
    );
  }
}

---------------------------------我的 pubspec.yaml---------- -----------------------------------------

#Don't Change anything here
name: zcart
description: A multivendor E commerce App.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

#Only Chnage this value to update your version
#1.0.0 is version number and 1 is build number
version: 2.0.1+2

#Don't Change Anything From here
environment:
  sdk: '>=2.12.0 <3.0.0'

dependencies:
  flutter:
    sdk: flutter
  flutter_riverpod: ^0.14.0
  http: ^0.13.3
  flutter_widget_from_html: ^0.8.0
  carousel_slider: ^4.0.0
  flutter_rating_bar: ^4.0.0
  shimmer: ^2.0.0
  flutter_slidable: ^0.6.0
  nb_utils: ^4.2.3
  velocity_x: ^3.3.0
  share: ^2.0.1
  datetime_picker_formfield: ^2.0.0
  flutter_countdown_timer: ^4.1.0
  font_awesome_flutter: ^9.1.0
  google_fonts: ^2.1.0
  flutter_spinkit: ^5.0.0
  cupertino_icons: ^1.0.0
  animations: ^2.0.1
  easy_localization: ^3.0.0
  easy_dynamic_theme: ^2.2.0
  google_sign_in: ^5.0.7
  flutter_facebook_auth: ^3.5.1
  hive: ^2.0.4
  hive_flutter: ^1.1.0
  device_info: ^2.0.2
  flutter_credit_card: ^3.0.0
  flutter_paystack: ^1.0.5+1
  flutter_paypal: ^0.0.8
  sign_in_with_apple: ^3.2.0
  url_launcher: ^6.0.12
  razorpay_flutter:
    git:
      url: git://github.com/devShakib015/razorpay-flutter.git

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_native_splash: ^1.2.1
  flutter_lints: ^1.0.4

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

flutter_native_splash:

  # This package generates native code to customize Flutter's default white native splash screen
  # with background color and splash image.
  # Customize the parameters below, and run the following command in the terminal:
  # flutter pub run flutter_native_splash:create
  # To restore Flutter's default white splash screen, run the following command in the terminal:
  # flutter pub run flutter_native_splash:remove

  # color or background_image is the only required parameter.  Use color to set the background
  # of your splash screen to a solid color.  Use background_image to set the background of your
  # splash screen to a png image.  This is useful for gradients. The image will be stretch to the
  # size of the app. Only one parameter can be used, color and background_image cannot both be set.
  color: "#f5f5f5"
  #background_image: "assets/splash.png"

  # Optional parameters are listed below.  To enable a parameter, uncomment the line by removing 
  # the leading # character.

  # The image parameter allows you to specify an image used in the splash screen.  It must be a 
  # png file and should be sized for 4x pixel density.
  image: assets/images/splash.png

  # The color_dark, background_image_dark, and image_dark are parameters that set the background
  # and image when the device is in dark mode. If they are not specified, the app will use the
  # parameters from above. If the image_dark parameter is specified, color_dark or 
  # background_image_dark must be specified.  color_dark and background_image_dark cannot both be
  # set.
  #color_dark: "#042a49"
  #background_image_dark: "assets/dark-background.png"
  #image_dark: assets/splash-invert.png

  # The android, ios and web parameters can be used to disable generating a splash screen on a given 
  # platform.
  #android: false
  #ios: false
  #web: false

  # The position of the splash image can be set with android_gravity, ios_content_mode, and
  # web_image_mode parameters.  All default to center.
  #
  # android_gravity can be one of the following Android Gravity (see 
  # https://developer.android.com/reference/android/view/Gravity): bottom, center, 
  # center_horizontal, center_vertical, clip_horizontal, clip_vertical, end, fill, fill_horizontal,
  # fill_vertical, left, right, start, or top.
  #android_gravity: center
  #
  # ios_content_mode can be one of the following iOS UIView.ContentMode (see 
  # https://developer.apple.com/documentation/uikit/uiview/contentmode): scaleToFill, 
  # scaleAspectFit, scaleAspectFill, center, top, bottom, left, right, topLeft, topRight, 
  # bottomLeft, or bottomRight.
  #ios_content_mode: center
  #
  # web_image_mode can be one of the following modes: center, contain, stretch, and cover.
  #web_image_mode: center

  # To hide the notification bar, use the fullscreen parameter.  Has no affect in web since web 
  # has no notification bar.  Defaults to false.
  # NOTE: Unlike Android, iOS will not automatically show the notification bar when the app loads.
  #       To show the notification bar, add the following code to your Flutter app:
  #       WidgetsFlutterBinding.ensureInitialized();
  #       SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom, SystemUiOverlay.top]);
  fullscreen: true

  # If you have changed the name(s) of your info.plist file(s), you can specify the filename(s)
  # with the info_plist_files parameter.  Remove only the # characters in the three lines below,
  # do not remove any spaces:
  #info_plist_files:
  #  - 'ios/Runner/Info-Debug.plist'
  #  - 'ios/Runner/Info-Release.plist'

  # To enable support for Android 12, set the following parameter to true.  Defaults to false.
  #android12: true
stack overflow Because every version of flutter_test from sdk depends on path 1.8.1 and easy_localization 3.0.0 depends on path >=1.8.0-nullsafety
原文答案

答案:

作者头像

我为我解决了。运行此命令:

dart pub upgrade --null-safety

此命令将所有库升级到空安全版本。在优化您的代码以实现零安全性之后。运行此命令时,您只能看到可升级的库:

dart pub upgrade --null-safety --dry-run
作者头像

编辑:他们最近将 flutter_test 的路径版本升级到 1.8.1 https://github.com/flutter/flutter/blame/d063961dda02ee1488daf3e5b336bc64060f4691/packages/flutter_test/pubspec.yaml#L18

flutter channel stable && flutter upgrade
rm pubspec.lock
flutter pub get

应该解决这个问题。

我认为问题在于您的 Flutter 版本。我认为您仍在使用 Flutter 1.x,因此您没有空安全性。你能分享一下你当前的 Flutter 版本吗?只需运行“flutter医生”并分享结果。如果你想将你的flutter版本升级到 2.x 运行:

flutter channel stable && flutter upgrade

但是您可能需要将代码迁移到空安全。查看这个有用的指南: https://blog.logrocket.com/migrating-flutter-project-null-safety/

无论如何,如果您不想升级 Flutter,可以尝试使用 easy_localization: ^2.3.3 代替。此版本不包括 null 安全功能。

试试这个:

easy_localization: ^2.3.3

代替

easy_localization: ^3.0.0