serenader2014 / flutter_carousel_slider

A flutter carousel widget, support infinite scroll, and custom child widget.
https://pub.dev/packages/carousel_slider
MIT License
1.59k stars 580 forks source link

Import conflicts with CarouselController in Flutter version 3.23.0-13.0.pre.168 #442

Closed mg3994 closed 2 months ago

mg3994 commented 3 months ago

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:


../../../hostedtoolcache/flutter/master/arm64/.pub-cache/hosted/pub.dev/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';
^^^^^^^^^^^^^^^^^^
../../../hostedtoolcache/flutter/master/arm64/.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,
              ^^^^^^^^^^^^^^^^^^
../../../hostedtoolcache/flutter/master/arm64/.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,
              ^^^^^^^^^^^^^^^^^^

Suggested Solution

This issue can be resolved by using the as or show 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.

corentinbourdeau commented 3 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.

kishan-dhankecha commented 3 months ago

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.

corentinbourdeau commented 3 months ago

Hi, I tryed to hide like you but that doesn't change. Used an other name is a good idea !

dhirajbajaj commented 3 months ago

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

kishan-dhankecha commented 3 months ago

See the changelog, there I mentioned what has changed!

MelvinITOI commented 3 months ago

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

dhirajbajaj commented 3 months ago

I get this error:

image

kishan-dhankecha commented 3 months ago

Please See the changelog, where I mentioned what has changed!

@dhirajbajaj In your case replace carouselController with controller.

dhirajbajaj commented 3 months ago

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;
lukehutch commented 2 months ago

@kishan-dhankecha Thank you for providing a solution!

rajuchapagain commented 2 months ago

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.

mg3994 commented 2 months ago

@rajuchapagain try to use hide keyword in import of material dart

al-batol commented 1 month ago

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.

hagiosolat commented 1 month ago

hide key word is not working @al-batol as you have explained above

al-batol commented 1 month ago

hide key word is not working @al-batol as you have explained above strange show me

YawashimaLearning commented 1 month ago

I try below can solved this issue:

  1. update carousel_slider to ^5.0.0
  2. Change CarouselController to CarouselSliderController()

    final CarouselSliderController _carouselController = CarouselSliderController();

PuzzleTakX commented 1 month ago

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 )

sergeahs commented 1 month ago

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();
RouryR commented 4 weeks ago

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();

Thank you, it works!

ThairongSeng commented 3 weeks ago

I try below can solved this issue:

  1. update carousel_slider to ^5.0.0
  2. Change CarouselController to CarouselSliderController()

final CarouselSliderController _carouselController = CarouselSliderController();

this one really works

lucas-almeida026 commented 2 weeks ago

Here are steps to "fix" this issue (using a work around strategy) while we wait for the merge

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.

Steps:

  1. download the code from flutterflow
  2. unzip the folder and open it using the code editor (in my case VScode)
  3. run flutter pub cache repair (it takes a while to finish)
  4. try to run the app (using your device id) flutter run -d <device_id> it will fail
  5. from the logs you'll see some files from the downloaded libraries, in my case, since I'm using windows, they contain AppData/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
  6. use Ctrl + F and search for the term CarouselController using both Match Case and Match Whole Word features find-and-replace
  7. replace all instances of CarouselController with CarouselControllerPlus this is case sensitive, so pay attention
  8. now change the search and replace all instance of carouselController with carouselControllerPlus and save the file
  9. go to the file carousel_controller.dart also inside the folder lib and repeat the process, replace all CarouselController with CarouselControllerPlus. there are no instances of carouselController in this file

now 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.

Now, for each file path in the logs that corresponds to a page in your app (in my case, there's only one), follow these steps:

  1. open the file (I use Ctrl + click on the file path), you should be placed in the line that is triggering the error, it probably looks like this carouselController: _model.carouselController ??= CarouselController()
  2. Ctrl + click (jump to definition) on the model.carouselController and replace CarouselController with CarouselControllerPlus and carouselController with carouselControllerPlus. (don't click in the word "model", click in the word "carouselController")
  3. go back to the page file and replace 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>