Skip to content

Commit

Permalink
feat: add auto refresh based on #PR115
Browse files Browse the repository at this point in the history
  • Loading branch information
ReuelJosafa committed Jun 19, 2023
1 parent 4384a77 commit 0195ce9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ class MyHomePageState extends State<MyHomePage> {
onSkip: () {
print("skip");
},
themeData: Theme.of(context),
);
}

Expand Down
25 changes: 25 additions & 0 deletions lib/src/widgets/animated_focus_light.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,31 @@ abstract class AnimatedFocusLightState extends State<AnimatedFocusLight>
_runFocus();
}

void refresh() {
_targetFocus = widget.targets[_currentFocus];
var targetPosition = getTargetCurrent(_targetFocus);

if (targetPosition == null) {
_finish();
return;
}

setState(() {
_targetPosition = targetPosition;

_positioned = Offset(
targetPosition.offset.dx + (targetPosition.size.width / 2),
targetPosition.offset.dy + (targetPosition.size.height / 2),
);

if (targetPosition.size.height > targetPosition.size.width) {
_sizeCircle = targetPosition.size.height * 0.6 + _getPaddingFocus();
} else {
_sizeCircle = targetPosition.size.width * 0.6 + _getPaddingFocus();
}
});
}

void _finish() {
safeSetState(() => _currentFocus = 0);
widget.finish!();
Expand Down
6 changes: 6 additions & 0 deletions lib/src/widgets/tutorial_coach_mark_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class TutorialCoachMarkWidgetState extends State<TutorialCoachMarkWidget>

@override
Widget build(BuildContext context) {
refresh();
return Material(
type: MaterialType.transparency,
child: Stack(
Expand Down Expand Up @@ -279,4 +280,9 @@ class TutorialCoachMarkWidgetState extends State<TutorialCoachMarkWidget>

@override
void previous() => _focusLightKey.currentState?.previous();

void refresh() {
setState(() {});
_focusLightKey.currentState?.refresh();
}
}

0 comments on commit 0195ce9

Please sign in to comment.