diff --git a/.github/workflows/component-ci.yml b/.github/workflows/component-ci.yml new file mode 100644 index 0000000..ca69d49 --- /dev/null +++ b/.github/workflows/component-ci.yml @@ -0,0 +1,14 @@ +name: Iconica Standard Component CI Workflow +# Workflow Caller version: 2.0.0 + +on: + pull_request: + workflow_dispatch: + +jobs: + call-global-iconica-workflow: + uses: Iconica-Development/.github/.github/workflows/component-ci.yml@master + secrets: inherit + permissions: write-all + with: + subfolder: "." # add optional subfolder to run workflow in diff --git a/.github/workflows/flutter.yml b/.github/workflows/flutter.yml deleted file mode 100644 index 328d54a..0000000 --- a/.github/workflows/flutter.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: CI - -on: - push: - branches: [ master ] - pull_request: - branches: - - master - - feature/* - - bugfix/* - - hotfix/* - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 - with: - path: | - ~/.gradle/wrapper - /opt/hostedtoolcache/flutter - key: ${{ runner.OS }}-flutter-install-cache - - uses: subosito/flutter-action@v2 - with: - channel: 'stable' - - name: Flutter pub get - run: flutter pub get - - name: Flutter format - run: dart format -o none --set-exit-if-changed . - - name: Flutter analyze - run: flutter analyze diff --git a/CHANGELOG.md b/CHANGELOG.md index 3108176..9494f15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.3.1 + +* Added Iconica CI and Iconica Linter + ## 0.3.0 * Added option for backwards infinite scrolling and intial page diff --git a/analysis_options.yaml b/analysis_options.yaml index a3be6b8..e2b30bf 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1 +1,9 @@ -include: package:flutter_lints/flutter.yaml \ No newline at end of file +include: package:flutter_iconica_analysis/analysis_options.yaml + +# Possible to overwrite the rules from the package + +analyzer: + exclude: + +linter: + rules: \ No newline at end of file diff --git a/lib/carousel.dart b/lib/carousel.dart index 7545a52..055a4f7 100644 --- a/lib/carousel.dart +++ b/lib/carousel.dart @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Iconica // // SPDX-License-Identifier: BSD-3-Clause - +/// A Flutter package for creating a carousel widget. library carousel; export 'package:carousel/src/carousel.dart'; diff --git a/lib/src/carousel.dart b/lib/src/carousel.dart index cd08f97..a448ca2 100644 --- a/lib/src/carousel.dart +++ b/lib/src/carousel.dart @@ -11,7 +11,8 @@ typedef CarouselCardBuilder = Widget Function(BuildContext context, int index); class Carousel extends StatefulWidget { /// Animated cards by swiping. - /// Each card can change its rotation, position and scale when swiping the cards. + /// Each card can change its rotation, position + /// and scale when swiping the cards. /// Transform path can be privided using [transforms] const Carousel({ required this.transforms, @@ -23,8 +24,8 @@ class Carousel extends StatefulWidget { this.onCardClick, this.initialPage = 0, this.allowInfiniteScrollingBackwards = false, - Key? key, - }) : super(key: key); + super.key, + }); /// A list of transforms to calculate the position of the card when swiping. /// Every item in the list is one of the possible card positions. @@ -33,7 +34,8 @@ class Carousel extends StatefulWidget { /// The index of the transform card which acts as the selected card. final int selectableCardId; - /// Builder for the card given a [context] and a [index] to identify the right card. + /// Builder for the card given a [context] and a [index] to + /// identify the right card. final CarouselCardBuilder builder; /// Called when selected card is changed to the next one. @@ -51,7 +53,9 @@ class Carousel extends StatefulWidget { /// The page to show when first creating the [Carousel]. final int initialPage; - /// Whether to allow infinite scrolling backwards. Defaults to false. If true, this works by using a very large number of pages (10000). Works in conjunction with [initialPage]. + /// Whether to allow infinite scrolling backwards. Defaults to false. If true, + /// this works by using a very large number of pages (10000). + /// Works in conjunction with [initialPage]. final bool allowInfiniteScrollingBackwards; @override @@ -84,38 +88,36 @@ class _CarouselState extends State { } @override - Widget build(BuildContext context) { - return Stack( - alignment: widget.alignment, - children: [ - AnimatedBuilder( - animation: _pageController, - builder: (context, _) { - final transitionPos = _currentPage % 1; - final index = _currentPage.floor(); - final length = widget.transforms.length - 1; + Widget build(BuildContext context) => Stack( + alignment: widget.alignment, + children: [ + AnimatedBuilder( + animation: _pageController, + builder: (context, _) { + var transitionPos = _currentPage % 1; + var index = _currentPage.floor(); + var length = widget.transforms.length - 1; - return Stack( - children: [ - for (var i = 0; i < length; i++) ...[ - CarouselCard( - cardTransform: widget.transforms[i] - .transform(widget.transforms[i + 1], transitionPos), - child: widget.builder.call(context, index - i), - ), + return Stack( + children: [ + for (var i = 0; i < length; i++) ...[ + CarouselCard( + cardTransform: widget.transforms[i] + .transform(widget.transforms[i + 1], transitionPos), + child: widget.builder.call(context, index - i), + ), + ], ], - ], - ); - }, - ), - SizedBox( - height: widget.pageViewHeight, - child: PageView.builder( - scrollBehavior: _MouseSwipeOnWeb(), - onPageChanged: widget.onPageChanged, - controller: _pageController, - itemBuilder: (context, index) { - return Visibility( + ); + }, + ), + SizedBox( + height: widget.pageViewHeight, + child: PageView.builder( + scrollBehavior: _MouseSwipeOnWeb(), + onPageChanged: widget.onPageChanged, + controller: _pageController, + itemBuilder: (context, index) => Visibility( visible: false, maintainState: true, maintainAnimation: true, @@ -135,13 +137,11 @@ class _CarouselState extends State { ), ], ), - ); - }, + ), + ), ), - ), - ], - ); - } + ], + ); } class _MouseSwipeOnWeb extends MaterialScrollBehavior { diff --git a/lib/src/models/card_transform.dart b/lib/src/models/card_transform.dart index 94bdce8..2d0d591 100644 --- a/lib/src/models/card_transform.dart +++ b/lib/src/models/card_transform.dart @@ -28,15 +28,14 @@ class CardTransform { /// [transitionPos] is a position value of a swipe for example. /// [other] is the position, scale, rotation /// which the current [CardTransform] need to be transformed to. - CardTransform transform(CardTransform other, double transitionPos) { - return CardTransform( - x: _transformValue(x, other.x, transitionPos), - y: _transformValue(y, other.y, transitionPos), - angle: _transformValue(angle, other.angle, transitionPos), - scale: _transformValue(scale, other.scale, transitionPos), - opacity: _transformValue(opacity, other.opacity, transitionPos), - ); - } + CardTransform transform(CardTransform other, double transitionPos) => + CardTransform( + x: _transformValue(x, other.x, transitionPos), + y: _transformValue(y, other.y, transitionPos), + angle: _transformValue(angle, other.angle, transitionPos), + scale: _transformValue(scale, other.scale, transitionPos), + opacity: _transformValue(opacity, other.opacity, transitionPos), + ); double _transformValue(double valueA, double valueB, double transformPos) => valueA - ((valueA - valueB) * transformPos); diff --git a/lib/src/widgets/carousel_card.dart b/lib/src/widgets/carousel_card.dart index 2efc32f..34672f0 100644 --- a/lib/src/widgets/carousel_card.dart +++ b/lib/src/widgets/carousel_card.dart @@ -10,26 +10,24 @@ class CarouselCard extends StatelessWidget { const CarouselCard({ required this.cardTransform, required this.child, - Key? key, - }) : super(key: key); + super.key, + }); final CardTransform cardTransform; final Widget child; @override - Widget build(BuildContext context) { - return Transform.translate( - offset: Offset(cardTransform.x, cardTransform.y), - child: Transform.rotate( - angle: cardTransform.angle, - child: Transform.scale( - scale: cardTransform.scale, - child: Opacity( - opacity: cardTransform.opacity, - child: child, + Widget build(BuildContext context) => Transform.translate( + offset: Offset(cardTransform.x, cardTransform.y), + child: Transform.rotate( + angle: cardTransform.angle, + child: Transform.scale( + scale: cardTransform.scale, + child: Opacity( + opacity: cardTransform.opacity, + child: child, + ), ), ), - ), - ); - } + ); } diff --git a/pubspec.yaml b/pubspec.yaml index f0177f6..5d1c500 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: carousel description: card carousel -version: 0.3.0 +version: 0.3.1 environment: sdk: ">=2.17.6 <3.0.0" @@ -13,41 +13,9 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^2.0.0 + flutter_iconica_analysis: + git: + url: https://github.com/Iconica-Development/flutter_iconica_analysis + ref: 6.0.0 -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter packages. flutter: - - # To add assets to your package, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - # - # For details regarding assets in packages, see - # https://flutter.dev/assets-and-images/#from-packages - # - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware - - # To add custom fonts to your package, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts in packages, see - # https://flutter.dev/custom-fonts/#from-packages