skip to Main Content

I have been using a listview to display my images, and everything works fine, but when I tried to switch to carousel slider package, the moment I installed it, I got these errors

Launching libmain.dart on SM M025F in debug mode...
Invalid depfile: C:UsersDEGUIOneDriveDocumentsFlutterkoulch_mobile.dart_toolflutter_build4db31347d1e56d1057c4a84218158705kernel_snapshot.d
Invalid depfile: C:UsersDEGUIOneDriveDocumentsFlutterkoulch_mobile.dart_toolflutter_build4db31347d1e56d1057c4a84218158705kernel_snapshot.d
Error: Couldn't resolve the package 'carousel_slider' in 'package:carousel_slider/carousel_slider.dart'.
packages/koulch_ui/lib/src/widgets/common/kch_carousel_slider.dart:1:8: Error: Not found: 'package:carousel_slider/carousel_slider.dart'
import 'package:carousel_slider/carousel_slider.dart';
       ^
packages/koulch_ui/lib/src/widgets/common/kch_carousel_slider.dart:19:14: Error: The method 'CarouselSlider' isn't defined for the class '_CarouselSliderTemplateState'.
 - '_CarouselSliderTemplateState' is from 'package:koulch_ui/src/widgets/common/kch_carousel_slider.dart' ('packages/koulch_ui/lib/src/widgets/common/kch_carousel_slider.dart').
Try correcting the name to the name of an existing method, or defining a method named 'CarouselSlider'.
      child: CarouselSlider(
             ^^^^^^^^^^^^^^
packages/koulch_ui/lib/src/widgets/common/kch_carousel_slider.dart:21:20: Error: The method 'CarouselOptions' isn't defined for the class '_CarouselSliderTemplateState'.
 - '_CarouselSliderTemplateState' is from 'package:koulch_ui/src/widgets/common/kch_carousel_slider.dart' ('packages/koulch_ui/lib/src/widgets/common/kch_carousel_slider.dart').
Try correcting the name to the name of an existing method, or defining a method named 'CarouselOptions'.
          options: CarouselOptions(
                   ^^^^^^^^^^^^^^^
Unhandled exception:
FileSystemException(uri=org-dartlang-untranslatable-uri:package%3Acarousel_slider%2Fcarousel_slider.dart; message=StandardFileSystem only supports file:* and data:* URIs)
#0      StandardFileSystem.entityForUri (package:front_end/src/api_prototype/standard_file_system.dart:34:7)
#1      asFileUri (package:vm/kernel_front_end.dart:732:37)
#2      writeDepfile (package:vm/kernel_front_end.dart:870:21)
<asynchronous suspension>
#3      FrontendCompiler.compile (package:frontend_server/frontend_server.dart:676:9)
<asynchronous suspension>
#4      starter (package:frontend_server/starter.dart:102:12)
<asynchronous suspension>
#5      main (file:///C:/b/s/w/ir/x/w/sdk/pkg/frontend_server/bin/frontend_server_starter.dart:13:14)
<asynchronous suspension>

Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* Where:
Script 'C:srcflutterpackagesflutter_toolsgradlesrcmaingroovyflutter.groovy' line: 1350

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:srcflutterbinflutter.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 55s
Exception: Gradle task assembleDebug failed with exit code 1


Exited (1).

I tried to change the package version, I removed the build folder, but nothing seems to work

I have a sub-package called Koulch-UI inside the main package, and the carousel slide is inside of it, this is the pubspec

name: koulch_ui
description: A new Flutter package project.
publish_to: none
version: 0.0.1
homepage:

environment:
  sdk: '>=3.0.6 <4.0.0'
  flutter: ">=1.17.0"

dependencies:
  flutter:
    sdk: flutter
  koulch:
    path: ../../
  flutter_rating_bar: ^4.0.1
  flutter_remixicon:
    path: ../flutter_remixicon
  koulch_assets:
    path: ../koulch_assets
  koulch_models:
    path: ../koulch_models
  lottie: ^2.5.0
  image_picker: ^1.0.7
  image_cropper: ^4.0.0
  shared_preferences: ^2.2.2
  carousel_slider: ^4.2.0

    

dev_dependencies:
  flutter_test:
    sdk: flutter
  # flutter_lints: ^2.0.0

and this is the code

import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';

class CarouselSliderTemplate extends StatefulWidget {
  final height;
  final Clip? clipBehaviour;
  final images;
  const CarouselSliderTemplate(
      {super.key, this.images, this.height, this.clipBehaviour});

  @override
  State<CarouselSliderTemplate> createState() => _CarouselSliderTemplateState();
}

class _CarouselSliderTemplateState extends State<CarouselSliderTemplate> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: CarouselSlider(
          items: widget.images,
          options: CarouselOptions(
            height: widget.height,
            clipBehavior: widget.clipBehaviour!,
            enlargeCenterPage: true,
            autoPlay: true,
            aspectRatio: 16 / 9,
            autoPlayCurve: Curves.fastOutSlowIn,
            enableInfiniteScroll: true,
            autoPlayAnimationDuration: Duration(milliseconds: 800),
            viewportFraction: 0.8,
          )),
    );
  }
}

sorry I am relatively new to coding so, maybe this is a stupid question

2

Answers


  1. Chosen as BEST ANSWER

    sorry guys, I tried two fixes and I am not sure which worked but now it has been fixed.

    1- I tried to Delete Flutter Build Cache.

    2- then i manually deleted the dart_tool folder.

    after that I ran pub-get and flutter run and it works now.


  2. Simply running flutter clean and when it finishes, running flutter pub get
    will fix your problem

    Happy Coding 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search