Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added autoFlipDuration parameter #64

Merged
merged 5 commits into from Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -84,3 +84,19 @@ void doStuff() {
_controller.toggleCard();
}
```

You can auto-flip the widget after a certain delay without any external triggering.
```dart
FlipCard(
fill: Fill.fillBack, // Fill the back side of the card to make in the same size as the front.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably combine all of these into

(
  ...,
  autoFlipDuration ...
)

direction: FlipDirection.HORIZONTAL, // default
side: CardSide.FRONT, // The side to initially display.
front: Container(
child: Text('Front'),
),
back: Container(
child: Text('Back'),
),
autoFlipDuration: const Duration(seconds: 2), // The flip effect will work automatically after the 2 seconds
);
```
8 changes: 8 additions & 0 deletions lib/flip_card.dart
Expand Up @@ -61,6 +61,9 @@ class FlipCard extends StatefulWidget {
final Fill fill;
final CardSide side;

/// If the value is set, the flip effect will work automatically after the specified duration.
final Duration? autoFlipDuration;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please documentation for this feature, ideally as a /// comment above the autoFlipDuration, but also in the readme

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added to documentation.

ciriousjoker marked this conversation as resolved.
Show resolved Hide resolved

/// When enabled, the card will flip automatically when touched. This behavior
/// can be disabled if this is not desired. To manually flip a card from your
/// code, you could do this:
Expand Down Expand Up @@ -101,6 +104,7 @@ class FlipCard extends StatefulWidget {
this.alignment = Alignment.center,
this.fill = Fill.none,
this.side = CardSide.FRONT,
this.autoFlipDuration,
}) : super(key: key);

@override
Expand Down Expand Up @@ -155,6 +159,10 @@ class FlipCardState extends State<FlipCard>
).animate(controller!);

widget.controller?.state = this;

if (widget.autoFlipDuration != null) {
Future.delayed(widget.autoFlipDuration!, toggleCard);
}
}

@override
Expand Down