How to receive state in App Bar using bloc
I have an list view Builder in scaffold widget. I need to count list size and display list size in App Bar. I can't get state in APP Bar using bloc pattern. I can get state except App Bar. How can i get and change state in App Bar using Bloc Pattern.
add a comment |
I have an list view Builder in scaffold widget. I need to count list size and display list size in App Bar. I can't get state in APP Bar using bloc pattern. I can get state except App Bar. How can i get and change state in App Bar using Bloc Pattern.
Why can't you get the state in yourAppBar? Just wrap yourScaffoldin aStreamBuilder.
– Jordan Davies
Jan 18 at 14:03
I am using bloc builder to change state. I have written bloc builder with in scaffold widget.
– Vinothkumar
Jan 18 at 14:06
Yes but you can just move your Scaffold widget so it is within the bloc builder.
– Jordan Davies
Jan 18 at 14:14
Could you please explain me how can i do that.
– Vinothkumar
Jan 18 at 14:30
If you update your question to include some code, I'll try and show you.
– Jordan Davies
Jan 18 at 14:47
add a comment |
I have an list view Builder in scaffold widget. I need to count list size and display list size in App Bar. I can't get state in APP Bar using bloc pattern. I can get state except App Bar. How can i get and change state in App Bar using Bloc Pattern.
I have an list view Builder in scaffold widget. I need to count list size and display list size in App Bar. I can't get state in APP Bar using bloc pattern. I can get state except App Bar. How can i get and change state in App Bar using Bloc Pattern.
asked Jan 18 at 13:55
VinothkumarVinothkumar
32
32
Why can't you get the state in yourAppBar? Just wrap yourScaffoldin aStreamBuilder.
– Jordan Davies
Jan 18 at 14:03
I am using bloc builder to change state. I have written bloc builder with in scaffold widget.
– Vinothkumar
Jan 18 at 14:06
Yes but you can just move your Scaffold widget so it is within the bloc builder.
– Jordan Davies
Jan 18 at 14:14
Could you please explain me how can i do that.
– Vinothkumar
Jan 18 at 14:30
If you update your question to include some code, I'll try and show you.
– Jordan Davies
Jan 18 at 14:47
add a comment |
Why can't you get the state in yourAppBar? Just wrap yourScaffoldin aStreamBuilder.
– Jordan Davies
Jan 18 at 14:03
I am using bloc builder to change state. I have written bloc builder with in scaffold widget.
– Vinothkumar
Jan 18 at 14:06
Yes but you can just move your Scaffold widget so it is within the bloc builder.
– Jordan Davies
Jan 18 at 14:14
Could you please explain me how can i do that.
– Vinothkumar
Jan 18 at 14:30
If you update your question to include some code, I'll try and show you.
– Jordan Davies
Jan 18 at 14:47
Why can't you get the state in your
AppBar? Just wrap your Scaffold in a StreamBuilder.– Jordan Davies
Jan 18 at 14:03
Why can't you get the state in your
AppBar? Just wrap your Scaffold in a StreamBuilder.– Jordan Davies
Jan 18 at 14:03
I am using bloc builder to change state. I have written bloc builder with in scaffold widget.
– Vinothkumar
Jan 18 at 14:06
I am using bloc builder to change state. I have written bloc builder with in scaffold widget.
– Vinothkumar
Jan 18 at 14:06
Yes but you can just move your Scaffold widget so it is within the bloc builder.
– Jordan Davies
Jan 18 at 14:14
Yes but you can just move your Scaffold widget so it is within the bloc builder.
– Jordan Davies
Jan 18 at 14:14
Could you please explain me how can i do that.
– Vinothkumar
Jan 18 at 14:30
Could you please explain me how can i do that.
– Vinothkumar
Jan 18 at 14:30
If you update your question to include some code, I'll try and show you.
– Jordan Davies
Jan 18 at 14:47
If you update your question to include some code, I'll try and show you.
– Jordan Davies
Jan 18 at 14:47
add a comment |
1 Answer
1
active
oldest
votes
You should put a listener on your List; fyi... this is a feature built into Streambuilder or ListView.builder and perform setState((){ publicInt = list.length}). Instantiate a public int variable of publicInt that will update every time list.length changes and add it to your AppBar title. Similar to the code below...
int publicInt;
@override
Widget build (BuildContext ctxt) {
return new Scaffold(
appBar: new AppBar(title: new Text("Dynamic Demo # $publicInt"),),
body: new ListView.builder
(
itemCount: litems.length,
itemBuilder: (BuildContext ctxt, int index) {
setState((){ publicInt = list.length});
}
)
),
);
}
}
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%2f54255463%2fhow-to-receive-state-in-app-bar-using-bloc%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 should put a listener on your List; fyi... this is a feature built into Streambuilder or ListView.builder and perform setState((){ publicInt = list.length}). Instantiate a public int variable of publicInt that will update every time list.length changes and add it to your AppBar title. Similar to the code below...
int publicInt;
@override
Widget build (BuildContext ctxt) {
return new Scaffold(
appBar: new AppBar(title: new Text("Dynamic Demo # $publicInt"),),
body: new ListView.builder
(
itemCount: litems.length,
itemBuilder: (BuildContext ctxt, int index) {
setState((){ publicInt = list.length});
}
)
),
);
}
}
add a comment |
You should put a listener on your List; fyi... this is a feature built into Streambuilder or ListView.builder and perform setState((){ publicInt = list.length}). Instantiate a public int variable of publicInt that will update every time list.length changes and add it to your AppBar title. Similar to the code below...
int publicInt;
@override
Widget build (BuildContext ctxt) {
return new Scaffold(
appBar: new AppBar(title: new Text("Dynamic Demo # $publicInt"),),
body: new ListView.builder
(
itemCount: litems.length,
itemBuilder: (BuildContext ctxt, int index) {
setState((){ publicInt = list.length});
}
)
),
);
}
}
add a comment |
You should put a listener on your List; fyi... this is a feature built into Streambuilder or ListView.builder and perform setState((){ publicInt = list.length}). Instantiate a public int variable of publicInt that will update every time list.length changes and add it to your AppBar title. Similar to the code below...
int publicInt;
@override
Widget build (BuildContext ctxt) {
return new Scaffold(
appBar: new AppBar(title: new Text("Dynamic Demo # $publicInt"),),
body: new ListView.builder
(
itemCount: litems.length,
itemBuilder: (BuildContext ctxt, int index) {
setState((){ publicInt = list.length});
}
)
),
);
}
}
You should put a listener on your List; fyi... this is a feature built into Streambuilder or ListView.builder and perform setState((){ publicInt = list.length}). Instantiate a public int variable of publicInt that will update every time list.length changes and add it to your AppBar title. Similar to the code below...
int publicInt;
@override
Widget build (BuildContext ctxt) {
return new Scaffold(
appBar: new AppBar(title: new Text("Dynamic Demo # $publicInt"),),
body: new ListView.builder
(
itemCount: litems.length,
itemBuilder: (BuildContext ctxt, int index) {
setState((){ publicInt = list.length});
}
)
),
);
}
}
answered Jan 18 at 17:57
Charles JrCharles Jr
8371638
8371638
add a comment |
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%2f54255463%2fhow-to-receive-state-in-app-bar-using-bloc%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
Why can't you get the state in your
AppBar? Just wrap yourScaffoldin aStreamBuilder.– Jordan Davies
Jan 18 at 14:03
I am using bloc builder to change state. I have written bloc builder with in scaffold widget.
– Vinothkumar
Jan 18 at 14:06
Yes but you can just move your Scaffold widget so it is within the bloc builder.
– Jordan Davies
Jan 18 at 14:14
Could you please explain me how can i do that.
– Vinothkumar
Jan 18 at 14:30
If you update your question to include some code, I'll try and show you.
– Jordan Davies
Jan 18 at 14:47