I use showCaseView package in my app, and want to showcase for one time (just after the first start), How can I do this only once and not show it on the next launches?
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback(
(_) {
ShowCaseWidget.of(myContext).startShowCase([_one]);
}
);
}
@override
Widget build(BuildContext context) {
return ShowCaseWidget(
// onFinish: ,
builder:
Builder(builder: (context) {
myContext = context;
return Scaffold(
floatingActionButton: Showcase(
key: _one,
title: 'Title',
description: 'Desc',
child: InkWell(
onTap: () {},
child: FloatingActionButton(
onPressed: (){
print("floating");
}
)
),
),
);
}));
}
You can easily do this with the shared_preferences
package:
class IsFirstLaunchPage extends StatefulWidget {
static const PREFERENCES_IS_FIRST_LAUNCH_STRING = "PREFERENCES_IS_FIRST_LAUNCH_STRING";
@override
_IsFirstLaunchPageState createState() => _IsFirstLaunchPageState();
}
class _IsFirstLaunchPageState extends State<IsFirstLaunchPage> {
GlobalKey _one = GlobalKey();
BuildContext myContext;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback(
(_) {
_isFirstLaunch().then((result){
if(result)
ShowCaseWidget.of(myContext).startShowCase([_one]);
});
}
);
}
@override
Widget build(BuildContext context) {
return ShowCaseWidget(
// onFinish: ,
builder:
Builder(builder: (context) {
myContext = context;
return Scaffold(
floatingActionButton: Showcase(
key: _one,
title: 'Title',
description: 'Desc',
child: InkWell(
onTap: () {},
child: FloatingActionButton(
onPressed: () {
print("floating");
}
)
),
),
);
}));
}
Future<bool> _isFirstLaunch() async{
final sharedPreferences = await SharedPreferences.getInstance();
bool isFirstLaunch = sharedPreferences.getBool(IsFirstLaunchPage.PREFERENCES_IS_FIRST_LAUNCH_STRING) ?? true;
if(isFirstLaunch)
sharedPreferences.setBool(IsFirstLaunchPage.PREFERENCES_IS_FIRST_LAUNCH_STRING, false);
return isFirstLaunch;
}
}