我正在尝试在 Flutter 应用程序中使用包 ShowoCaseView,以下是我所做的步骤:
GlobalKey _oneShowcaseKey = GlobalKey();
startShowCase() {
WidgetsBinding.instance.addPostFrameCallback((_) async {
ShowCaseWidget.of(context).startShowCase([_oneShowcaseKey]);
});
}
@override
void initState() {
startShowCase();
super.initState();
}
@override
Widget build(BuildContext context) {
super.build(context);
return ShowCaseWidget(
builder: Builder(
builder: (context) => Scaffold(
child: Showcase(
key: _oneShowcaseKey,
title: 'Menu',
description: 'Click here to see menu options',
child: Column())
)
这是我在应用程序中实现包的方式,但出现此错误:
[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Exception: Please provide ShowCaseView context
答案 0 :(得分:0)
我也有问题。
我改写“ShowCaseWIdget”到父widget如下,这个问题解决了。
class SolvedStatelessWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: ShowCaseWidget(
builder: Builder(builder: (context) => SolvedStatefulWidget())));
}
}
class SolvedStatefulWidget extends StatefulWidget {
@override
_SolvedStatefulWidgetState createState() => _SolvedStatefulWidgetState();
}
class _SolvedStatefulWidgetState extends State<SolvedStatefulWidget> {
GlobalKey _oneShowcaseKey = GlobalKey();
startShowCase() {
WidgetsBinding.instance.addPostFrameCallback((_) async {
ShowCaseWidget.of(context).startShowCase([_oneShowcaseKey]);
});
}
@override
void initState() {
startShowCase();
super.initState();
}
@override
Widget build(BuildContext context) {
super.build(context);
return yourWidget()
)