card_shuffler_2 1.0.1 copy "card_shuffler_2: ^1.0.1" to clipboard
card_shuffler_2: ^1.0.1 copied to clipboard

A Dart package for shuffling, dealing, and managing playing card decks. Supports standard 52-card decks, custom decks, multiple shuffle algorithms, and dealing hands.

https://github.com/user-attachments/assets/d9493395-cc1f-44fa-afb5-b82a3bea4aab

card_shuffler #

*Submitted by: Group 6 Members: Haseeb 22k-4307 Murtaza 22k-4508 Saad 22k-4345 Shahmir 22k-4414 *

A pure Dart package for shuffling, dealing, and managing standard playing card decks.


Features #

  • πŸƒ Standard 52-card deck (PlayingCard, Suit, Rank)
  • πŸ”€ Three shuffle algorithms: Fisher-Yates, Riffle, Overhand
  • 🎴 Deal hands to multiple players (round-robin)
  • βœ‚οΈ Cut the deck
  • πŸ”„ Reset to original order
  • 🎲 Deterministic shuffles via seeded Random

UI Showcase #

Shuffle & Cut Tab #

Displays all 52 cards in a grid. Tap Shuffle, Cut, or Reset and watch the deck change in real time.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  πŸƒ Card Shuffler Demo          [Shuffle & Cut] β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Standard 52-card deck. Tap Shuffle or Cut! β”‚
β”‚                                             β”‚
β”‚  [Shuffle]  [Cut]  [Reset]                  β”‚
β”‚                                             β”‚
β”‚  Aβ™   2β™   3β™   4β™   5β™   6β™   7β™                β”‚
β”‚  8β™   9β™   10β™  Jβ™   Qβ™   Kβ™   Aβ™₯               β”‚
β”‚  2β™₯  3β™₯  4β™₯  5β™₯  6β™₯  7β™₯  8β™₯               β”‚
β”‚  ...                                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Deal Hands Tab #

Use sliders to set the number of players (2–8) and cards per hand (1–13), then tap Deal Hands.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Players: 4  ━━━━●━━━━━━━━━━━               β”‚
β”‚  Cards each: 5  ━━━●━━━━━━━━━               β”‚
β”‚                [Deal Hands]                  β”‚
β”‚  32 cards remaining in deck                 β”‚
β”‚  ─────────────────────────                  β”‚
β”‚  Player 1:  Kβ™   7β™₯  A♦  3♣  Jβ™             β”‚
β”‚  Player 2:  5♦  2β™₯  10♣ 8β™   Qβ™₯            β”‚
β”‚  Player 3:  9♣  4♦  6β™   Kβ™₯  2♣            β”‚
β”‚  Player 4:  Aβ™   J♦  3β™₯  7♣  10♦           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Algorithms Tab #

Pick a shuffle algorithm, run it, and see the resulting order for the first 13 cards.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Choose algorithm:                          β”‚
β”‚  β—‹ Fisher-Yates β€” uniform random            β”‚
β”‚  ● Riffle β€” splits & interleaves halves     β”‚
β”‚  β—‹ Overhand β€” cuts small top packets        β”‚
β”‚                 [Run Shuffle]               β”‚
β”‚  Result (first 13 cards):                  β”‚
β”‚  7β™   A♦  Qβ™₯  3♣  10β™   5♦  Kβ™₯ ...         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Getting Started #

Add to your pubspec.yaml:

dependencies:
  card_shuffler: ^0.0.1

Then import:

import 'package:card_shuffler/card_shuffler.dart';

Usage #

Create a standard deck #

final deck = CardDeck.standard();
print(deck.remaining); // 52

Shuffle the deck #

// Default: Fisher-Yates
deck.shuffle();

// Riffle shuffle
deck.shuffle(algorithm: ShuffleAlgorithm.riffle);

// Overhand shuffle
deck.shuffle(algorithm: ShuffleAlgorithm.overhand);

// Deterministic (for tests)
deck.shuffle(random: Random(42));

Deal cards #

// Deal 5 cards to one player
final hand = deck.deal(5);
print(hand); // [Kβ™ , 7β™₯, A♦, 3♣, Jβ™ ]

// Deal one card at a time
final card = deck.dealOne(); // returns null if deck is empty

Deal to multiple players #

final result = HandDealer.deal(
  deck: deck,
  playerCount: 4,
  cardsPerHand: 5,
);

for (int i = 0; i < result.playerCount; i++) {
  print('Player ${i + 1}: ${result.hands[i]}');
}
print('Remaining: ${result.remainingCards.length}');

Cut the deck #

deck.cut();       // cuts at the middle
deck.cut(10);     // cuts at position 10

Peek & reset #

final top = deck.peek(); // see top card without removing it

deck.reset();     // return all cards, restore original order

Custom deck #

final custom = CardDeck.custom([
  PlayingCard(rank: Rank.ace, suit: Suit.spades),
  PlayingCard(rank: Rank.king, suit: Suit.hearts),
]);

PlayingCard model #

const card = PlayingCard(rank: Rank.ace, suit: Suit.spades);
print(card);            // Aβ™ 
print(card.rank.value); // 1
print(card.suit.symbol);// β™ 

API Reference #

PlayingCard #

Property Type Description
rank Rank Card rank (Ace–King)
suit Suit Card suit (β™  β™₯ ♦ ♣)
toString() String e.g. "Aβ™ "

CardDeck #

Method Returns Description
CardDeck.standard() CardDeck New ordered 52-card deck
CardDeck.custom(cards) CardDeck Deck from custom card list
shuffle({algorithm, random}) void Shuffle in place
deal(count) List<PlayingCard> Remove & return top N cards
dealOne() PlayingCard? Remove & return top card
cut([position]) void Cut at position (default: middle)
peek() PlayingCard? Top card without removing
reset() void Restore original 52-card order
remaining int Cards left in deck
isEmpty bool True if deck is empty

ShuffleAlgorithm #

Value Description
fisherYates Uniform random β€” every permutation equally likely
riffle Splits deck and interleaves packets
overhand Repeatedly cuts small packets from top

HandDealer.deal() #

Parameter Type Description
deck CardDeck The deck to deal from
playerCount int Number of players
cardsPerHand int Cards per player

Returns a DealResult with hands (list of player hands) and remainingCards.


Example App #

The example/ folder contains a full Flutter app demonstrating all APIs across three tabs:

  • Shuffle & Cut β€” visual 52-card grid with shuffle/cut/reset buttons
  • Deal Hands β€” configurable multi-player hand dealing
  • Algorithms β€” side-by-side comparison of all three shuffle algorithms

Run the example:

cd example
flutter run

Additional Information #

  • This is a Dart-only package (no plugins, no native code).
  • All operations mutate the deck in place; use reset() to restore.
  • For reproducible results in tests, pass a seeded Random to shuffle().

Submitted by: [Your Group Name] β€” Members: [Member 1], [Member 2], ...
Topic: Card Shuffler

0
likes
150
points
33
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Dart package for shuffling, dealing, and managing playing card decks. Supports standard 52-card decks, custom decks, multiple shuffle algorithms, and dealing hands.

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on card_shuffler_2