Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/src/hotspot_provider.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:hotspot/hotspot.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -173,14 +175,16 @@ class HotspotProviderState extends State<HotspotProvider>
/// focus to close the keyboard, and after the tour is done we
/// put the focus back where it was.
FocusNode? _lastFocusNode;

Completer? _flowCompleter;

/// Convenience getter for the current flow sorted by order.
List<HotspotTargetState> get currentFlow =>
_targets.where((e) => e.widget.flow == _flow).toList()
..sort((a, b) => a.widget.order.compareTo(b.widget.order));

/// Initiate a hotspot flow
void startFlow([String flow = 'main']) {
Future<void> startFlow([String flow = 'main']) async {
/// Dismiss keyboard if open
_lastFocusNode = FocusManager.instance.primaryFocus;
_lastFocusNode?.unfocus();
Expand All @@ -200,6 +204,12 @@ class HotspotProviderState extends State<HotspotProvider>
_visible = true;
}
});

final flowCompleter = Completer();

_flowCompleter = flowCompleter;

await flowCompleter.future;
}

/// Called when tapping the next button.
Expand Down Expand Up @@ -233,13 +243,19 @@ class HotspotProviderState extends State<HotspotProvider>

setState(() => _visible = false);

_flowCompleter?.complete();

/// Put the focus back where it was if we
/// have a previously-saved focus node.
_lastFocusNode?.requestFocus();
_lastFocusNode = null;

/// don't animate to first tag on subsequent flow runs
Future.delayed(widget.duration, () => setState(() => _index = 0));
Future.delayed(widget.duration, () {
if(mounted) {
setState(() => _index = 0);
}
});
}

/// Removes all targets that are not mounted
Expand Down