Want to make your Flutter app super easy for new users to understand? Adding tutorials or guide overlays is a fantastic way! The pal_widgets
package helps you do just that, letting you create cool popups that point right to parts of your screen.
Here’s a simple way to add these helpful overlays:
1 - Install the Package
First, add pal_widgets
to your pubspec.yaml
file. You can find it on pub.dev.
Run flutter pub get
in your terminal.
2 - Add the Helper Manager
Place the HelperOrchestrator
widget high up in your widget tree, typically above your main page or even your MaterialApp
.
HelperOrchestrator(
child: Scaffold(
appBar: AppBar(title: Text(widget.title)),
body: Center(child: Text('Hello!')),
// ... rest of your page content
),
)
This widget will control showing and hiding your tutorials.
3 - Create Your Tutorial Message
Define what your tutorial step will look like. This includes the text (title and description) and how it should appear. You'll often use an AnchoredHelper
.
AnchoredHelper get myFirstHelper => AnchoredHelper(
title: 'Welcome!',
description: 'Tap here to get started.',
// You can add styles, colors, buttons here too!
);
Good news! Many properties like colors, buttons, and text styles are optional, so you can keep it simple or customize it a lot.
4 - Link to a Widget
Give the specific widget you want to highlight a special key generated by the HelperOrchestrator
. This key tells the tutorial where to point.
ElevatedButton(
key: HelperOrchestrator.of(context).generateKey('startButton'), // Give it a unique ID like 'startButton'
onPressed: () { /* do something */ },
child: const Text('Start'),
)
5 - Show the Tutorial
You need to wait until the screen is fully built before showing the overlay. Use WidgetsBinding.instance.addPostFrameCallback
for this.
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
HelperOrchestrator.of(context).ShowAnchoredHelper('startButton', myFirstHelper);
});
}
Replace 'startButton'
with the ID you used in step 4 and myFirstHelper
with the helper you created in step 3.
Helpful Tips:
- You can easily add multiple steps to your tutorial, guiding users through several actions.
- Tapping anywhere on the dim background often hides the current tutorial step.
- Remember to save whether the user has seen a tutorial already (e.g., using
SharedPreferences
) so it only shows the first time.
Using pal_widgets
is a quick and user-friendly way to add clear guidance directly within your Flutter app!