onboarding_overlay 2.3.1-pre.3 onboarding_overlay: ^2.3.1-pre.3 copied to clipboard
Flexible to control Onboarding overlay with or without target element (fork from onboard_overlay)
onboarding_overlay #
A flexible onboarding widget that can start and stop with an arbitrary number of steps and arbitrary starting point
Demo #
Usage #
- Create your
List<FocusNodes>
somewhere accessible
final List<FocusNode> overlayKeys = <FocusNode>[
FocusNode(),
FocusNode(),
FocusNode(),
];
- Create your
List<OnboardingSteps>
somewhere accessible
final List<OnboardingSteps> steps = [OnboardingStep(
focusNode: _focusNodes != null ? _focusNodes[0] : null,
title: "Hi",
titleTextStyle: Theme.of(context).textTheme.headline5.copyWith(
color: Theme.of(context).canvasColor,
),
bodyText:
'''Check this out''',
bodyTextStyle: Theme.of(context).textTheme.subtitle1.copyWith(
color: Theme.of(context).canvasColor,
),
hasLabelBox: false,
fullscreen: true,
overlayColor: Theme.of(context).primaryColorDark.withOpacity(0.8),
hasArrow: false,
),]
- Provide the
FocusNode
s to the widgets.
Focus(
focusNode: focusNode[0]
Text(
'You have pushed the button this many times:',
),
)
- Add Onboarding widget to your widget tree below MaterialWidget
void main() {
runApp(App());
}
class App extends StatefulWidget {
final GlobalKey<OnboardingState> onboardingKey = GlobalKey<OnboardingState>();
@override
_AppState createState() => _AppState();
}
class _AppState extends State<App> {
List<FocusNode> focusNodes = <FocusNode>[];
@override
void initState() {
super.initState();
focusNodes = List<FocusNode>.generate(
7,
(int i) => FocusNode(debugLabel: i.toString()),
growable: false,
);
}
@override
Widget build(BuildContext context) => MaterialApp(
home: Onboarding(
key: widget.onboardingKey,
steps: steps,
onChanged: (int index) {
debugPrint('----index $index');
if (index == 5) {
/// interrupt onboarding on specific step
/// widget.onboardingKey.currentState.hide();
/// or do something else
}
},
child: Home(
focusNodes: focusNodes,
),
),
);
}
- Show onboarding widget on some activity
final OnboardingState? onboading = Onboarding.of(context);
if (onboarding != null) {
onboarding.show();
}
or immediately in initState
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((Duration timeStamp) {
final OnboardingState? onboading = Onboarding.of(context);
if (onboarding != null) {
onboarding.showWithSteps(3, <int>[3,4,5,6]);
}
});
}