Closed mg3994 closed 2 months ago
As or show doesn't work for me, i've got the same issue :
Error: 'CarouselController' is imported from both 'package:carousel_slider/carousel_controller.dart' and 'package:flutter/src/material/carousel.dart'. import 'carousel_controller.dart'; ^^^^^^^^^^^^^^^^^^ ../.pub-cache/hosted/pub.dev/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, ^^^^^^^^^^^^^^^^^^ ../.pub-cache/hosted/pub.dev/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, ^^^^^^^^^^^^^^^^^^ Error: Compilation failed.
Hi, @mg3994 @corentinbourdeau
I'll fix this issue in my fork. So far I have hidden CarouselController
while importing material library from carousel_controller.dart
and carousel_slider_plus.dart
import 'package:flutter/material.dart' hide CarouselController;
Now I am thinking of changing the name of CarouselController
in this package. Is there any naming suggestion? I was thinking of using CarouselControllerPlus
as my fork is called carousel_slider_plus.
Hi, I tryed to hide like you but that doesn't change. Used an other name is a good idea !
What are the changes i have to do to shift to your package? @kishan-dhankecha
Besides import statement? it breaks in CarouselController part as well
See the changelog, there I mentioned what has changed!
I removed carousel_slider: ^4.2.1 in my pubspec.yaml. And i added carousel_slider_plus: ^6.0.0 to my pubspec.yaml. Now its working Great
I get this error:
Please See the changelog, where I mentioned what has changed!
@dhirajbajaj In your case replace carouselController
with controller
.
Yes it did the trick;
Replace
import 'package:carousel_slider/carousel_slider.dart';
to:
import 'package:carousel_slider_plus/carousel_slider_plus.dart';
In widget, do this
controller: _model.carouselController1 ??= CarouselControllerPlus(),
In all, model
replace to CarouselControllerPlus?
CarouselControllerPlus? carouselController1;
CarouselControllerPlus? carouselController2;
@kishan-dhankecha Thank you for providing a solution!
Until the issue gets fixed by Flutter team, I made it work by removing the line export 'src/material/carousel.dart'; from material.dart file manually.
@rajuchapagain try to use hide
keyword in import of material dart
This conflict happens because of the new flutter version and has added CarouselController.
just open the package file: carousel_slider.dart
and find out:
import 'package:flutter/material.dart';
change it to:
import 'package:flutter/material.dart' hide CarouselController;
also anywhere you invoke CarouselController you should hide it from material as we did above.
hide key word is not working @al-batol as you have explained above
hide key word is not working @al-batol as you have explained above strange show me
I try below can solved this issue:
Change CarouselController to CarouselSliderController()
final CarouselSliderController _carouselController = CarouselSliderController();
Use this and it will solve your problem
update package carousel_slider to version
carousel_slider: ^5.0.0
use import
import 'package:carousel_slider/carousel_slider.dart' as slider;
slider.CarouselSlider( options: slider.CarouselOptions( viewportFraction: 1, onPageChanged: (index, reason) { }, ), //... order your code )
Use this and it will solve your problem
update package carousel_slider to version
carousel_slider: ^5.0.0
and now replace CarouselController
to CarouselSliderController
ex :
import 'package:carousel_slider/carousel_slider.dart' as cs;
final cs.CarouselSliderController _controller = cs.CarouselSliderController();
Use this and it will solve your problem
update package carousel_slider to version
carousel_slider: ^5.0.0
and now replace
CarouselController
toCarouselSliderController
ex :
import 'package:carousel_slider/carousel_slider.dart' as cs; final cs.CarouselSliderController _controller = cs.CarouselSliderController();
Thank you, it works!
I try below can solved this issue:
- update carousel_slider to ^5.0.0
- Change CarouselController to CarouselSliderController()
final CarouselSliderController _carouselController = CarouselSliderController();
this one really works
I have one screen that uses the native carousel, and as far as I know, the steps are simple. However, the more instances of the component you have, the more changes you'll need to make. I'm testing the app locally using my Android phone in debug mode, so if your setup differs significantly from mine, the steps may not work for you.
flutter pub cache repair
(it takes a while to finish)flutter run -d <device_id>
it will failAppData/Local/Pub/Cache
which indicates these files are related to pub packages. Open the file that contains the path carousel_slider-4.2.1/lib/carousel_slider.dart
CarouselController
using both Match Case and Match Whole Word features CarouselController
with CarouselControllerPlus
this is case sensitive, so pay attentioncarouselController
with carouselControllerPlus
and save the filecarousel_controller.dart
also inside the folder lib
and repeat the process, replace all CarouselController
with CarouselControllerPlus
. there are no instances of carouselController
in this filenow if we try to run the app again, it should still fail but the file paths shown in the error logs shouldn't include any paths from the pub get cache folder except for one which will probably include the message "Context: Found this candidate, but the arguments don't match."
All other file paths should be related to the usage of the Carousel widget on pages in your app, if you're also using the widget on a custom code then I don't know exactly how to fix them but it should be similar.
carouselController: _model.carouselController ??= CarouselController()
CarouselController
with CarouselControllerPlus
and carouselController
with carouselControllerPlus
. (don't click in the word "model", click in the word "carouselController")CarouselController
with CarouselControllerPlus
and carouselController
with carouselControllerPlus
don't forget to save all files of course
now lets run the command again and it should work flutter run -d <device_id>
I'm experiencing import conflicts with CarouselController when using the carousel_slider package (version 4.2.1) with the latest Flutter version on the master channel (3.23.0-13.0.pre.168). This issue arises due to CarouselController being imported from both package:carousel_slider/carousel_controller.dart and package:flutter/src/material/carousel.dart.
Steps to Reproduce
Upgrade to Flutter version 3.23.0-13.0.pre.168 on the master channel. Add
carousel_slider: ^4.2.1
to pubspec.yaml. Attempt to build the project.Expected Behavior
The project should compile without import conflicts.
Actual Behavior
The following import conflict errors are encountered:
Suggested Solution
This issue can be resolved by using the
as
orshow
keywords to disambiguate the imports.Environment
carousel_slider version: 4.2.1 Flutter version: 3.23.0-13.0.pre.168 (master channel) Dart version: 3.5.0 (build 3.5.0-236.0.dev)
Additional Information
Please let me know if you need any more information or if I can assist in any way. Thank you for your attention to this issue.