### CHANGELOG Entry Format Example Source: https://github.com/ricardodalarme/flutter_card_swiper/blob/main/CONTRIBUTING.md Demonstrates the standard format for entries in the CHANGELOG.md file, including version headers, itemization, and the declaration of breaking changes. This format ensures consistency and clarity for all package updates. ```markdown ## NEXT * Description of the change. ## 1.0.2 ... ``` ```markdown ## 2.0.0 - Adds the ability to fetch data from the future. - **BREAKING CHANGES**: - Removes the deprecated `neverCallThis` method. - URLs parameters are now `Uri`s rather than `String`s. ## 1.0.3 - Fixes a crash when the device teleports during a network operation. ``` ```markdown ## NEXT * Description of your new change. * Existing entry. ## 1.0.2 ... ``` ```markdown ## 1.0.3 * Description of your new change. * Existing entry. ## 1.0.2 ... ``` -------------------------------- ### Basic CardSwiper Widget Example in Flutter Source: https://github.com/ricardodalarme/flutter_card_swiper/blob/main/README.md This Dart code demonstrates a basic implementation of the CardSwiper widget in a Flutter application. It displays a list of cards that can be swiped in various directions, utilizing the CardSwiper's core functionality. ```dart import 'package:flutter_card_swiper/flutter_card_swiper.dart'; import 'package:flutter/material.dart'; class Example extends StatelessWidget { List cards = [ Container( alignment: Alignment.center, child: const Text('1'), color: Colors.blue, ), Container( alignment: Alignment.center, child: const Text('2'), color: Colors.red, ), Container( alignment: Alignment.center, child: const Text('3'), color: Colors.purple, ) ]; @override Widget build(BuildContext context) { return Scaffold( body: Flexible( child: CardSwiper( cardsCount: cards.length, cardBuilder: (context, index, percentThresholdX, percentThresholdY) => cards[index], ), ), ); } } ``` -------------------------------- ### Restrict Swipe Directions in Flutter Card Swiper Source: https://context7.com/ricardodalarme/flutter_card_swiper/llms.txt This example demonstrates how to limit the allowed swipe directions for the card swiper component. It showcases two scenarios: allowing only horizontal swipes and allowing only left and up swipes. Dependencies include flutter/material.dart and flutter_card_swiper/flutter_card_swiper.dart. ```dart import 'package:flutter/material.dart'; import 'package:flutter_card_swiper/flutter_card_swiper.dart'; class RestrictedSwipeExample extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Restricted Swipe Directions')), body: Column( children: [ // Only horizontal swipes allowed Expanded( child: CardSwiper( cardsCount: 5, allowedSwipeDirection: const AllowedSwipeDirection.symmetric( horizontal: true, vertical: false, ), cardBuilder: (context, index, h, v) => Card( child: Center(child: Text('Horizontal Only\nCard ${index + 1}')), ), ), ), // Only left and up swipes allowed Expanded( child: CardSwiper( cardsCount: 5, allowedSwipeDirection: const AllowedSwipeDirection.only( left: true, up: true, right: false, down: false, ), cardBuilder: (context, index, h, v) => Card( color: Colors.orange[200], child: Center(child: Text('Left & Up Only\nCard ${index + 1}')), ), ), ), ], ), ); } } ``` -------------------------------- ### Define Custom Swipe Directions with Angles in Dart Source: https://context7.com/ricardodalarme/flutter_card_swiper/llms.txt This Dart code defines a custom swipe direction for the flutter_card_swiper package. It utilizes angles to specify directions and provides methods to check if a direction is horizontal, vertical, or close to a predefined direction within a tolerance. The example includes a CardSwiper widget and buttons to trigger different swipe directions. ```dart import 'package:flutter/material.dart'; import 'package:flutter_card_swiper/flutter_card_swiper.dart'; class CustomDirectionExample extends StatefulWidget { @override State createState() => _CustomDirectionExampleState(); } class _CustomDirectionExampleState extends State { final CardSwiperController controller = CardSwiperController(); bool _onSwipe(int previousIndex, int? currentIndex, CardSwiperDirection direction) { print('Direction: ${direction.name} at ${direction.angle}°'); print('Is horizontal: ${direction.isHorizontal}'); print('Is vertical: ${direction.isVertical}'); if (direction.isCloseTo(CardSwiperDirection.right, tolerance: 10)) { print('Roughly swiped right'); } return true; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Custom Directions')), body: Column( children: [ Flexible( child: CardSwiper( controller: controller, cardsCount: 10, onSwipe: _onSwipe, cardBuilder: (context, index, h, v) => Card( child: Center(child: Text('Card ${index + 1}')), ), ), ), Padding( padding: const EdgeInsets.all(16.0), child: Wrap( spacing: 8, runSpacing: 8, children: [ ElevatedButton( onPressed: () => controller.swipe(CardSwiperDirection.top), child: const Text('Top (0°)'), ), ElevatedButton( onPressed: () => controller.swipe(CardSwiperDirection.custom(45, name: 'top-right')), child: const Text('Top-Right (45°)'), ), ElevatedButton( onPressed: () => controller.swipe(CardSwiperDirection.right), child: const Text('Right (90°)'), ), ElevatedButton( onPressed: () => controller.swipe(CardSwiperDirection.custom(135)), child: const Text('Bottom-Right (135°)'), ), ElevatedButton( onPressed: () => controller.swipe(CardSwiperDirection.bottom), child: const Text('Bottom (180°)'), ), ElevatedButton( onPressed: () => controller.swipe(CardSwiperDirection.left), child: const Text('Left (270°)'), ), ], ), ), ], ), ); } @override void dispose() { controller.dispose(); super.dispose(); } } ``` -------------------------------- ### Card Swiper Widget Configuration Source: https://github.com/ricardodalarme/flutter_card_swiper/blob/main/README.md Configuration options for the Card Swiper widget, including how cards are built, the number of cards, and swipe control. ```APIDOC ## Card Swiper Widget ### Description This section details the parameters used to configure the Card Swiper widget, enabling customization of card appearance, quantity, and swipe behavior. ### Method Widget Configuration ### Endpoint N/A (Widget Configuration) ### Parameters #### Widget Properties - **cardBuilder** (WidgetBuilder) - Required - A function that builds the widget for each card. - **cardsCount** (int) - Required - The total number of cards to display. - **controller** (CardSwiperController) - Optional - A controller to programmatically trigger swipe actions. - **duration** (Duration) - Optional - The duration for animations, defaults to 200 milliseconds. - **initialIndex** (int) - Optional - The index of the first card to display, defaults to 0. - **isDisabled** (bool) - Optional - If true, disables swipe gestures on the cards, defaults to false. - **isLoop** (bool) - Optional - If true, enables looping of cards, defaults to true. - **maxAngle** (double) - Optional - The maximum angle a card can reach during a swipe, defaults to 30. - **allowedSwipeDirection** (AllowedSwipeDirection) - Optional - Specifies the allowed swipe directions (left, right, up, down), defaults to `AllowedSwipeDirection.all`. - **numberOfCardsDisplayed** (int) - Optional - The number of cards visible at the same time, defaults to 2. - **onEnd** (VoidCallback) - Optional - A callback function executed when all cards have been swiped. ### Request Example ```dart CardSwiper( cardsCount: 10, cardBuilder: (context, index) => MyCardWidget(index: index), // Other optional parameters... ) ``` ### Response #### Widget Rendering - **Widget** - The configured Card Swiper widget instance. #### Response Example ```dart // No direct response, the widget is rendered in the UI. ``` ``` -------------------------------- ### Card Swiper Properties Source: https://github.com/ricardodalarme/flutter_card_swiper/blob/main/README.md Configuration options for the Card Swiper widget, controlling its appearance and behavior. ```APIDOC ## Card Swiper Widget Properties ### Description These properties allow customization of the card swiper's behavior and appearance. ### Properties - **onSwipe** (Function) - Callback when the user swipes a card. Returning `false` cancels the swipe; `true` performs it. - **onTapDisabled** (Function) - Callback when a card is tapped and `isDisabled` is `true`. - **onUndo** (Function) - Callback when the controller calls undo. Returning `false` cancels the undo; `true` performs it. - **padding** (EdgeInsets) - The padding around the swiper. Default is `EdgeInsets.symmetric(horizontal: 20, vertical: 25)`. - **scale** (double) - Scale of the card behind the front card. Default is `0.9`. - **threshold** (double) - Threshold from which the card is swiped away. Default is `50`. - **onSwipeDirectionChange** (Function) - A callback containing the horizontal and vertical swipe direction. - **showBackCardOnUndo** (bool) - If true, the previous card will be shown in the background when swiping, and the swipe action will trigger an undo. Default is `false`. - **undoSwipeThreshold** (double) - The horizontal swipe distance threshold, in pixels, after which the back card switches to the previous card. Only active when `showBackCardOnUndo` is true. Default is `50`. - **undoDirection** (UndoDirection) - The direction of the swipe to trigger an undo. Default is `UndoDirection.left`. ``` -------------------------------- ### Card Swiper Controller Source: https://github.com/ricardodalarme/flutter_card_swiper/blob/main/README.md Methods to programmatically control the Card Swiper widget, such as swiping, undoing, or moving to a specific card. ```APIDOC ## Card Swiper Controller ### Description The `CardSwiperController` allows external control over the swiper's actions like swiping cards, undoing the last swipe, or moving to a specific card index. ### Methods - **swipe** (Direction) - Swipes the card to a specific direction. - **undo** () - Brings back the last card that was swiped away. - **moveTo** (int index) - Changes the top card to the card at the specified index. ``` -------------------------------- ### CardSwiperController for Programmatic Card Control in Dart Source: https://context7.com/ricardodalarme/flutter_card_swiper/llms.txt Illustrates how to use the CardSwiperController to programmatically manage card swiping actions. This includes enabling undo, swiping in specific directions (left/right), and resetting the card stack. ```dart import 'package:flutter/material.dart'; import 'package:flutter_card_swiper/flutter_card_swiper.dart'; class ControlledCardSwiperExample extends StatefulWidget { @override State createState() => _ControlledCardSwiperExampleState(); } class _ControlledCardSwiperExampleState extends State { final CardSwiperController controller = CardSwiperController(); final List items = List.generate(10, (index) => 'Item ${index + 1}'); @override void dispose() { controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Controlled Swiper')), body: Column( children: [ Flexible( child: CardSwiper( controller: controller, cardsCount: items.length, cardBuilder: (context, index, hPercent, vPercent) { return Card( child: Center( child: Text( items[index], style: const TextStyle(fontSize: 32), ), ), ); }, ), ), Padding( padding: const EdgeInsets.all(16.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ ElevatedButton.icon( onPressed: controller.undo, icon: const Icon(Icons.undo), label: const Text('Undo'), ), ElevatedButton.icon( onPressed: () => controller.swipe(CardSwiperDirection.left), icon: const Icon(Icons.arrow_back), label: const Text('Reject'), ), ElevatedButton.icon( onPressed: () => controller.swipe(CardSwiperDirection.right), icon: const Icon(Icons.arrow_forward), label: const Text('Accept'), ), ElevatedButton.icon( onPressed: () => controller.moveTo(0), icon: const Icon(Icons.refresh), label: const Text('Reset'), ), ], ), ), ], ), ); } } ``` -------------------------------- ### Add flutter_card_swiper Dependency to pubspec.yaml Source: https://github.com/ricardodalarme/flutter_card_swiper/blob/main/README.md This snippet shows how to add the flutter_card_swiper package as a dependency in your Flutter project's pubspec.yaml file. You can either add the dependency manually or use the flutter pub add command. ```yaml card_swiper: ... ``` -------------------------------- ### Handle Swipe Events with Callbacks in Flutter Source: https://context7.com/ricardodalarme/flutter_card_swiper/llms.txt This snippet shows how to use onSwipe and onEnd callbacks to react to user swipe gestures. It manages lists of liked and disliked items and displays a summary when all cards are swiped. Dependencies include flutter/material.dart and flutter_card_swiper/flutter_card_swiper.dart. ```dart import 'package:flutter/material.dart'; import 'package:flutter_card_swiper/flutter_card_swiper.dart'; class CallbackExample extends StatefulWidget { @override State createState() => _CallbackExampleState(); } class _CallbackExampleState extends State { final List likedItems = []; final List dislikedItems = []; int currentIndex = 0; bool _onSwipe(int previousIndex, int? currentIndex, CardSwiperDirection direction) { final item = 'Item ${previousIndex + 1}'; if (direction == CardSwiperDirection.right) { setState(() => likedItems.add(item)); print('✓ Liked: $item'); } else if (direction == CardSwiperDirection.left) { setState(() => dislikedItems.add(item)); print('✗ Disliked: $item'); } else if (direction == CardSwiperDirection.top) { print('↑ Super liked: $item'); } else if (direction == CardSwiperDirection.bottom) { print('↓ Skipped: $item'); } setState(() => this.currentIndex = currentIndex ?? 0); // Return true to allow swipe, false to cancel return true; } void _onEnd() { print('All cards swiped!'); showDialog( context: context, builder: (context) => AlertDialog( title: const Text('Finished!'), content: Text('Liked: ${likedItems.length}, Disliked: ${dislikedItems.length}'), actions: [ TextButton( onPressed: () => Navigator.pop(context), child: const Text('OK'), ), ], ), ); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Swipe Callbacks'), actions: [ Center( child: Padding( padding: const EdgeInsets.all(8.0), child: Text('Liked: ${likedItems.length} | Disliked: ${dislikedItems.length}'), ), ), ], ), body: CardSwiper( cardsCount: 20, onSwipe: _onSwipe, onEnd: _onEnd, cardBuilder: (context, index, hPercent, vPercent) { return Container( decoration: BoxDecoration( gradient: LinearGradient( colors: [Colors.blue[300]!, Colors.purple[300]!], ), borderRadius: BorderRadius.circular(16), ), child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'Card ${index + 1}', style: const TextStyle(fontSize: 48, color: Colors.white), ), const SizedBox(height: 20), Text( 'Swipe offset: H: $hPercent%, V: $vPercent%', style: const TextStyle(fontSize: 16, color: Colors.white70), ), ], ), ), ); }, ), ); } } ``` -------------------------------- ### Implement Undo Swipes with Back Card Preview (Dart) Source: https://context7.com/ricardodalarme/flutter_card_swiper/llms.txt This Dart code snippet demonstrates how to implement undo swipe functionality for the `flutter_card_swiper` widget. It utilizes `CardSwiperController` to manage swipes and undo actions, and the `onUndo` callback to handle the visual back card preview. The `history` list tracks swipe actions for display. ```dart import 'package:flutter/material.dart'; import 'package:flutter_card_swiper/flutter_card_swiper.dart'; class UndoExample extends StatefulWidget { @override State createState() => _UndoExampleState(); } class _UndoExampleState extends State { final CardSwiperController controller = CardSwiperController(); final List history = []; bool _onUndo(int? previousIndex, int currentIndex, CardSwiperDirection direction) { final item = history.isNotEmpty ? history.removeLast() : null; print('Undo: Bringing back card $currentIndex (was swiped ${direction.name})'); if (item != null) { ScaffoldMessenger.of(context).showSnackBar( SnackBar(content: Text('Undone: $item'), duration: const Duration(seconds: 1)), ); } // Return true to allow undo, false to cancel return true; } bool _onSwipe(int previousIndex, int? currentIndex, CardSwiperDirection direction) { history.add('Card ${previousIndex + 1} swiped ${direction.name}'); return true; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Undo Feature'), actions: [ IconButton( icon: const Icon(Icons.undo), onPressed: controller.undo, tooltip: 'Undo last swipe', ), ], ), body: Column( children: [ Flexible( child: CardSwiper( controller: controller, cardsCount: 15, onSwipe: _onSwipe, onUndo: _onUndo, showBackCardOnUndo: true, undoDirection: UndoDirection.left, undoSwipeThreshold: 50.0, cardBuilder: (context, index, h, v) { return Container( decoration: BoxDecoration( color: Colors.primaries[index % Colors.primaries.length], borderRadius: BorderRadius.circular(20), ), child: Center( child: Text( 'Card ${index + 1}', style: const TextStyle(fontSize: 36, color: Colors.white), ), ), ); }, ), ), Container( padding: const EdgeInsets.all(16), child: Column( children: [ const Text('History:', style: TextStyle(fontWeight: FontWeight.bold)), const SizedBox(height: 8), Text( history.isEmpty ? 'No swipes yet' : history.reversed.take(3).join('\n'), textAlign: TextAlign.center, ), ], ), ), ], ), ); } @override void dispose() { controller.dispose(); super.dispose(); } } ``` -------------------------------- ### Configure Card Swiper Animation and Appearance (Dart) Source: https://context7.com/ricardodalarme/flutter_card_swiper/llms.txt This Dart code snippet showcases how to configure the CardSwiper widget for advanced customization. It allows adjustment of animation speed, card angles, swipe thresholds, scaling, and visual styling through interactive sliders. Dependencies include 'flutter/material.dart' and 'flutter_card_swiper/flutter_card_swiper.dart'. ```dart import 'package:flutter/material.dart'; import 'package:flutter_card_swiper/flutter_card_swiper.dart'; class AdvancedCustomizationExample extends StatefulWidget { @override State createState() => _AdvancedCustomizationExampleState(); } class _AdvancedCustomizationExampleState extends State { double maxAngle = 30; int threshold = 50; double scale = 0.9; int durationMs = 200; void _onSwipeDirectionChange( CardSwiperDirection horizontalDirection, CardSwiperSwiperDirection verticalDirection, ) { print('Swipe direction changed - H: ${horizontalDirection.name}, V: ${verticalDirection.name}'); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Advanced Customization')), body: Column( children: [ Flexible( child: CardSwiper( cardsCount: 10, duration: Duration(milliseconds: durationMs), maxAngle: maxAngle, threshold: threshold, scale: scale, backCardOffset: const Offset(0, 40), padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 25), numberOfCardsDisplayed: 3, onSwipeDirectionChange: _onSwipeDirectionChange, cardBuilder: (context, index, h, v) { return Container( decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [ Colors.blue[300 + (index * 10) % 400]!, Colors.purple[300 + (index * 10) % 400]!, ], ), borderRadius: BorderRadius.circular(20), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.3), blurRadius: 10, offset: const Offset(0, 5), ), ], ), child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text( 'Card ${index + 1}', style: const TextStyle( fontSize: 48, color: Colors.white, fontWeight: FontWeight.bold, ), ), const SizedBox(height: 20), Text( 'Angle: ${maxAngle.toStringAsFixed(0)}°\nThreshold: $threshold%\nScale: ${scale.toStringAsFixed(2)}', textAlign: TextAlign.center, style: const TextStyle(color: Colors.white70), ), ], ), ), ); }, ), ), Container( padding: const EdgeInsets.all(16), child: Column( children: [ _buildSlider('Max Angle', maxAngle, 0, 60, (v) => setState(() => maxAngle = v)), _buildSlider('Threshold', threshold.toDouble(), 1, 100, (v) => setState(() => threshold = v.toInt())), _buildSlider('Scale', scale, 0.5, 1.0, (v) => setState(() => scale = v)), _buildSlider('Duration (ms)', durationMs.toDouble(), 100, 1000, (v) => setState(() => durationMs = v.toInt())), ], ), ), ], ), ); } Widget _buildSlider(String label, double value, double min, double max, ValueChanged onChanged) { return Row( children: [ SizedBox(width: 100, child: Text(label)), Expanded( child: Slider( value: value, min: min, max: max, onChanged: onChanged, ), ), SizedBox(width: 50, child: Text(value.toStringAsFixed(value < 10 ? 1 : 0))), ], ); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.