Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
kevlatus committed Feb 22, 2021
2 parents e587a59 + a17eb86 commit 85abe8f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.4.0"
version: "0.3.2"
flutter_hooks:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions lib/src/bar/fortune_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ class FortuneBar extends HookWidget implements FortuneWidget {
/// {@macro flutter_fortune_wheel.FortuneWidget.styleStrategy}
final StyleStrategy styleStrategy;

/// {@macro flutter_fortune_wheel.FortuneWidget.physics}
final PanPhysics physics;

/// {@macro flutter_fortune_wheel.FortuneWidget.onFling}
final VoidCallback? onFling;

/// If this value is true, this widget expands to the screen width and ignores
Expand Down
16 changes: 16 additions & 0 deletions lib/src/core/fortune_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,20 @@ abstract class FortuneWidget implements Widget {
/// Defaults to true.
/// {@endtemplate}
bool get animateFirst;

/// {@template flutter_fortune_wheel.FortuneWidget.physics}
/// The behavior used for handling pan events on this widget.
///
/// See also:
/// * [PanPhysics] as the base class for implementing custom behavior
/// * [NoPanPhysics], which disables panning
/// * [DirectionalPanPhysics], which handles one directional panning
/// * [CircularPanPhysics], which handles panning on circular shapes
/// {@endtemplate}
PanPhysics get physics;

/// {@template flutter_fortune_wheel.FortuneWidget.onFling}
/// Called when a fling gesture is detected by the active [physics].
/// {@endtemplate}
VoidCallback? get onFling;
}
13 changes: 13 additions & 0 deletions lib/src/core/pan_detector.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
part of 'core.dart';

/// A class representing the current state of a [PanAwareBuilder].
///
/// See also:
/// * [PanPhysics], a base class for implementing pan behavior
@immutable
class PanState {
/// Is set to true if a user is currently panning on the screen.
final bool isPanning;

/// The distance traveled in pixels since panning started.
final double distance;

/// Is set to true if panning resulted in a fling gesture.
final bool wasFlung;

const PanState({
Expand All @@ -11,6 +21,7 @@ class PanState {
this.wasFlung = false,
});

/// Returns a copy of this [PanState] instance updated with the given values.
PanState copyWith({
bool? isPanning,
double? distance,
Expand Down Expand Up @@ -44,6 +55,8 @@ class PanState {
}
}

/// Base class for handling pan events and translating them to travelled
/// distances.
abstract class PanPhysics extends ValueNotifier<PanState> {
static const Duration kDefaultDuration = Duration(milliseconds: 300);
static const Curve kDefaultCurve = Curves.linear;
Expand Down
2 changes: 2 additions & 0 deletions lib/src/wheel/fortune_wheel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ class FortuneWheel extends HookWidget implements FortuneWidget {
/// {@macro flutter_fortune_wheel.FortuneWidget.animateFirst}
final bool animateFirst;

/// {@macro flutter_fortune_wheel.FortuneWidget.physics}
final PanPhysics physics;

/// {@macro flutter_fortune_wheel.FortuneWidget.onFling}
final VoidCallback? onFling;

double _getAngle(double progress) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: flutter_fortune_wheel
description: Visualize (random) selection processes with widgets like a spinning wheel of fortune or a fortune bar.
repository: https://github.com/kevlatus/flutter_fortune_wheel
version: 0.4.0
version: 0.3.2

environment:
sdk: '>=2.12.0-259.9.beta <3.0.0'
Expand Down

0 comments on commit 85abe8f

Please sign in to comment.