Skip to content

Refactor to remove flutter_hooks dependency#135

Merged
kevlatus merged 3 commits into
mainfrom
refactor/remove-flutter-hooks-5516356372207270902
Jan 10, 2026
Merged

Refactor to remove flutter_hooks dependency#135
kevlatus merged 3 commits into
mainfrom
refactor/remove-flutter-hooks-5516356372207270902

Conversation

@google-labs-jules
Copy link
Copy Markdown
Contributor

This PR removes the flutter_hooks dependency from the package. It refactors FortuneBar, FortuneWheel, and PanAwareBuilder to use StatefulWidget and standard state management. A new helper class FortuneAnimationManager was created in lib/src/core/animations.dart to encapsulate the fortune animation logic previously handled by useFortuneAnimation hook.

Key changes:

  • lib/src/core/animations.dart: Replaced useFortuneAnimation with FortuneAnimationManager.
  • lib/src/core/pan_detector.dart: Converted PanAwareBuilder to StatefulWidget.
  • lib/src/bar/fortune_bar.dart: Converted FortuneBar to StatefulWidget.
  • lib/src/wheel/fortune_wheel.dart: Converted FortuneWheel to StatefulWidget.
  • Removed flutter_hooks imports and dependency.

PR created automatically by Jules for task 5516356372207270902 started by @kevlatus

Replaced `flutter_hooks` usage with standard `StatefulWidget` implementations in `FortuneBar`, `FortuneWheel`, and `PanAwareBuilder`.
Introduced `FortuneAnimationManager` to handle shared animation logic.
Removed `flutter_hooks` from `pubspec.yaml` and imports.
@google-labs-jules
Copy link
Copy Markdown
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@kevlatus
Copy link
Copy Markdown
Owner

kevlatus commented Jan 9, 2026

Tests are failing

@google-labs-jules
Copy link
Copy Markdown
Contributor Author

Tests are failing

I've refactored the widgets to improve testability and stability. FortuneBar and FortuneWheel now use addPostFrameCallback for animateFirst to better simulate useEffect behavior from the hooks implementation. Additionally, I've updated FortuneAnimationManager to allow updating properties (duration, curve, selected) without disposing the underlying animation controller, which prevents animation resets during rebuilds.

- Updated `FortuneAnimationManager` to support property updates (duration, curve, selected stream) without recreating the controller.
- Moved `animateFirst` logic to `addPostFrameCallback` in `FortuneBar` and `FortuneWheel` to ensure proper timing (matching `useEffect`).
- Fixed callback handling to avoid unnecessary re-subscriptions.
@kevlatus
Copy link
Copy Markdown
Owner

kevlatus commented Jan 9, 2026

lib/src/core/animations.dart:23:3: Error: Type 'StreamSubscription' not found.
StreamSubscription? _subscription;
^^^^^^^^^^^^^^^^^^
lib/src/core/animations.dart:23:3: Error: 'StreamSubscription' isn't a type.
StreamSubscription? _subscription;
^^^^^^^^^^^^^^^^^^
lib/src/wheel/fortune_wheel.dart:7:23: Error: Method not found: 'getSmallerSide'.
final smallerSide = getSmallerSide(constraints);
^^^^^^^^^^^^^^
lib/src/wheel/fortune_wheel.dart:61:35: Error: The method 'getSmallerSide' isn't defined for the type '_WheelData'.

  • '_WheelData' is from 'package:flutter_fortune_wheel/src/wheel/wheel.dart' ('lib/src/wheel/wheel.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'getSmallerSide'.
    late final double smallerSide = getSmallerSide(constraints);
    ^^^^^^^^^^^^^^
    lib/src/wheel/fortune_wheel.dart:62:34: Error: The method 'getLargerSide' isn't defined for the type '_WheelData'.
  • '_WheelData' is from 'package:flutter_fortune_wheel/src/wheel/wheel.dart' ('lib/src/wheel/wheel.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'getLargerSide'.
    late final double largerSide = getLargerSide(constraints);
    ^^^^^^^^^^^^^
    lib/src/wheel/slice_layout_delegate.dart:33:45: Error: The method 'rotate' isn't defined for the type 'Point'.
  • 'Point' is from 'dart:math'.
    Try correcting the name to the name of an existing method, or defining a method named 'rotate'.
    final halfAngleVector = topRectVector.rotate(angle / 2);
    ^^^^^^
    lib/src/wheel/wheel_indicator.dart:62:25: Error: The method 'getCenteredMargins' isn't defined for the type '_WheelIndicator'.
  • '_WheelIndicator' is from 'package:flutter_fortune_wheel/src/wheel/wheel.dart' ('lib/src/wheel/wheel.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'getCenteredMargins'.
    final margins = getCenteredMargins(constraints);
    ^^^^^^^^^^^^^^^^^^
    ❌ loading /home/runner/work/flutter_fortune_wheel/flutter_fortune_wheel/test/triangle_indicator_test.dart (failed)
    ❌ loading /home/runner/work/flutter_fortune_wheel/flutter_fortune_wheel/test/triangle_indicator_test.dart (failed after test completion)
    lib/src/core/animations.dart:23:3: Error: Type 'StreamSubscription' not found.
    StreamSubscription? _subscription;
    ^^^^^^^^^^^^^^^^^^
    lib/src/core/animations.dart:23:3: Error: 'StreamSubscription' isn't a type.
    StreamSubscription? _subscription;
    ^^^^^^^^^^^^^^^^^^
    lib/src/wheel/fortune_wheel.dart:7:23: Error: Method not found: 'getSmallerSide'.
    final smallerSide = getSmallerSide(constraints);
    ^^^^^^^^^^^^^^
    lib/src/wheel/fortune_wheel.dart:61:35: Error: The method 'getSmallerSide' isn't defined for the type '_WheelData'.
  • '_WheelData' is from 'package:flutter_fortune_wheel/src/wheel/wheel.dart' ('lib/src/wheel/wheel.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'getSmallerSide'.
    late final double smallerSide = getSmallerSide(constraints);
    ^^^^^^^^^^^^^^
    lib/src/wheel/fortune_wheel.dart:62:34: Error: The method 'getLargerSide' isn't defined for the type '_WheelData'.
  • '_WheelData' is from 'package:flutter_fortune_wheel/src/wheel/wheel.dart' ('lib/src/wheel/wheel.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'getLargerSide'.
    late final double largerSide = getLargerSide(constraints);
    ^^^^^^^^^^^^^
    lib/src/wheel/slice_layout_delegate.dart:33:45: Error: The method 'rotate' isn't defined for the type 'Point'.
  • 'Point' is from 'dart:math'.
    Try correcting the name to the name of an existing method, or defining a method named 'rotate'.
    final halfAngleVector = topRectVector.rotate(angle / 2);
    ^^^^^^
    lib/src/wheel/wheel_indicator.dart:62:25: Error: The method 'getCenteredMargins' isn't defined for the type '_WheelIndicator'.
  • '_WheelIndicator' is from 'package:flutter_fortune_wheel/src/wheel/wheel.dart' ('lib/src/wheel/wheel.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'getCenteredMargins'.
    final margins = getCenteredMargins(constraints);
    ^^^^^^^^^^^^^^^^^^
    ❌ loading /home/runner/work/flutter_fortune_wheel/flutter_fortune_wheel/test/fortune_wheel_test.dart (failed)
    ❌ loading /home/runner/work/flutter_fortune_wheel/flutter_fortune_wheel/test/triangle_indicator_test.dart (failed after test completion)

@google-labs-jules
Copy link
Copy Markdown
Contributor Author

lib/src/core/animations.dart:23:3: Error: Type 'StreamSubscription' not found.
StreamSubscription? _subscription;
^^^^^^^^^^^^^^^^^^
lib/src/core/animations.dart:23:3: Error: 'StreamSubscription' isn't a type.
StreamSubscription? _subscription;
^^^^^^^^^^^^^^^^^^
lib/src/wheel/fortune_wheel.dart:7:23: Error: Method not found: 'getSmallerSide'.
final smallerSide = getSmallerSide(constraints);
^^^^^^^^^^^^^^
lib/src/wheel/fortune_wheel.dart:61:35: Error: The method 'getSmallerSide' isn't defined for the type '_WheelData'.

  • '_WheelData' is from 'package:flutter_fortune_wheel/src/wheel/wheel.dart' ('lib/src/wheel/wheel.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'getSmallerSide'.
    late final double smallerSide = getSmallerSide(constraints);
    ^^^^^^^^^^^^^^
    lib/src/wheel/fortune_wheel.dart:62:34: Error: The method 'getLargerSide' isn't defined for the type '_WheelData'.
  • '_WheelData' is from 'package:flutter_fortune_wheel/src/wheel/wheel.dart' ('lib/src/wheel/wheel.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'getLargerSide'.
    late final double largerSide = getLargerSide(constraints);
    ^^^^^^^^^^^^^
    lib/src/wheel/slice_layout_delegate.dart:33:45: Error: The method 'rotate' isn't defined for the type 'Point'.
  • 'Point' is from 'dart:math'.
    Try correcting the name to the name of an existing method, or defining a method named 'rotate'.
    final halfAngleVector = topRectVector.rotate(angle / 2);
    ^^^^^^
    lib/src/wheel/wheel_indicator.dart:62:25: Error: The method 'getCenteredMargins' isn't defined for the type '_WheelIndicator'.
  • '_WheelIndicator' is from 'package:flutter_fortune_wheel/src/wheel/wheel.dart' ('lib/src/wheel/wheel.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'getCenteredMargins'.
    final margins = getCenteredMargins(constraints);
    ^^^^^^^^^^^^^^^^^^
    ❌ loading /home/runner/work/flutter_fortune_wheel/flutter_fortune_wheel/test/triangle_indicator_test.dart (failed)
    ❌ loading /home/runner/work/flutter_fortune_wheel/flutter_fortune_wheel/test/triangle_indicator_test.dart (failed after test completion)
    lib/src/core/animations.dart:23:3: Error: Type 'StreamSubscription' not found.
    StreamSubscription? _subscription;
    ^^^^^^^^^^^^^^^^^^
    lib/src/core/animations.dart:23:3: Error: 'StreamSubscription' isn't a type.
    StreamSubscription? _subscription;
    ^^^^^^^^^^^^^^^^^^
    lib/src/wheel/fortune_wheel.dart:7:23: Error: Method not found: 'getSmallerSide'.
    final smallerSide = getSmallerSide(constraints);
    ^^^^^^^^^^^^^^
    lib/src/wheel/fortune_wheel.dart:61:35: Error: The method 'getSmallerSide' isn't defined for the type '_WheelData'.
  • '_WheelData' is from 'package:flutter_fortune_wheel/src/wheel/wheel.dart' ('lib/src/wheel/wheel.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'getSmallerSide'.
    late final double smallerSide = getSmallerSide(constraints);
    ^^^^^^^^^^^^^^
    lib/src/wheel/fortune_wheel.dart:62:34: Error: The method 'getLargerSide' isn't defined for the type '_WheelData'.
  • '_WheelData' is from 'package:flutter_fortune_wheel/src/wheel/wheel.dart' ('lib/src/wheel/wheel.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'getLargerSide'.
    late final double largerSide = getLargerSide(constraints);
    ^^^^^^^^^^^^^
    lib/src/wheel/slice_layout_delegate.dart:33:45: Error: The method 'rotate' isn't defined for the type 'Point'.
  • 'Point' is from 'dart:math'.
    Try correcting the name to the name of an existing method, or defining a method named 'rotate'.
    final halfAngleVector = topRectVector.rotate(angle / 2);
    ^^^^^^
    lib/src/wheel/wheel_indicator.dart:62:25: Error: The method 'getCenteredMargins' isn't defined for the type '_WheelIndicator'.
  • '_WheelIndicator' is from 'package:flutter_fortune_wheel/src/wheel/wheel.dart' ('lib/src/wheel/wheel.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'getCenteredMargins'.
    final margins = getCenteredMargins(constraints);
    ^^^^^^^^^^^^^^^^^^
    ❌ loading /home/runner/work/flutter_fortune_wheel/flutter_fortune_wheel/test/fortune_wheel_test.dart (failed)
    ❌ loading /home/runner/work/flutter_fortune_wheel/flutter_fortune_wheel/test/triangle_indicator_test.dart (failed after test completion)

I've fixed the compilation errors by adding the missing imports. lib/src/core/core.dart now imports dart:async for StreamSubscription, and lib/src/wheel/wheel.dart now imports ../util.dart for the utility functions and extensions like getSmallerSide and rotate.

- Added `import 'dart:async'` to `lib/src/core/core.dart`.
- Added `import '../util.dart'` to `lib/src/wheel/wheel.dart`.
@kevlatus kevlatus marked this pull request as ready for review January 10, 2026 08:32
@kevlatus kevlatus merged commit e1b6c3b into main Jan 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant