From 0c57b7fbebad3efb3f56fe8bf1c07d345dd2c895 Mon Sep 17 00:00:00 2001 From: Nikhil Rajput Date: Wed, 1 Feb 2023 21:56:02 +0530 Subject: [PATCH] bumped to version 2.0.2 --- CHANGELOG.md | 8 + example/lib/app_themes.dart | 98 +++--- example/lib/colors.dart | 14 +- example/lib/main.dart | 40 ++- example/pubspec.yaml | 2 +- lib/src/_expandable_carousel_widget.dart | 155 +++++----- lib/src/_flutter_carousel_widget.dart | 122 ++++---- lib/src/components/overflow_page.dart | 10 +- lib/src/components/size_reporting_widget.dart | 28 +- .../helpers/flutter_carousel_controller.dart | 91 +++--- lib/src/helpers/flutter_carousel_options.dart | 280 +++++++++--------- lib/src/helpers/flutter_carousel_state.dart | 40 +-- .../indicators/circular_slide_indicator.dart | 38 +-- .../indicators/circular_static_indicator.dart | 41 ++- .../circular_wave_slide_indicator.dart | 37 ++- .../indicators/sequential_fill_indicator.dart | 41 ++- pubspec.yaml | 10 +- 17 files changed, 538 insertions(+), 517 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69ceca3..a15fba7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 2.0.2 + +* **Add**: `indicatorMargin` property added to `CarouselOptions`. +* **Improvement**: Removed unnecessary dependencies. +* **Fix**: All known bug fixed and removed. +* **Improvement**: Performance improvements. +* **Optimization**: Removed unnecessary codes. + ## 2.0.1 * **Documentation**: Updated the documentation to reflect the new Github Pages deployment diff --git a/example/lib/app_themes.dart b/example/lib/app_themes.dart index 03b54bd..eadf78b 100644 --- a/example/lib/app_themes.dart +++ b/example/lib/app_themes.dart @@ -5,16 +5,16 @@ import 'colors.dart'; class AppThemes { AppThemes._(); - static final lightTheme = ThemeData.light().copyWith( - scaffoldBackgroundColor: lightBGColor, + static final darkTheme = ThemeData.dark().copyWith( + scaffoldBackgroundColor: darkBGColor, visualDensity: VisualDensity.adaptivePlatformDensity, bottomSheetTheme: const BottomSheetThemeData( - backgroundColor: lightColor, - modalBackgroundColor: lightColor, + backgroundColor: darkColor2, + modalBackgroundColor: darkColor2, ), - dialogBackgroundColor: lightBGColor, + dialogBackgroundColor: darkColor2, popupMenuTheme: const PopupMenuThemeData( - color: lightColor, + color: darkColor2, ), elevatedButtonTheme: ElevatedButtonThemeData( style: ButtonStyle( @@ -23,51 +23,50 @@ class AppThemes { ), textButtonTheme: TextButtonThemeData( style: ButtonStyle( - foregroundColor: MaterialStateProperty.all(darkColor), + foregroundColor: MaterialStateProperty.all(lightColor), ), ), appBarTheme: const AppBarTheme( - backgroundColor: lightBGColor, - elevation: 0.0, + backgroundColor: darkColor2, + elevation: 2.0, titleTextStyle: TextStyle( - color: darkColor, + color: lightColor, fontSize: 20.0, fontWeight: FontWeight.bold, ), iconTheme: IconThemeData( - color: darkColor, + color: lightColor, ), ), iconTheme: const IconThemeData( - color: darkColor, + color: lightColor, ), textTheme: const TextTheme( - bodyText1: TextStyle(color: darkColor), - bodyText2: TextStyle(color: darkColor), - subtitle1: TextStyle(color: darkColor), - subtitle2: TextStyle(color: darkColor), - caption: TextStyle(color: darkColor), - headline1: TextStyle(color: darkColor), - headline2: TextStyle(color: darkColor), - headline3: TextStyle(color: darkColor), - headline4: TextStyle(color: darkColor), - headline5: TextStyle(color: darkColor), - headline6: TextStyle(color: darkColor), - button: TextStyle(color: darkColor), - overline: TextStyle(color: darkColor), + bodyLarge: TextStyle(color: lightColor), + bodyMedium: TextStyle(color: lightColor), + bodySmall: TextStyle(color: lightColor), + titleLarge: TextStyle(color: lightColor), + titleMedium: TextStyle(color: lightColor), + titleSmall: TextStyle(color: lightColor), + displayLarge: TextStyle(color: lightColor), + displayMedium: TextStyle(color: lightColor), + displaySmall: TextStyle(color: lightColor), + labelLarge: TextStyle(color: lightColor), + labelMedium: TextStyle(color: lightColor), + labelSmall: TextStyle(color: lightColor), ), ); - static final darkTheme = ThemeData.dark().copyWith( - scaffoldBackgroundColor: darkBGColor, + static final lightTheme = ThemeData.light().copyWith( + scaffoldBackgroundColor: lightBGColor, visualDensity: VisualDensity.adaptivePlatformDensity, bottomSheetTheme: const BottomSheetThemeData( - backgroundColor: darkColor2, - modalBackgroundColor: darkColor2, + backgroundColor: lightColor, + modalBackgroundColor: lightColor, ), - dialogBackgroundColor: darkColor2, + dialogBackgroundColor: lightBGColor, popupMenuTheme: const PopupMenuThemeData( - color: darkColor2, + color: lightColor, ), elevatedButtonTheme: ElevatedButtonThemeData( style: ButtonStyle( @@ -76,38 +75,37 @@ class AppThemes { ), textButtonTheme: TextButtonThemeData( style: ButtonStyle( - foregroundColor: MaterialStateProperty.all(lightColor), + foregroundColor: MaterialStateProperty.all(darkColor), ), ), appBarTheme: const AppBarTheme( - backgroundColor: darkBGColor, - elevation: 0.0, + backgroundColor: lightColor, + elevation: 2.0, titleTextStyle: TextStyle( - color: lightColor, + color: darkColor, fontSize: 20.0, fontWeight: FontWeight.bold, ), iconTheme: IconThemeData( - color: lightColor, + color: darkColor, ), ), iconTheme: const IconThemeData( - color: lightColor, + color: darkColor, ), textTheme: const TextTheme( - bodyText1: TextStyle(color: lightColor), - bodyText2: TextStyle(color: lightColor), - subtitle1: TextStyle(color: lightColor), - subtitle2: TextStyle(color: lightColor), - caption: TextStyle(color: lightColor), - headline1: TextStyle(color: lightColor), - headline2: TextStyle(color: lightColor), - headline3: TextStyle(color: lightColor), - headline4: TextStyle(color: lightColor), - headline5: TextStyle(color: lightColor), - headline6: TextStyle(color: lightColor), - button: TextStyle(color: lightColor), - overline: TextStyle(color: lightColor), + bodyLarge: TextStyle(color: darkColor), + bodyMedium: TextStyle(color: darkColor), + bodySmall: TextStyle(color: darkColor), + titleLarge: TextStyle(color: darkColor), + titleMedium: TextStyle(color: darkColor), + titleSmall: TextStyle(color: darkColor), + displayLarge: TextStyle(color: darkColor), + displayMedium: TextStyle(color: darkColor), + displaySmall: TextStyle(color: darkColor), + labelLarge: TextStyle(color: darkColor), + labelMedium: TextStyle(color: darkColor), + labelSmall: TextStyle(color: darkColor), ), ); } diff --git a/example/lib/colors.dart b/example/lib/colors.dart index 4d471cd..62ece28 100644 --- a/example/lib/colors.dart +++ b/example/lib/colors.dart @@ -1,9 +1,9 @@ import 'dart:ui'; -const Color lightColor = Color.fromRGBO(250, 250, 250, 1); -const Color lightBGColor = Color.fromRGBO(220, 220, 220, 1); -const Color darkBGColor = Color.fromRGBO(20, 20, 30, 1); -const Color darkColor = Color.fromRGBO(10, 10, 40, 1.0); -const Color darkColor2 = Color.fromRGBO(21, 21, 36, 1.0); -Color lightShadowColor = const Color(0x1A505050); -Color darkShadowColor = const Color(0x0ddcdcdc); +const Color lightColor = Color.fromARGB(255, 252, 252, 252); +const Color lightBGColor = Color.fromARGB(255, 240, 240, 240); +const Color darkBGColor = Color.fromARGB(255, 20, 20, 30); +const Color darkColor = Color.fromARGB(255, 10, 10, 40); +const Color darkColor2 = Color.fromARGB(255, 21, 21, 36); +Color lightShadowColor = const Color.fromARGB(26, 80, 80, 80); +Color darkShadowColor = const Color.fromARGB(13, 220, 220, 220); diff --git a/example/lib/main.dart b/example/lib/main.dart index 3776701..1ffa4cb 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -4,15 +4,15 @@ import 'package:flutter_carousel_widget/flutter_carousel_widget.dart'; import 'app_themes.dart'; class Slide { - final String title; - final double height; - final Color color; - Slide({ required this.title, required this.height, required this.color, }); + + final Color color; + final double height; + final String title; } var slides = List.generate( @@ -35,7 +35,14 @@ final List sliders = slides width: double.infinity, height: item.height, child: Center( - child: Text(item.title), + child: Text( + item.title, + style: const TextStyle( + color: Colors.white, + fontSize: 24.0, + fontWeight: FontWeight.bold, + ), + ), ), ), ), @@ -71,11 +78,11 @@ class FlutterCarouselWidgetDemo extends StatelessWidget { } class DemoItem extends StatelessWidget { - final String title; - final String route; - const DemoItem(this.title, this.route, {Key? key}) : super(key: key); + final String route; + final String title; + @override Widget build(BuildContext context) { return InkWell( @@ -156,17 +163,25 @@ class ComplicatedImageDemo extends StatelessWidget { @override Widget build(BuildContext context) { + final deviceSize = MediaQuery.of(context).size; return Scaffold( appBar: AppBar(title: const Text('Image Slider Demo')), - body: Center( + body: Padding( + padding: const EdgeInsets.all(8.0), child: Container( constraints: BoxConstraints( maxHeight: MediaQuery.of(context).size.width, ), child: FlutterCarousel( options: CarouselOptions( - autoPlay: true, + autoPlay: false, autoPlayInterval: const Duration(seconds: 5), + disableCenter: true, + viewportFraction: 0.8, + height: deviceSize.height * 0.45, + indicatorMargin: 12.0, + enableInfiniteScroll: false, + slideIndicator: const CircularSlideIndicator(), ), items: sliders, ), @@ -216,8 +231,11 @@ class _ManuallyControlledSliderState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Manually Controlled Slider')), - body: Center( + body: Padding( + padding: const EdgeInsets.all(8.0), child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Expanded( diff --git a/example/pubspec.yaml b/example/pubspec.yaml index f69f5a6..687b0d6 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -3,7 +3,7 @@ description: Demonstrates how to use the flutter_carousel_widget package. publish_to: "none" -version: 1.0.0+1 +version: 1.0.0 environment: sdk: ">=2.16.0 <3.0.0" diff --git a/lib/src/_expandable_carousel_widget.dart b/lib/src/_expandable_carousel_widget.dart index fd81979..3fb2784 100644 --- a/lib/src/_expandable_carousel_widget.dart +++ b/lib/src/_expandable_carousel_widget.dart @@ -13,24 +13,6 @@ import 'package:flutter_carousel_widget/src/typedefs/widget_builder.dart'; import 'package:flutter_carousel_widget/src/utils/flutter_carousel_utils.dart'; class ExpandableCarousel extends StatefulWidget { - /// [ExpandableCarouselOptions] to create a [ExpandableCarouselState] with - final CarouselOptions options; - - /// The widgets to be shown in the carousel of default constructor - final List? items; - - /// The widget item builder that will be used to build item on demand - /// The third argument is the PageView's real index, can be used to cooperate - /// with Hero. - final ExtendedWidgetBuilder? itemBuilder; - - /// The count of items to be shown in the carousel - final int? itemCount; - - /// Setting it to a value much bigger than most pages' sizes might result in a - /// reversed - "expand and shrink" - effect. - final double estimatedPageSize; - /// The default constructor const ExpandableCarousel({ required this.items, @@ -54,43 +36,89 @@ class ExpandableCarousel extends StatefulWidget { assert(itemBuilder != null), super(key: key); + /// Setting it to a value much bigger than most pages' sizes might result in a + /// reversed - "expand and shrink" - effect. + final double estimatedPageSize; + + /// The widget item builder that will be used to build item on demand + /// The third argument is the PageView's real index, can be used to cooperate + /// with Hero. + final ExtendedWidgetBuilder? itemBuilder; + + /// The count of items to be shown in the carousel + final int? itemCount; + + /// The widgets to be shown in the carousel of default constructor + final List? items; + + /// [ExpandableCarouselOptions] to create a [ExpandableCarouselState] with + final CarouselOptions options; + @override ExpandableCarouselState createState() => ExpandableCarouselState(); } class ExpandableCarouselState extends State with TickerProviderStateMixin { - CarouselControllerImpl get carouselController => - widget.options.controller != null - ? widget.options.controller as CarouselControllerImpl - : CarouselController() as CarouselControllerImpl; + /// mode is related to why the page is being changed + CarouselPageChangedReason mode = CarouselPageChangedReason.controller; + CarouselState? _carouselState; + int _currentPage = 0; + bool _firstPageLoaded = false; + PageController? _pageController; + double _pageDelta = 0.0; + int _previousPage = 0; + bool _shouldDisposePageController = false; + late List _sizes; Timer? _timer; - CarouselOptions get options => widget.options; + @override + void didUpdateWidget(covariant ExpandableCarousel oldWidget) { + super.didUpdateWidget(oldWidget); - CarouselState? _carouselState; + _carouselState!.options = options; + _carouselState!.itemCount = widget.itemCount; - PageController? _pageController; + /// [_pageController] needs to be re-initialized to respond + /// to state changes + _pageController = PageController( + viewportFraction: options.viewportFraction, + keepPage: options.keepPage, + initialPage: _carouselState!.realPage, + ); - /// mode is related to why the page is being changed - CarouselPageChangedReason mode = CarouselPageChangedReason.controller; + _carouselState!.pageController = _pageController; - late List _sizes; - int _currentPage = 0; - int _previousPage = 0; - double _pageDelta = 0.0; - bool _shouldDisposePageController = false; - bool _firstPageLoaded = false; + /// handle autoplay when state changes + _handleAutoPlay(); - double get _currentSize => _sizes[_currentPage]; + _pageController?.addListener(() { + setState(() { + _currentPage = _pageController!.page!.floor(); + _pageDelta = _pageController!.page! - _pageController!.page!.floor(); + }); + }); - double get _previousSize => _sizes[_previousPage]; + if (oldWidget.options.controller != widget.options.controller) { + _pageController?.addListener(_updatePage); + _shouldDisposePageController = widget.options.controller == null; + } - bool get isBuilder => widget.itemBuilder != null; + if (_shouldReinitializeHeights(oldWidget)) { + _reinitializeSizes(); + } + } - bool get _isHorizontalScroll => - widget.options.scrollDirection == Axis.horizontal; + @override + void dispose() { + _pageController?.removeListener(_updatePage); + if (_shouldDisposePageController) { + _pageController?.dispose(); + } + _clearTimer(); + super.dispose(); + } @override void initState() { @@ -137,52 +165,21 @@ class ExpandableCarouselState extends State _shouldDisposePageController = widget.options.controller == null; } - @override - void didUpdateWidget(covariant ExpandableCarousel oldWidget) { - super.didUpdateWidget(oldWidget); - - _carouselState!.options = options; - _carouselState!.itemCount = widget.itemCount; - - /// [_pageController] needs to be re-initialized to respond - /// to state changes - _pageController = PageController( - viewportFraction: options.viewportFraction, - keepPage: options.keepPage, - initialPage: _carouselState!.realPage, - ); - - _carouselState!.pageController = _pageController; + CarouselControllerImpl get carouselController => + widget.options.controller != null + ? widget.options.controller as CarouselControllerImpl + : CarouselController() as CarouselControllerImpl; - /// handle autoplay when state changes - _handleAutoPlay(); + CarouselOptions get options => widget.options; - _pageController?.addListener(() { - setState(() { - _currentPage = _pageController!.page!.floor(); - _pageDelta = _pageController!.page! - _pageController!.page!.floor(); - }); - }); + bool get isBuilder => widget.itemBuilder != null; - if (oldWidget.options.controller != widget.options.controller) { - _pageController?.addListener(_updatePage); - _shouldDisposePageController = widget.options.controller == null; - } + double get _currentSize => _sizes[_currentPage]; - if (_shouldReinitializeHeights(oldWidget)) { - _reinitializeSizes(); - } - } + double get _previousSize => _sizes[_previousPage]; - @override - void dispose() { - _pageController?.removeListener(_updatePage); - if (_shouldDisposePageController) { - _pageController?.dispose(); - } - _clearTimer(); - super.dispose(); - } + bool get _isHorizontalScroll => + widget.options.scrollDirection == Axis.horizontal; void _changeMode(CarouselPageChangedReason mode) { mode = mode; diff --git a/lib/src/_flutter_carousel_widget.dart b/lib/src/_flutter_carousel_widget.dart index 381ac42..28fc1d1 100644 --- a/lib/src/_flutter_carousel_widget.dart +++ b/lib/src/_flutter_carousel_widget.dart @@ -13,20 +13,6 @@ import 'package:flutter_carousel_widget/src/typedefs/widget_builder.dart'; import 'package:flutter_carousel_widget/src/utils/flutter_carousel_utils.dart'; class FlutterCarousel extends StatefulWidget { - /// [CarouselOptions] to create a [FlutterCarouselState] with - final CarouselOptions options; - - /// The widgets to be shown in the carousel of default constructor - final List? items; - - /// The widget item builder that will be used to build item on demand - /// The third argument is the PageView's real index, can be used to cooperate - /// with Hero. - final ExtendedWidgetBuilder? itemBuilder; - - /// The count of items to be shown in the carousel - final int? itemCount; - /// The default constructor const FlutterCarousel({ required this.items, @@ -48,30 +34,67 @@ class FlutterCarousel extends StatefulWidget { assert(itemBuilder != null), super(key: key); + /// The widget item builder that will be used to build item on demand + /// The third argument is the PageView's real index, can be used to cooperate + /// with Hero. + final ExtendedWidgetBuilder? itemBuilder; + + /// The count of items to be shown in the carousel + final int? itemCount; + + /// The widgets to be shown in the carousel of default constructor + final List? items; + + /// [CarouselOptions] to create a [FlutterCarouselState] with + final CarouselOptions options; + @override FlutterCarouselState createState() => FlutterCarouselState(); } class FlutterCarouselState extends State with TickerProviderStateMixin { - CarouselControllerImpl get carouselController => - widget.options.controller != null - ? widget.options.controller as CarouselControllerImpl - : CarouselController() as CarouselControllerImpl; + /// mode is related to why the page is being changed + CarouselPageChangedReason mode = CarouselPageChangedReason.controller; + CarouselState? _carouselState; + int _currentPage = 0; + PageController? _pageController; + double _pageDelta = 0.0; Timer? _timer; - CarouselOptions get options => widget.options; + @override + void didUpdateWidget(covariant FlutterCarousel oldWidget) { + super.didUpdateWidget(oldWidget); + _carouselState!.options = options; + _carouselState!.itemCount = widget.itemCount; - CarouselState? _carouselState; + /// [_pageController] needs to be re-initialized to respond + /// to state changes + _pageController = PageController( + viewportFraction: options.viewportFraction, + keepPage: options.keepPage, + initialPage: _carouselState!.realPage, + ); - PageController? _pageController; + _carouselState!.pageController = _pageController; - /// mode is related to why the page is being changed - CarouselPageChangedReason mode = CarouselPageChangedReason.controller; + /// handle autoplay when state changes + _handleAutoPlay(); - int _currentPage = 0; - double _pageDelta = 0.0; + _pageController!.addListener(() { + setState(() { + _currentPage = _pageController!.page!.floor(); + _pageDelta = _pageController!.page! - _pageController!.page!.floor(); + }); + }); + } + + @override + void dispose() { + _clearTimer(); + super.dispose(); + } @override void initState() { @@ -112,38 +135,12 @@ class FlutterCarouselState extends State }); } - @override - void didUpdateWidget(covariant FlutterCarousel oldWidget) { - super.didUpdateWidget(oldWidget); - _carouselState!.options = options; - _carouselState!.itemCount = widget.itemCount; - - /// [_pageController] needs to be re-initialized to respond - /// to state changes - _pageController = PageController( - viewportFraction: options.viewportFraction, - keepPage: options.keepPage, - initialPage: _carouselState!.realPage, - ); - - _carouselState!.pageController = _pageController; - - /// handle autoplay when state changes - _handleAutoPlay(); - - _pageController!.addListener(() { - setState(() { - _currentPage = _pageController!.page!.floor(); - _pageDelta = _pageController!.page! - _pageController!.page!.floor(); - }); - }); - } + CarouselControllerImpl get carouselController => + widget.options.controller != null + ? widget.options.controller as CarouselControllerImpl + : CarouselController() as CarouselControllerImpl; - @override - void dispose() { - _clearTimer(); - super.dispose(); - } + CarouselOptions get options => widget.options; /// Timer Timer? _getTimer() { @@ -208,10 +205,12 @@ class FlutterCarouselState extends State } } + /// onStart void _onStart() { _changeMode(CarouselPageChangedReason.manual); } + /// onPanDown void _onPanDown() { if (widget.options.pauseAutoPlayOnTouch) { _clearTimer(); @@ -220,6 +219,7 @@ class FlutterCarouselState extends State _changeMode(CarouselPageChangedReason.manual); } + /// onPanEnd void _onPanUp() { if (widget.options.pauseAutoPlayOnTouch) { _resumeTimer(); @@ -271,13 +271,15 @@ class FlutterCarouselState extends State ); } + /// The method that build center wrapper Widget _getCenterWrapper(Widget child) { if (widget.options.disableCenter) { - return SizedBox(child: child); + return child; } return Center(child: child); } + /// The methoda that build enlarge wrapper Widget _getEnlargeWrapper(Widget? child, {double? width, double? height, double? scale}) { /// If [enlargeStrategy] is [CenterPageEnlargeStrategy.height] @@ -363,7 +365,7 @@ class FlutterCarouselState extends State var storageContext = _carouselState! .pageController!.position.context.storageContext; final previousSavedPosition = PageStorage.of(storageContext) - ?.readState(storageContext) as double?; + .readState(storageContext) as double?; if (previousSavedPosition != null) { itemOffset = previousSavedPosition - idx.toDouble(); } else { @@ -428,7 +430,7 @@ class FlutterCarouselState extends State children: [ _buildCarouselWidget(context), Positioned( - bottom: 8.0, + bottom: widget.options.indicatorMargin, left: 0.0, right: 0.0, child: _buildSlideIndicator(), @@ -449,7 +451,7 @@ class FlutterCarouselState extends State flex: 1, child: _buildCarouselWidget(context), ), - const SizedBox(height: 8.0), + SizedBox(height: widget.options.indicatorMargin), Expanded( flex: 0, child: _buildSlideIndicator(), diff --git a/lib/src/components/overflow_page.dart b/lib/src/components/overflow_page.dart index af79a43..ea4bab3 100644 --- a/lib/src/components/overflow_page.dart +++ b/lib/src/components/overflow_page.dart @@ -2,11 +2,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_carousel_widget/src/components/size_reporting_widget.dart'; class OverflowPage extends StatelessWidget { - final ValueChanged onSizeChange; - final Widget child; - final Alignment alignment; - final Axis scrollDirection; - const OverflowPage({ super.key, required this.onSizeChange, @@ -15,6 +10,11 @@ class OverflowPage extends StatelessWidget { required this.scrollDirection, }); + final Alignment alignment; + final Widget child; + final ValueChanged onSizeChange; + final Axis scrollDirection; + @override Widget build(BuildContext context) { return OverflowBox( diff --git a/lib/src/components/size_reporting_widget.dart b/lib/src/components/size_reporting_widget.dart index 2074032..add98a0 100644 --- a/lib/src/components/size_reporting_widget.dart +++ b/lib/src/components/size_reporting_widget.dart @@ -1,22 +1,32 @@ import 'package:flutter/material.dart'; class SizeReportingWidget extends StatefulWidget { - final Widget child; - final ValueChanged onSizeChange; - const SizeReportingWidget({ Key? key, required this.child, required this.onSizeChange, }) : super(key: key); + final Widget child; + final ValueChanged onSizeChange; + @override SizeReportingWidgetState createState() => SizeReportingWidgetState(); } class SizeReportingWidgetState extends State { - final _widgetKey = GlobalKey(); Size? _oldSize; + final _widgetKey = GlobalKey(); + + void _notifySize() { + final context = _widgetKey.currentContext; + if (context == null) return; + final size = context.size; + if (_oldSize != size) { + _oldSize = size; + widget.onSizeChange(size!); + } + } @override Widget build(BuildContext context) { @@ -34,14 +44,4 @@ class SizeReportingWidgetState extends State { ), ); } - - void _notifySize() { - final context = _widgetKey.currentContext; - if (context == null) return; - final size = context.size; - if (_oldSize != size) { - _oldSize = size; - widget.onSizeChange(size!); - } - } } diff --git a/lib/src/helpers/flutter_carousel_controller.dart b/lib/src/helpers/flutter_carousel_controller.dart index 7804192..c3bb208 100644 --- a/lib/src/helpers/flutter_carousel_controller.dart +++ b/lib/src/helpers/flutter_carousel_controller.dart @@ -6,6 +6,8 @@ import 'package:flutter_carousel_widget/src/helpers/flutter_carousel_state.dart' import 'package:flutter_carousel_widget/src/utils/flutter_carousel_utils.dart'; abstract class CarouselController { + factory CarouselController() => CarouselControllerImpl(); + bool get ready; Future get onReady; @@ -21,56 +23,56 @@ abstract class CarouselController { void startAutoPlay(); void stopAutoPlay(); - - factory CarouselController() => CarouselControllerImpl(); } class CarouselControllerImpl implements CarouselController { final Completer _readyCompleter = Completer(); - CarouselState? _state; - set state(CarouselState? state) { - _state = state; - if (!_readyCompleter.isCompleted) { - _readyCompleter.complete(); - } - } - - void _setModeController() => - _state!.changeMode(CarouselPageChangedReason.controller); - - @override - bool get ready => _state != null; - - @override - Future get onReady => _readyCompleter.future; - - /// Animates the controlled [FlutterCarouselWidget] to the next page. + /// Animates the controlled [FlutterCarouselWidget] from the current page to the given page. /// /// The animation lasts for the given duration and follows the given curve. /// The returned [Future] resolves when the animation completes. @override - Future nextPage( + Future animateToPage(int page, {Duration? duration = const Duration(milliseconds: 300), Curve? curve = Curves.linear}) async { final isNeedResetTimer = _state!.options.pauseAutoPlayOnManualNavigate; if (isNeedResetTimer) { _state!.onResetTimer(); } + final index = getRealIndex(_state!.pageController!.page!.toInt(), + _state!.realPage - _state!.initialPage, _state!.itemCount); _setModeController(); - await _state!.pageController!.nextPage(duration: duration!, curve: curve!); + await _state!.pageController!.animateToPage( + _state!.pageController!.page!.toInt() + page - index, + duration: duration!, + curve: curve!); if (isNeedResetTimer) { _state!.onResumeTimer(); } } - /// Animates the controlled [FlutterCarouselWidget] to the previous page. + /// Changes which page is displayed in the controlled [FlutterCarouselWidget]. + /// + /// Jumps the page position from its current value to the given value, + /// without animation, and without checking if the new value is in range. + @override + void jumpToPage(int page) { + final index = getRealIndex(_state!.pageController!.page!.toInt(), + _state!.realPage - _state!.initialPage, _state!.itemCount); + + _setModeController(); + final pageToJump = _state!.pageController!.page!.toInt() + page - index; + return _state!.pageController!.jumpToPage(pageToJump); + } + + /// Animates the controlled [FlutterCarouselWidget] to the next page. /// /// The animation lasts for the given duration and follows the given curve. /// The returned [Future] resolves when the animation completes. @override - Future previousPage( + Future nextPage( {Duration? duration = const Duration(milliseconds: 300), Curve? curve = Curves.linear}) async { final isNeedResetTimer = _state!.options.pauseAutoPlayOnManualNavigate; @@ -78,51 +80,38 @@ class CarouselControllerImpl implements CarouselController { _state!.onResetTimer(); } _setModeController(); - await _state!.pageController! - .previousPage(duration: duration!, curve: curve!); + await _state!.pageController!.nextPage(duration: duration!, curve: curve!); if (isNeedResetTimer) { _state!.onResumeTimer(); } } - /// Changes which page is displayed in the controlled [FlutterCarouselWidget]. - /// - /// Jumps the page position from its current value to the given value, - /// without animation, and without checking if the new value is in range. @override - void jumpToPage(int page) { - final index = getRealIndex(_state!.pageController!.page!.toInt(), - _state!.realPage - _state!.initialPage, _state!.itemCount); - - _setModeController(); - final pageToJump = _state!.pageController!.page!.toInt() + page - index; - return _state!.pageController!.jumpToPage(pageToJump); - } + Future get onReady => _readyCompleter.future; - /// Animates the controlled [FlutterCarouselWidget] from the current page to the given page. + /// Animates the controlled [FlutterCarouselWidget] to the previous page. /// /// The animation lasts for the given duration and follows the given curve. /// The returned [Future] resolves when the animation completes. @override - Future animateToPage(int page, + Future previousPage( {Duration? duration = const Duration(milliseconds: 300), Curve? curve = Curves.linear}) async { final isNeedResetTimer = _state!.options.pauseAutoPlayOnManualNavigate; if (isNeedResetTimer) { _state!.onResetTimer(); } - final index = getRealIndex(_state!.pageController!.page!.toInt(), - _state!.realPage - _state!.initialPage, _state!.itemCount); _setModeController(); - await _state!.pageController!.animateToPage( - _state!.pageController!.page!.toInt() + page - index, - duration: duration!, - curve: curve!); + await _state!.pageController! + .previousPage(duration: duration!, curve: curve!); if (isNeedResetTimer) { _state!.onResumeTimer(); } } + @override + bool get ready => _state != null; + /// Starts the controlled [FlutterCarouselWidget] autoplay. /// /// The carousel will only autoPlay if the [autoPlay] parameter @@ -140,4 +129,14 @@ class CarouselControllerImpl implements CarouselController { void stopAutoPlay() { _state!.onResetTimer(); } + + set state(CarouselState? state) { + _state = state; + if (!_readyCompleter.isCompleted) { + _readyCompleter.complete(); + } + } + + void _setModeController() => + _state!.changeMode(CarouselPageChangedReason.controller); } diff --git a/lib/src/helpers/flutter_carousel_options.dart b/lib/src/helpers/flutter_carousel_options.dart index 6e4d90e..8e29694 100644 --- a/lib/src/helpers/flutter_carousel_options.dart +++ b/lib/src/helpers/flutter_carousel_options.dart @@ -7,33 +7,55 @@ import 'package:flutter_carousel_widget/src/indicators/circular_slide_indicator. import 'package:flutter_carousel_widget/src/indicators/slide_indicator.dart'; class CarouselOptions { - /// Set carousel height and overrides any existing [aspectRatio]. - final double? height; - - /// Aspect ratio is used if no height have been declared. - /// - /// Defaults to 1:1 (square) aspect ratio. - final double? aspectRatio; - - /// The fraction of the viewport that each page should occupy. - /// - /// Defaults to 0.8, which means each page fills 80% of the carousel. - final double viewportFraction; + CarouselOptions({ + this.height, + this.aspectRatio, + this.viewportFraction = 0.9, + this.initialPage = 0, + this.enableInfiniteScroll = false, + this.reverse = false, + this.autoPlay = false, + this.autoPlayInterval = const Duration(seconds: 5), + this.autoPlayAnimationDuration = const Duration(milliseconds: 300), + this.autoPlayCurve = Curves.easeInCubic, + this.enlargeCenterPage = false, + this.controller, + this.onPageChanged, + this.onScrolled, + this.physics = const BouncingScrollPhysics(), + this.scrollDirection = Axis.horizontal, + this.pauseAutoPlayOnTouch = true, + this.pauseAutoPlayOnManualNavigate = true, + this.pauseAutoPlayInFiniteScroll = false, + this.pageViewKey, + this.keepPage = true, + this.enlargeStrategy = CenterPageEnlargeStrategy.scale, + this.disableCenter = false, + this.showIndicator = true, + this.floatingIndicator = true, + this.indicatorMargin = 8.0, + this.slideIndicator = const CircularSlideIndicator(), + this.clipBehavior = Clip.antiAlias, + this.scrollBehavior, + this.pageSnapping = true, + this.padEnds = true, + this.dragStartBehavior = DragStartBehavior.start, + this.allowImplicitScrolling = false, + this.restorationId, + }) : assert(showIndicator == true ? slideIndicator != null : true); - /// The initial page to show when first creating the [CarouselSlider]. - /// - /// Defaults to 0. - final int initialPage; + /// Called whenever the page in the center of the viewport changes. + final Function(int index, CarouselPageChangedReason reason)? onPageChanged; - ///Determines if carousel should loop infinitely or be limited to item length. + /// Controls whether the widget's pages will respond to [RenderObject.showOnScreen], which will allow for implicit accessibility scrolling. /// - ///Defaults to true, i.e. infinite loop. - final bool enableInfiniteScroll; + /// Corresponds to Material's PageView's allowImplicitScrolling parameter: https://api.flutter.dev/flutter/widgets/PageView-class.html + final bool allowImplicitScrolling; - /// Reverse the order of items if set to true. + /// Aspect ratio is used if no height have been declared. /// - /// Defaults to false. - final bool reverse; + /// Defaults to 1:1 (square) aspect ratio. + final double? aspectRatio; /// Enables auto play, sliding one page at a time. /// @@ -41,12 +63,6 @@ class CarouselOptions { /// Defaults to false. final bool autoPlay; - /// Sets Duration to determent the frequency of slides when - /// - /// [autoPlay] is set to true. - /// Defaults to 5 seconds. - final Duration autoPlayInterval; - /// The animation duration between two transitioning pages while in auto playback. /// /// Defaults to 500 ms. @@ -57,81 +73,79 @@ class CarouselOptions { /// Defaults to [Curves.easeInOut]. final Curve autoPlayCurve; - /// Determines if current page should be larger then the side images, - /// creating a feeling of depth in the carousel. + /// Sets Duration to determent the frequency of slides when /// - /// Defaults to false. - final bool? enlargeCenterPage; + /// [autoPlay] is set to true. + /// Defaults to 5 seconds. + final Duration autoPlayInterval; - /// The axis along which the page view scrolls. + /// The content will be clipped (or not) according to this option. /// - /// Defaults to [Axis.horizontal]. - final Axis scrollDirection; + /// Corresponds to Material's PageView's clipBehavior parameter: https://api.flutter.dev/flutter/widgets/PageView-class.html + final Clip clipBehavior; /// A [MapController], used to control the map. final CarouselController? controller; - /// Called whenever the page in the center of the viewport changes. - final Function(int index, CarouselPageChangedReason reason)? onPageChanged; - - /// Called whenever the carousel is scrolled - final ValueChanged? onScrolled; - - /// How the carousel should respond to user input. - /// - /// For example, determines how the items continues to animate after the - /// user stops dragging the page view. - /// - /// The physics are modified to snap to page boundaries using - /// [PageScrollPhysics] prior to being used. - /// - /// Defaults to matching platform conventions. - final ScrollPhysics? physics; - - ///A ScrollBehavior that will be applied to this widget individually. - // - // Defaults to null, wherein the inherited ScrollBehavior is copied and modified to alter the viewport decoration, like Scrollbars. - // - // ScrollBehaviors also provide ScrollPhysics. If an explicit ScrollPhysics is provided in physics, it will take precedence, followed by scrollBehavior, and then the inherited ancestor ScrollBehavior. - // - // The ScrollBehavior of the inherited ScrollConfiguration will be modified by default to not apply a Scrollbar. - final ScrollBehavior? scrollBehavior; + /// Whether or not to disable the `Center` widget for each slide. + final bool disableCenter; /// Determines the way that drag start behavior is handled. /// /// Corresponds to Material's PageView's dragStartBehavior parameter: https://api.flutter.dev/flutter/widgets/PageView-class.html final DragStartBehavior dragStartBehavior; - /// Controls whether the widget's pages will respond to [RenderObject.showOnScreen], which will allow for implicit accessibility scrolling. + ///Determines if carousel should loop infinitely or be limited to item length. /// - /// Corresponds to Material's PageView's allowImplicitScrolling parameter: https://api.flutter.dev/flutter/widgets/PageView-class.html - final bool allowImplicitScrolling; + ///Defaults to true, i.e. infinite loop. + final bool enableInfiniteScroll; - /// Restoration ID to save and restore the scroll offset of the scrollable. + /// Determines if current page should be larger then the side images, + /// creating a feeling of depth in the carousel. /// - /// Corresponds to Material's PageView's restorationId parameter: https://api.flutter.dev/flutter/widgets/PageView-class.html - final String? restorationId; + /// Defaults to false. + final bool? enlargeCenterPage; - /// The content will be clipped (or not) according to this option. + /// Use `enlargeStrategy` to determine which method to enlarge the center page. + final CenterPageEnlargeStrategy enlargeStrategy; + + /// Whether or not to float `SlideIndicator` over `Carousel`. + final bool floatingIndicator; + + /// Set carousel height and overrides any existing [aspectRatio]. + final double? height; + + /// Indicator margin + final double? indicatorMargin; + + /// The initial page to show when first creating the [CarouselSlider]. /// - /// Corresponds to Material's PageView's clipBehavior parameter: https://api.flutter.dev/flutter/widgets/PageView-class.html - final Clip clipBehavior; + /// Defaults to 0. + final int initialPage; + + /// Whether or not to keep pages in PageView + final bool keepPage; + + /// Called whenever the carousel is scrolled + final ValueChanged? onScrolled; + + /// Whether to add padding to both ends of the list. + /// If this is set to true and [viewportFraction] < 1.0, padding will be + /// added such that the first and last child slivers will be in the center + /// of the viewport when scrolled all the way to the start or end, + /// respectively. + /// If [viewportFraction] >= 1.0, this property has no effect. + /// This property defaults to true and must not be null. + final bool padEnds; /// Set to false to disable page snapping, useful for custom scroll behavior. /// /// Default to `true`. final bool pageSnapping; - /// If `true`, the auto play function will be paused when user is interacting with - /// the carousel, and will be resumed when user finish interacting. - /// Default to `true`. - final bool pauseAutoPlayOnTouch; - - /// If `true`, the auto play function will be paused when user is calling - /// pageController's `nextPage` or `previousPage` or `animateToPage` method. - /// And after the animation complete, the auto play will be resumed. - /// Default to `true`. - final bool pauseAutoPlayOnManualNavigate; + /// Pass a `PageStorageKey` if you want to keep the PageView's position when + /// it was recreated. + final PageStorageKey? pageViewKey; /// If `enableInfiniteScroll` is `false`, and `autoPlay` is `true`, this option /// decide the carousel should go to the first item when it reach the last item or not. @@ -140,72 +154,62 @@ class CarouselOptions { /// in the last item. final bool pauseAutoPlayInFiniteScroll; - /// Pass a `PageStorageKey` if you want to keep the PageView's position when - /// it was recreated. - final PageStorageKey? pageViewKey; + /// If `true`, the auto play function will be paused when user is calling + /// pageController's `nextPage` or `previousPage` or `animateToPage` method. + /// And after the animation complete, the auto play will be resumed. + /// Default to `true`. + final bool pauseAutoPlayOnManualNavigate; - /// Use `enlargeStrategy` to determine which method to enlarge the center page. - final CenterPageEnlargeStrategy enlargeStrategy; + /// If `true`, the auto play function will be paused when user is interacting with + /// the carousel, and will be resumed when user finish interacting. + /// Default to `true`. + final bool pauseAutoPlayOnTouch; - /// Whether or not to disable the `Center` widget for each slide. - final bool disableCenter; + /// How the carousel should respond to user input. + /// + /// For example, determines how the items continues to animate after the + /// user stops dragging the page view. + /// + /// The physics are modified to snap to page boundaries using + /// [PageScrollPhysics] prior to being used. + /// + /// Defaults to matching platform conventions. + final ScrollPhysics? physics; - /// Use `slideIndicator` to determine which indicator you want to show for each slide. - final SlideIndicator? slideIndicator; + /// Restoration ID to save and restore the scroll offset of the scrollable. + /// + /// Corresponds to Material's PageView's restorationId parameter: https://api.flutter.dev/flutter/widgets/PageView-class.html + final String? restorationId; - /// Whether or not to show the `SlideIndicator` for each slide. - final bool showIndicator; + /// Reverse the order of items if set to true. + /// + /// Defaults to false. + final bool reverse; - /// Whether or not to float `SlideIndicator` over `Carousel`. - final bool floatingIndicator; + ///A ScrollBehavior that will be applied to this widget individually. + // + // Defaults to null, wherein the inherited ScrollBehavior is copied and modified to alter the viewport decoration, like Scrollbars. + // + // ScrollBehaviors also provide ScrollPhysics. If an explicit ScrollPhysics is provided in physics, it will take precedence, followed by scrollBehavior, and then the inherited ancestor ScrollBehavior. + // + // The ScrollBehavior of the inherited ScrollConfiguration will be modified by default to not apply a Scrollbar. + final ScrollBehavior? scrollBehavior; - /// Whether or not to keep pages in PageView - final bool keepPage; + /// The axis along which the page view scrolls. + /// + /// Defaults to [Axis.horizontal]. + final Axis scrollDirection; - /// Whether to add padding to both ends of the list. - /// If this is set to true and [viewportFraction] < 1.0, padding will be - /// added such that the first and last child slivers will be in the center - /// of the viewport when scrolled all the way to the start or end, - /// respectively. - /// If [viewportFraction] >= 1.0, this property has no effect. - /// This property defaults to true and must not be null. - final bool padEnds; + /// Whether or not to show the `SlideIndicator` for each slide. + final bool showIndicator; - CarouselOptions({ - this.height, - this.aspectRatio, - this.viewportFraction = 0.9, - this.initialPage = 0, - this.enableInfiniteScroll = false, - this.reverse = false, - this.autoPlay = false, - this.autoPlayInterval = const Duration(seconds: 5), - this.autoPlayAnimationDuration = const Duration(milliseconds: 300), - this.autoPlayCurve = Curves.easeInCubic, - this.enlargeCenterPage = false, - this.controller, - this.onPageChanged, - this.onScrolled, - this.physics = const BouncingScrollPhysics(), - this.scrollDirection = Axis.horizontal, - this.pauseAutoPlayOnTouch = true, - this.pauseAutoPlayOnManualNavigate = true, - this.pauseAutoPlayInFiniteScroll = false, - this.pageViewKey, - this.keepPage = true, - this.enlargeStrategy = CenterPageEnlargeStrategy.scale, - this.disableCenter = false, - this.showIndicator = true, - this.floatingIndicator = true, - this.slideIndicator = const CircularSlideIndicator(), - this.padEnds = true, - this.clipBehavior = Clip.hardEdge, - this.scrollBehavior, - this.pageSnapping = true, - this.dragStartBehavior = DragStartBehavior.start, - this.allowImplicitScrolling = false, - this.restorationId, - }) : assert(showIndicator == true ? slideIndicator != null : true); + /// Use `slideIndicator` to determine which indicator you want to show for each slide. + final SlideIndicator? slideIndicator; + + /// The fraction of the viewport that each page should occupy. + /// + /// Defaults to 0.8, which means each page fills 80% of the carousel. + final double viewportFraction; /// Copy With Constructor CarouselOptions copyWith({ @@ -235,6 +239,7 @@ class CarouselOptions { SlideIndicator? slideIndicator, bool? showIndicator, bool? floatingIndicator, + double? indicatorMargin, bool? keepPage, bool? padEnds, Clip? clipBehavior, @@ -272,6 +277,7 @@ class CarouselOptions { disableCenter: disableCenter ?? this.disableCenter, showIndicator: showIndicator ?? this.showIndicator, floatingIndicator: floatingIndicator ?? this.floatingIndicator, + indicatorMargin: indicatorMargin ?? this.indicatorMargin, slideIndicator: slideIndicator ?? this.slideIndicator, padEnds: padEnds ?? this.padEnds, clipBehavior: clipBehavior ?? this.clipBehavior, diff --git a/lib/src/helpers/flutter_carousel_state.dart b/lib/src/helpers/flutter_carousel_state.dart index a8b68bf..c72dd66 100644 --- a/lib/src/helpers/flutter_carousel_state.dart +++ b/lib/src/helpers/flutter_carousel_state.dart @@ -3,19 +3,12 @@ import 'package:flutter_carousel_widget/src/enums/carousel_page_changed_reason.d import 'package:flutter_carousel_widget/src/helpers/flutter_carousel_options.dart'; class CarouselState { - /// The [CarouselOptions] to create this state - CarouselOptions options; - - /// [pageController] is created using the properties passed to the constructor - /// and can be used to control the [PageView] it is passed to. - PageController? pageController; - - /// The actual index of the [PageView]. - /// - /// This value can be ignored unless you know the carousel will be scrolled - /// backwards more then 10000 pages. - /// Defaults to 10000 to simulate infinite backwards scrolling. - int realPage = 100000; + CarouselState( + this.options, + this.onResetTimer, + this.onResumeTimer, + this.changeMode, + ); /// The initial index of the [PageView] on [FlutterCarouselWidget] init. /// @@ -34,13 +27,20 @@ class CarouselState { /// Internal use only Function onResumeTimer; + /// The [CarouselOptions] to create this state + CarouselOptions options; + + /// [pageController] is created using the properties passed to the constructor + /// and can be used to control the [PageView] it is passed to. + PageController? pageController; + + /// The actual index of the [PageView]. + /// + /// This value can be ignored unless you know the carousel will be scrolled + /// backwards more then 10000 pages. + /// Defaults to 10000 to simulate infinite backwards scrolling. + int realPage = 100000; + /// The callback to set the Reason Carousel changed Function(CarouselPageChangedReason) changeMode; - - CarouselState( - this.options, - this.onResetTimer, - this.onResumeTimer, - this.changeMode, - ); } diff --git a/lib/src/indicators/circular_slide_indicator.dart b/lib/src/indicators/circular_slide_indicator.dart index 434a951..3ad3db1 100644 --- a/lib/src/indicators/circular_slide_indicator.dart +++ b/lib/src/indicators/circular_slide_indicator.dart @@ -4,15 +4,6 @@ import 'package:flutter/scheduler.dart'; import 'slide_indicator.dart'; class CircularSlideIndicator implements SlideIndicator { - final double itemSpacing; - final double indicatorRadius; - final double indicatorBorderWidth; - final Color? indicatorBorderColor; - final EdgeInsets? padding; - final AlignmentGeometry alignment; - final Color? currentIndicatorColor; - final Color? indicatorBackgroundColor; - const CircularSlideIndicator({ this.itemSpacing = 20, this.indicatorRadius = 6, @@ -24,6 +15,15 @@ class CircularSlideIndicator implements SlideIndicator { this.indicatorBackgroundColor, }); + final AlignmentGeometry alignment; + final Color? currentIndicatorColor; + final Color? indicatorBackgroundColor; + final Color? indicatorBorderColor; + final double indicatorBorderWidth; + final double indicatorRadius; + final double itemSpacing; + final EdgeInsets? padding; + @override Widget build(int currentPage, double pageDelta, int itemCount) { var activeColor = const Color(0xFFFFFFFF); @@ -32,7 +32,7 @@ class CircularSlideIndicator implements SlideIndicator { if (SchedulerBinding.instance.window.platformBrightness == Brightness.light) { activeColor = const Color(0xFF000000); - backgroundColor = const Color(0xFF878484); + backgroundColor = const Color.fromARGB(255, 163, 159, 159); } return Container( @@ -60,15 +60,6 @@ class CircularSlideIndicator implements SlideIndicator { } class CircularIndicatorPainter extends CustomPainter { - final int itemCount; - final double radius; - final Paint indicatorPaint = Paint(); - final Paint currentIndicatorPaint = Paint(); - final int currentPage; - final double pageDelta; - final Paint borderIndicatorPaint = Paint(); - final Color? indicatorBorderColor; - CircularIndicatorPainter({ required this.currentPage, required this.pageDelta, @@ -94,6 +85,15 @@ class CircularIndicatorPainter extends CustomPainter { } } + final Paint borderIndicatorPaint = Paint(); + final Paint currentIndicatorPaint = Paint(); + final int currentPage; + final Color? indicatorBorderColor; + final Paint indicatorPaint = Paint(); + final int itemCount; + final double pageDelta; + final double radius; + @override void paint(Canvas canvas, Size size) { final dx = itemCount < 2 diff --git a/lib/src/indicators/circular_static_indicator.dart b/lib/src/indicators/circular_static_indicator.dart index 350a602..b26c283 100644 --- a/lib/src/indicators/circular_static_indicator.dart +++ b/lib/src/indicators/circular_static_indicator.dart @@ -4,16 +4,6 @@ import 'package:flutter/scheduler.dart'; import 'slide_indicator.dart'; class CircularStaticIndicator extends SlideIndicator { - final double itemSpacing; - final double indicatorRadius; - final EdgeInsets? padding; - final AlignmentGeometry alignment; - final Color? currentIndicatorColor; - final Color? indicatorBackgroundColor; - final bool enableAnimation; - final double indicatorBorderWidth; - final Color? indicatorBorderColor; - CircularStaticIndicator({ this.itemSpacing = 20, this.indicatorRadius = 6, @@ -26,6 +16,16 @@ class CircularStaticIndicator extends SlideIndicator { this.indicatorBorderColor, }); + final AlignmentGeometry alignment; + final Color? currentIndicatorColor; + final bool enableAnimation; + final Color? indicatorBackgroundColor; + final Color? indicatorBorderColor; + final double indicatorBorderWidth; + final double indicatorRadius; + final double itemSpacing; + final EdgeInsets? padding; + @override Widget build(int currentPage, double pageDelta, int itemCount) { var activeColor = const Color(0xFFFFFFFF); @@ -63,17 +63,6 @@ class CircularStaticIndicator extends SlideIndicator { } class CircularStaticIndicatorPainter extends CustomPainter { - final int itemCount; - final double radius; - final Paint indicatorPaint = Paint(); - final Paint currentIndicatorPaint = Paint(); - final int currentPage; - final double pageDelta; - final bool enableAnimation; - - final Paint borderIndicatorPaint = Paint(); - final Color? indicatorBorderColor; - CircularStaticIndicatorPainter({ required this.currentPage, required this.pageDelta, @@ -100,6 +89,16 @@ class CircularStaticIndicatorPainter extends CustomPainter { } } + final Paint borderIndicatorPaint = Paint(); + final Paint currentIndicatorPaint = Paint(); + final int currentPage; + final bool enableAnimation; + final Color? indicatorBorderColor; + final Paint indicatorPaint = Paint(); + final int itemCount; + final double pageDelta; + final double radius; + @override void paint(Canvas canvas, Size size) { final dx = itemCount < 2 diff --git a/lib/src/indicators/circular_wave_slide_indicator.dart b/lib/src/indicators/circular_wave_slide_indicator.dart index 169d598..d71ec9b 100644 --- a/lib/src/indicators/circular_wave_slide_indicator.dart +++ b/lib/src/indicators/circular_wave_slide_indicator.dart @@ -4,15 +4,6 @@ import 'package:flutter/scheduler.dart'; import 'slide_indicator.dart'; class CircularWaveSlideIndicator implements SlideIndicator { - final double itemSpacing; - final double indicatorRadius; - final EdgeInsets? padding; - final AlignmentGeometry alignment; - final Color? currentIndicatorColor; - final Color? indicatorBackgroundColor; - final double indicatorBorderWidth; - final Color? indicatorBorderColor; - CircularWaveSlideIndicator({ this.itemSpacing = 20, this.indicatorRadius = 6, @@ -24,6 +15,15 @@ class CircularWaveSlideIndicator implements SlideIndicator { this.indicatorBorderColor, }); + final AlignmentGeometry alignment; + final Color? currentIndicatorColor; + final Color? indicatorBackgroundColor; + final Color? indicatorBorderColor; + final double indicatorBorderWidth; + final double indicatorRadius; + final double itemSpacing; + final EdgeInsets? padding; + @override Widget build(int currentPage, double pageDelta, int itemCount) { var activeColor = const Color(0xFFFFFFFF); @@ -60,16 +60,6 @@ class CircularWaveSlideIndicator implements SlideIndicator { } class CircularWaveIndicatorPainter extends CustomPainter { - final int? itemCount; - final int? currentPage; - final double? pageDelta; - final double? radius; - final Paint indicatorPaint = Paint(); - final Paint currentIndicatorPaint = Paint(); - - final Paint borderIndicatorPaint = Paint(); - final Color? indicatorBorderColor; - CircularWaveIndicatorPainter({ this.itemCount, this.currentPage, @@ -95,6 +85,15 @@ class CircularWaveIndicatorPainter extends CustomPainter { } } + final Paint borderIndicatorPaint = Paint(); + final Paint currentIndicatorPaint = Paint(); + final int? currentPage; + final Color? indicatorBorderColor; + final Paint indicatorPaint = Paint(); + final int? itemCount; + final double? pageDelta; + final double? radius; + @override void paint(Canvas canvas, Size size) { final dx = itemCount! < 2 diff --git a/lib/src/indicators/sequential_fill_indicator.dart b/lib/src/indicators/sequential_fill_indicator.dart index 0a51b1d..cd37c48 100644 --- a/lib/src/indicators/sequential_fill_indicator.dart +++ b/lib/src/indicators/sequential_fill_indicator.dart @@ -4,16 +4,6 @@ import 'package:flutter/scheduler.dart'; import 'slide_indicator.dart'; class SequentialFillIndicator extends SlideIndicator { - final double itemSpacing; - final double indicatorRadius; - final EdgeInsets? padding; - final AlignmentGeometry alignment; - final Color? currentIndicatorColor; - final Color? indicatorBackgroundColor; - final bool enableAnimation; - final double indicatorBorderWidth; - final Color? indicatorBorderColor; - SequentialFillIndicator({ this.itemSpacing = 20, this.indicatorRadius = 6, @@ -26,6 +16,16 @@ class SequentialFillIndicator extends SlideIndicator { this.indicatorBorderColor, }); + final AlignmentGeometry alignment; + final Color? currentIndicatorColor; + final bool enableAnimation; + final Color? indicatorBackgroundColor; + final Color? indicatorBorderColor; + final double indicatorBorderWidth; + final double indicatorRadius; + final double itemSpacing; + final EdgeInsets? padding; + @override Widget build(int currentPage, double pageDelta, int itemCount) { var activeColor = const Color(0xFFFFFFFF); @@ -63,17 +63,6 @@ class SequentialFillIndicator extends SlideIndicator { } class SequentialFillIndicatorPainter extends CustomPainter { - final int itemCount; - final double radius; - final Paint indicatorPaint = Paint(); - final Paint currentIndicatorPaint = Paint(); - final int currentPage; - final double pageDelta; - final bool enableAnimation; - - final Paint borderIndicatorPaint = Paint(); - final Color? indicatorBorderColor; - SequentialFillIndicatorPainter({ required this.currentPage, required this.pageDelta, @@ -102,6 +91,16 @@ class SequentialFillIndicatorPainter extends CustomPainter { } } + final Paint borderIndicatorPaint = Paint(); + final Paint currentIndicatorPaint = Paint(); + final int currentPage; + final bool enableAnimation; + final Color? indicatorBorderColor; + final Paint indicatorPaint = Paint(); + final int itemCount; + final double pageDelta; + final double radius; + @override void paint(Canvas canvas, Size size) { var currentPage = this.currentPage; diff --git a/pubspec.yaml b/pubspec.yaml index 838d3da..7768aef 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,12 +1,12 @@ name: flutter_carousel_widget description: A customizable carousel slider widget in Flutter which supports inifinte scrolling, auto scrolling, custom child widget, custom animations and built-in indicators. -version: 2.0.1 +version: 2.0.2 homepage: https://github.com/nixrajput repository: https://github.com/nixrajput/flutter_carousel_widget issue_tracker: https://github.com/nixrajput/flutter_carousel_widget/issues environment: - sdk: ">=2.18.0 <3.0.0" + sdk: ">=2.18.0 <4.0.0" flutter: ">=2.0.0" dependencies: @@ -14,9 +14,5 @@ dependencies: sdk: flutter dev_dependencies: - flutter_test: - sdk: flutter - + test: ^1.22.2 flutter_lints: ^2.0.1 - -flutter: