运行trip_flutter主工程时报错
来源:2-7 前端开发者如何快速上手Flutter开发(二)

whitecomet
2024-09-09
运行trip_flutter主工程时报错,报错日志如下:
Resolving dependencies…
Downloading packages…
carousel_slider 4.2.1 (5.0.0 available)
collection 1.18.0 (1.19.0 available)
flutter_lints 2.0.3 (4.0.0 available)
http_parser 4.0.2 (4.1.0 available)
leak_tracker 10.0.5 (10.0.7 available)
leak_tracker_flutter_testing 3.0.5 (3.0.8 available)
lints 2.1.1 (4.0.0 available)
material_color_utilities 0.11.1 (0.12.0 available)
string_scanner 1.2.0 (1.3.0 available)
test_api 0.7.2 (0.7.3 available)
Got dependencies!
10 packages have newer versions incompatible with dependency constraints.
Try flutter pub outdated
for more information.
Launching lib\main.dart on sdk gphone16k x86 64 in debug mode…
Running Gradle task ‘assembleDebug’…
You are applying Flutter’s app_plugin_loader Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/to/flutter-gradle-plugin-apply
You are applying Flutter’s main Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block: https://flutter.dev/to/flutter-gradle-plugin-apply
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
lib/widget/banner_widget.dart:2:1: Error: ‘CarouselController’ is imported from both ‘package:carousel_slider/carousel_controller.dart’ and ‘package:flutter/src/material/carousel.dart’.
import ‘package:flutter/material.dart’;
^^^^^^^^^^^^^^^^^^
lib/widget/banner_widget.dart:19:42: Error: ‘CarouselController’ is imported from both ‘package:carousel_slider/carousel_controller.dart’ and ‘package:flutter/src/material/carousel.dart’.
final CarouselController _controller = CarouselController();
^^^^^^^^^^^^^^^^^^
/C:/Users/longxl/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/carousel_slider-4.2.1/lib/carousel_slider.dart:9:1: Error: ‘CarouselController’ is imported from both ‘package:carousel_slider/carousel_controller.dart’ and ‘package:flutter/src/material/carousel.dart’.
import ‘carousel_controller.dart’;
^^^^^^^^^^^^^^^^^^
/C:/Users/longxl/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/carousel_slider-4.2.1/lib/carousel_slider.dart:48:15: Error: ‘CarouselController’ is imported from both ‘package:carousel_slider/carousel_controller.dart’ and ‘package:flutter/src/material/carousel.dart’.
: CarouselController() as CarouselControllerImpl,
^^^^^^^^^^^^^^^^^^
/C:/Users/longxl/AppData/Local/Pub/Cache/hosted/pub.flutter-io.cn/carousel_slider-4.2.1/lib/carousel_slider.dart:62:15: Error: ‘CarouselController’ is imported from both ‘package:carousel_slider/carousel_controller.dart’ and ‘package:flutter/src/material/carousel.dart’.
: CarouselController() as CarouselControllerImpl,
^^^^^^^^^^^^^^^^^^
Target kernel_snapshot_program failed: Exception
FAILURE: Build failed with an exception.
-
Where:
Script ‘E:\LXL_WORK\DEV_ENV\flutter\packages\flutter_tools\gradle\src\main\groovy\flutter.groovy’ line: 1687 -
What went wrong:
Execution failed for task ‘:app:compileFlutterBuildDebug’.
Process ‘command ‘E:\LXL_WORK\DEV_ENV\flutter\bin\flutter.bat’’ finished with non-zero exit value 1
- Try:
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.
- Get more help at https://help.gradle.org
BUILD FAILED in 3s
Error: Gradle task assembleDebug failed with exit code 1
日志提示CarouselController 有两处重复导入,如何解决啊
2回答
-
宝慕林6515096
2024-10-31
111
00 -
whitecomet
提问者
2024-09-09
已解决,参考https://pub.dev/packages/carousel_slider,修改pubspec.yaml的库的版本即可:
修改前:
carousel_slider: ^4.2.1
修改后:
carousel_slider: ^5.0.0
032024-11-04
相似问题