Closed bossbeagle1509 closed 3 years ago
Hey, It seems that ShowcaseWidget
is not the root of your tree and you're trying to access it in IconButton
.
Hey @BirjuVachhani ! Thank you so much for reverting !
I need the showcase to to trigger via a button, not on a page bein initialised, hence the button's onPressed is being used.
This is is simply one of the pages in a sample app I built to try the package. What do you mean by it is not the root of my tree ? Where do you suggest I place the required widget ?
@bossbeagle1509 What I mean is to put ShowCaseWidget
above the Scaffold
and use builder's context to do ShowCaseWidget.of(context)
.
Ok, I changed it to this:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:showcaseview/showcaseview.dart';
class Guide extends StatefulWidget {
const Guide({Key? key}) : super(key: key);
@override
_GuideState createState() => _GuideState();
}
class _GuideState extends State<Guide> {
final GlobalKey _one = GlobalKey();
final GlobalKey _two = GlobalKey();
@override
Widget build(BuildContext context) {
return ShowCaseWidget(
builder: Builder(
builder: (context) => Scaffold(
appBar: AppBar(
actions: [
IconButton(
onPressed: () {
ShowCaseWidget.of(context)!.startShowCase(
[
_one,
_two,
],
);
},
icon: const Icon(
CupertinoIcons.power,
),
)
],
),
body: ShowCaseWidget(
builder: Builder(
builder: (context) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Showcase(
key: _one,
title: 'blah blah',
description: 'This shows you what day today is.',
child: const Text(
'Today is Wensten :)',
),
),
// for some space
const SizedBox(
height: 40,
),
Showcase(
key: _two,
description: 'This shows you what the weather is.',
title: 'blah blah',
child: const Text(
'And it may rain :(',
),
),
],
),
),
),
),
),
),
);
}
}
But now I get no error and it still doesn't work :(
Ok so I managed to get it to work by moving the button down to be within the Column,
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:showcaseview/showcaseview.dart';
class Guide extends StatefulWidget {
const Guide({Key? key}) : super(key: key);
@override
_GuideState createState() => _GuideState();
}
class _GuideState extends State<Guide> {
final GlobalKey _one = GlobalKey();
final GlobalKey _two = GlobalKey();
@override
Widget build(BuildContext context) {
return ShowCaseWidget(
builder: Builder(
builder: (context) => Scaffold(
// appBar: AppBar(
// actions: [
// IconButton(
// onPressed: () {
// ShowCaseWidget.of(context)!.startShowCase(
// [
// _one,
// _two,
// ],
// );
// },
// icon: const Icon(
// CupertinoIcons.power,
// ),
// )
// ],
// ),
body: ShowCaseWidget(
builder: Builder(
builder: (context) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// to trigger
IconButton(
onPressed: () {
ShowCaseWidget.of(context)!.startShowCase(
[
_one,
_two,
],
);
},
icon: const Icon(
CupertinoIcons.power,
),
),
const SizedBox(
height: 100,
),
// a showcase
Showcase(
key: _one,
title: 'blah blah',
description: 'This shows you what day today is.',
child: const Text(
'Today is Wensten :)',
),
),
// for some space
const SizedBox(
height: 40,
),
// a showcase
Showcase(
key: _two,
description: 'This shows you what the weather is.',
title: 'blah blah',
child: const Text(
'And it may rain :(',
),
),
],
),
),
),
),
),
),
);
}
}
but is it not possible to have the button in the AppBar ?
You are having 2 ShowcaseWidget
. Remove the one in the body. I think it should work then. Avoid shadowing the context of Builder
with the context of build
method. Rename Builder
's context to ctx
and use it in ShowcaseWidget.of(ctx)
.
Fantabulous ! Works great now !
Thank you so much for your time and the suggestions ! I'm closing the issue now.
When I try to begin the showcase I get an error saying
Exception: Please provide ShowCaseView context
.Here's my code for the page:
This issue has been mentioned by several others, but no one has taken the time to respond. A successful package need not depend on class leading features, but rather on an active community and responsive repo owners.
Please do respond, even if not to point out whatever mistake I'm making.
Thanks, Pranav