Error calling 'Void' on 'onPressed/onTap' Flutter
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I get an error calling a void in onPressed/onTap
I'm trying to call a set state in an Inherited widget/state
following this instructions
https://medium.com/flutter-community/widget-state-buildcontext-inheritedwidget-898d671b7956
To my inexpert eyes looks like he is doing the same,
but clearly I missed something;
can you help me out?
class InhCore extends InheritedWidget
InhCore(Key key, @required Widget child, @required this.data)
: super(key: key, child: child);
final InhState data;
@override
bool updateShouldNotify(InhCore oldWidget)
return true;
class InhWidget extends StatefulWidget
InhWidget(this.child);
final Widget child;
@override
State<StatefulWidget> createState() => InhState();
static InhState of(BuildContext context)
return (context.inheritFromWidgetOfExactType(InhCore) as InhCore).data;
class InhState extends State<InhWidget>
final Map<String, int> cardMap =
'A':1,
'2':2,
'3':3,
'4':4,
'5':5,
'6':6,
'7':7,
'8':8,
'9':9,
'10':0,
'J':0,
'Q':0,
'K':0
;
List<String> cardDisplayed;
void deal(String card) => setState(() => cardDisplayed.add(card));
@override
Widget build(BuildContext context)
return new InhCore(
data: this,
child: widget.child,
);
class CardButton extends StatelessWidget
final String input;
CardButton(this.input);
Widget build(BuildContext context)
final InhState state = InhWidget.of(context);
return Container(
width: 55.0,
height: 55.0,
child: Material(
color: Colors.grey[200],
child: InkWell(
onTap: state.deal(input),
child: Center (
child:Text(input),
),
),
),
);
thanks in advance for the help
dart flutter void
add a comment |
I get an error calling a void in onPressed/onTap
I'm trying to call a set state in an Inherited widget/state
following this instructions
https://medium.com/flutter-community/widget-state-buildcontext-inheritedwidget-898d671b7956
To my inexpert eyes looks like he is doing the same,
but clearly I missed something;
can you help me out?
class InhCore extends InheritedWidget
InhCore(Key key, @required Widget child, @required this.data)
: super(key: key, child: child);
final InhState data;
@override
bool updateShouldNotify(InhCore oldWidget)
return true;
class InhWidget extends StatefulWidget
InhWidget(this.child);
final Widget child;
@override
State<StatefulWidget> createState() => InhState();
static InhState of(BuildContext context)
return (context.inheritFromWidgetOfExactType(InhCore) as InhCore).data;
class InhState extends State<InhWidget>
final Map<String, int> cardMap =
'A':1,
'2':2,
'3':3,
'4':4,
'5':5,
'6':6,
'7':7,
'8':8,
'9':9,
'10':0,
'J':0,
'Q':0,
'K':0
;
List<String> cardDisplayed;
void deal(String card) => setState(() => cardDisplayed.add(card));
@override
Widget build(BuildContext context)
return new InhCore(
data: this,
child: widget.child,
);
class CardButton extends StatelessWidget
final String input;
CardButton(this.input);
Widget build(BuildContext context)
final InhState state = InhWidget.of(context);
return Container(
width: 55.0,
height: 55.0,
child: Material(
color: Colors.grey[200],
child: InkWell(
onTap: state.deal(input),
child: Center (
child:Text(input),
),
),
),
);
thanks in advance for the help
dart flutter void
add a comment |
I get an error calling a void in onPressed/onTap
I'm trying to call a set state in an Inherited widget/state
following this instructions
https://medium.com/flutter-community/widget-state-buildcontext-inheritedwidget-898d671b7956
To my inexpert eyes looks like he is doing the same,
but clearly I missed something;
can you help me out?
class InhCore extends InheritedWidget
InhCore(Key key, @required Widget child, @required this.data)
: super(key: key, child: child);
final InhState data;
@override
bool updateShouldNotify(InhCore oldWidget)
return true;
class InhWidget extends StatefulWidget
InhWidget(this.child);
final Widget child;
@override
State<StatefulWidget> createState() => InhState();
static InhState of(BuildContext context)
return (context.inheritFromWidgetOfExactType(InhCore) as InhCore).data;
class InhState extends State<InhWidget>
final Map<String, int> cardMap =
'A':1,
'2':2,
'3':3,
'4':4,
'5':5,
'6':6,
'7':7,
'8':8,
'9':9,
'10':0,
'J':0,
'Q':0,
'K':0
;
List<String> cardDisplayed;
void deal(String card) => setState(() => cardDisplayed.add(card));
@override
Widget build(BuildContext context)
return new InhCore(
data: this,
child: widget.child,
);
class CardButton extends StatelessWidget
final String input;
CardButton(this.input);
Widget build(BuildContext context)
final InhState state = InhWidget.of(context);
return Container(
width: 55.0,
height: 55.0,
child: Material(
color: Colors.grey[200],
child: InkWell(
onTap: state.deal(input),
child: Center (
child:Text(input),
),
),
),
);
thanks in advance for the help
dart flutter void
I get an error calling a void in onPressed/onTap
I'm trying to call a set state in an Inherited widget/state
following this instructions
https://medium.com/flutter-community/widget-state-buildcontext-inheritedwidget-898d671b7956
To my inexpert eyes looks like he is doing the same,
but clearly I missed something;
can you help me out?
class InhCore extends InheritedWidget
InhCore(Key key, @required Widget child, @required this.data)
: super(key: key, child: child);
final InhState data;
@override
bool updateShouldNotify(InhCore oldWidget)
return true;
class InhWidget extends StatefulWidget
InhWidget(this.child);
final Widget child;
@override
State<StatefulWidget> createState() => InhState();
static InhState of(BuildContext context)
return (context.inheritFromWidgetOfExactType(InhCore) as InhCore).data;
class InhState extends State<InhWidget>
final Map<String, int> cardMap =
'A':1,
'2':2,
'3':3,
'4':4,
'5':5,
'6':6,
'7':7,
'8':8,
'9':9,
'10':0,
'J':0,
'Q':0,
'K':0
;
List<String> cardDisplayed;
void deal(String card) => setState(() => cardDisplayed.add(card));
@override
Widget build(BuildContext context)
return new InhCore(
data: this,
child: widget.child,
);
class CardButton extends StatelessWidget
final String input;
CardButton(this.input);
Widget build(BuildContext context)
final InhState state = InhWidget.of(context);
return Container(
width: 55.0,
height: 55.0,
child: Material(
color: Colors.grey[200],
child: InkWell(
onTap: state.deal(input),
child: Center (
child:Text(input),
),
),
),
);
thanks in advance for the help
dart flutter void
dart flutter void
asked Nov 15 '18 at 15:48
Francesco IapiccaFrancesco Iapicca
15911
15911
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You missed () =>
onPressed: () => state.deal(input)
Your code passes the result of the call state.deal(input)
to onPressed
, while above code passes a function that when called invokes state.deal(input)
1
thanks mate, it works I have other problems apparently with inherited widget (which I find super cool), but one step at the time :)
– Francesco Iapicca
Nov 16 '18 at 19:45
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323105%2ferror-calling-void-on-onpressed-ontap-flutter%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You missed () =>
onPressed: () => state.deal(input)
Your code passes the result of the call state.deal(input)
to onPressed
, while above code passes a function that when called invokes state.deal(input)
1
thanks mate, it works I have other problems apparently with inherited widget (which I find super cool), but one step at the time :)
– Francesco Iapicca
Nov 16 '18 at 19:45
add a comment |
You missed () =>
onPressed: () => state.deal(input)
Your code passes the result of the call state.deal(input)
to onPressed
, while above code passes a function that when called invokes state.deal(input)
1
thanks mate, it works I have other problems apparently with inherited widget (which I find super cool), but one step at the time :)
– Francesco Iapicca
Nov 16 '18 at 19:45
add a comment |
You missed () =>
onPressed: () => state.deal(input)
Your code passes the result of the call state.deal(input)
to onPressed
, while above code passes a function that when called invokes state.deal(input)
You missed () =>
onPressed: () => state.deal(input)
Your code passes the result of the call state.deal(input)
to onPressed
, while above code passes a function that when called invokes state.deal(input)
answered Nov 15 '18 at 15:55
Günter ZöchbauerGünter Zöchbauer
338k721045964
338k721045964
1
thanks mate, it works I have other problems apparently with inherited widget (which I find super cool), but one step at the time :)
– Francesco Iapicca
Nov 16 '18 at 19:45
add a comment |
1
thanks mate, it works I have other problems apparently with inherited widget (which I find super cool), but one step at the time :)
– Francesco Iapicca
Nov 16 '18 at 19:45
1
1
thanks mate, it works I have other problems apparently with inherited widget (which I find super cool), but one step at the time :)
– Francesco Iapicca
Nov 16 '18 at 19:45
thanks mate, it works I have other problems apparently with inherited widget (which I find super cool), but one step at the time :)
– Francesco Iapicca
Nov 16 '18 at 19:45
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323105%2ferror-calling-void-on-onpressed-ontap-flutter%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown