How to refresh a route page
I followed the startup name generator tutorial in the flutter website and there was no problem.
But then I wanted to add the ability to remove wordpairs from the saved list. That worked too but when a word was removed from the list, the listview wouldn't update and I had to go back to the main page and open the list again to see the effect. I searched for a way to update the listview at the setState function that I delete the wordpair in, but I could't find anything. So after removing the wordpair in the setstate, I just popped the route and pushed it again.
Can anyone suggest a better way?
Thanks
routes flutter
add a comment |
I followed the startup name generator tutorial in the flutter website and there was no problem.
But then I wanted to add the ability to remove wordpairs from the saved list. That worked too but when a word was removed from the list, the listview wouldn't update and I had to go back to the main page and open the list again to see the effect. I searched for a way to update the listview at the setState function that I delete the wordpair in, but I could't find anything. So after removing the wordpair in the setstate, I just popped the route and pushed it again.
Can anyone suggest a better way?
Thanks
routes flutter
add a comment |
I followed the startup name generator tutorial in the flutter website and there was no problem.
But then I wanted to add the ability to remove wordpairs from the saved list. That worked too but when a word was removed from the list, the listview wouldn't update and I had to go back to the main page and open the list again to see the effect. I searched for a way to update the listview at the setState function that I delete the wordpair in, but I could't find anything. So after removing the wordpair in the setstate, I just popped the route and pushed it again.
Can anyone suggest a better way?
Thanks
routes flutter
I followed the startup name generator tutorial in the flutter website and there was no problem.
But then I wanted to add the ability to remove wordpairs from the saved list. That worked too but when a word was removed from the list, the listview wouldn't update and I had to go back to the main page and open the list again to see the effect. I searched for a way to update the listview at the setState function that I delete the wordpair in, but I could't find anything. So after removing the wordpair in the setstate, I just popped the route and pushed it again.
Can anyone suggest a better way?
Thanks
routes flutter
routes flutter
asked Nov 14 '18 at 17:09
CredoCredo
215
215
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You might be able to do that using a StreamBuilder
. Using that, your argument should like the following:
stream: FirebaseDatabase.instance.reference().child(
"profiles").onValue
As you can see, the onValue
will automatically update your screen whenever you delete a value.
The wordpairs are stored in a set and sets don't have an onValue getter(as the error informed me). How can I transform a set to a stream? Also, streams don't seem to have any method for removing a previously sent item.
– Credo
Nov 15 '18 at 11:09
add a comment |
Assuming you've just used the main.dart
from the startup name generator tutorial, then you can just modify your _buildRow
function to add a delete button which will then call setState
and modify the _suggestions
list like this:
Widget _buildRow(WordPair pair)
return ListTile(
title: Text(
pair.asPascalCase,
style: _biggerFont,
),
subtitle: RaisedButton(
child: Text('delete'),
onPressed: ()
setState(()
_suggestions.remove(pair);
);
));
And here's the full main.dart
:
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget
@override
Widget build(BuildContext context)
return MaterialApp(
title: 'Startup Name Generator',
home: RandomWords(),
);
class RandomWordsState extends State<RandomWords>
final _suggestions = <WordPair>;
final _biggerFont = const TextStyle(fontSize: 18.0);
Widget _buildSuggestions()
return ListView.builder(
padding: const EdgeInsets.all(16.0),
itemBuilder: (context, i)
// Add a one-pixel-high divider widget before each row in theListView.
if (i.isOdd) return Divider();
final index = i ~/ 2;
if (index >= _suggestions.length)
_suggestions.addAll(generateWordPairs().take(10));
return _buildRow(_suggestions[index]);
);
Widget _buildRow(WordPair pair)
return ListTile(
title: Text(
pair.asPascalCase,
style: _biggerFont,
),
subtitle: RaisedButton(
child: Text('delete'),
onPressed: ()
setState(()
_suggestions.remove(pair);
);
));
@override
Widget build(BuildContext context)
return Scaffold(
appBar: AppBar(
title: Text('Startup Name Generator'),
),
body: _buildSuggestions(),
);
class RandomWords extends StatefulWidget
@override
RandomWordsState createState() => new RandomWordsState();
add a comment |
I fixed it by making the list of saved pairs a separate stateful widget. I knew this would make the list refresh each time I deleted a pair but I thought the link between the states of the two stateful widgets would be lost and any time I deleted a pair from the list of saved pairs, the favorite icon in the other stateful widget would not update. But amazingly I was wrong. The states are somehow connected. I assume its because they're two stateful widgets on the same stack. I'm beginning to really like flutter.
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%2f53305444%2fhow-to-refresh-a-route-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You might be able to do that using a StreamBuilder
. Using that, your argument should like the following:
stream: FirebaseDatabase.instance.reference().child(
"profiles").onValue
As you can see, the onValue
will automatically update your screen whenever you delete a value.
The wordpairs are stored in a set and sets don't have an onValue getter(as the error informed me). How can I transform a set to a stream? Also, streams don't seem to have any method for removing a previously sent item.
– Credo
Nov 15 '18 at 11:09
add a comment |
You might be able to do that using a StreamBuilder
. Using that, your argument should like the following:
stream: FirebaseDatabase.instance.reference().child(
"profiles").onValue
As you can see, the onValue
will automatically update your screen whenever you delete a value.
The wordpairs are stored in a set and sets don't have an onValue getter(as the error informed me). How can I transform a set to a stream? Also, streams don't seem to have any method for removing a previously sent item.
– Credo
Nov 15 '18 at 11:09
add a comment |
You might be able to do that using a StreamBuilder
. Using that, your argument should like the following:
stream: FirebaseDatabase.instance.reference().child(
"profiles").onValue
As you can see, the onValue
will automatically update your screen whenever you delete a value.
You might be able to do that using a StreamBuilder
. Using that, your argument should like the following:
stream: FirebaseDatabase.instance.reference().child(
"profiles").onValue
As you can see, the onValue
will automatically update your screen whenever you delete a value.
answered Nov 14 '18 at 17:20
Issmeil EL.Issmeil EL.
641423
641423
The wordpairs are stored in a set and sets don't have an onValue getter(as the error informed me). How can I transform a set to a stream? Also, streams don't seem to have any method for removing a previously sent item.
– Credo
Nov 15 '18 at 11:09
add a comment |
The wordpairs are stored in a set and sets don't have an onValue getter(as the error informed me). How can I transform a set to a stream? Also, streams don't seem to have any method for removing a previously sent item.
– Credo
Nov 15 '18 at 11:09
The wordpairs are stored in a set and sets don't have an onValue getter(as the error informed me). How can I transform a set to a stream? Also, streams don't seem to have any method for removing a previously sent item.
– Credo
Nov 15 '18 at 11:09
The wordpairs are stored in a set and sets don't have an onValue getter(as the error informed me). How can I transform a set to a stream? Also, streams don't seem to have any method for removing a previously sent item.
– Credo
Nov 15 '18 at 11:09
add a comment |
Assuming you've just used the main.dart
from the startup name generator tutorial, then you can just modify your _buildRow
function to add a delete button which will then call setState
and modify the _suggestions
list like this:
Widget _buildRow(WordPair pair)
return ListTile(
title: Text(
pair.asPascalCase,
style: _biggerFont,
),
subtitle: RaisedButton(
child: Text('delete'),
onPressed: ()
setState(()
_suggestions.remove(pair);
);
));
And here's the full main.dart
:
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget
@override
Widget build(BuildContext context)
return MaterialApp(
title: 'Startup Name Generator',
home: RandomWords(),
);
class RandomWordsState extends State<RandomWords>
final _suggestions = <WordPair>;
final _biggerFont = const TextStyle(fontSize: 18.0);
Widget _buildSuggestions()
return ListView.builder(
padding: const EdgeInsets.all(16.0),
itemBuilder: (context, i)
// Add a one-pixel-high divider widget before each row in theListView.
if (i.isOdd) return Divider();
final index = i ~/ 2;
if (index >= _suggestions.length)
_suggestions.addAll(generateWordPairs().take(10));
return _buildRow(_suggestions[index]);
);
Widget _buildRow(WordPair pair)
return ListTile(
title: Text(
pair.asPascalCase,
style: _biggerFont,
),
subtitle: RaisedButton(
child: Text('delete'),
onPressed: ()
setState(()
_suggestions.remove(pair);
);
));
@override
Widget build(BuildContext context)
return Scaffold(
appBar: AppBar(
title: Text('Startup Name Generator'),
),
body: _buildSuggestions(),
);
class RandomWords extends StatefulWidget
@override
RandomWordsState createState() => new RandomWordsState();
add a comment |
Assuming you've just used the main.dart
from the startup name generator tutorial, then you can just modify your _buildRow
function to add a delete button which will then call setState
and modify the _suggestions
list like this:
Widget _buildRow(WordPair pair)
return ListTile(
title: Text(
pair.asPascalCase,
style: _biggerFont,
),
subtitle: RaisedButton(
child: Text('delete'),
onPressed: ()
setState(()
_suggestions.remove(pair);
);
));
And here's the full main.dart
:
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget
@override
Widget build(BuildContext context)
return MaterialApp(
title: 'Startup Name Generator',
home: RandomWords(),
);
class RandomWordsState extends State<RandomWords>
final _suggestions = <WordPair>;
final _biggerFont = const TextStyle(fontSize: 18.0);
Widget _buildSuggestions()
return ListView.builder(
padding: const EdgeInsets.all(16.0),
itemBuilder: (context, i)
// Add a one-pixel-high divider widget before each row in theListView.
if (i.isOdd) return Divider();
final index = i ~/ 2;
if (index >= _suggestions.length)
_suggestions.addAll(generateWordPairs().take(10));
return _buildRow(_suggestions[index]);
);
Widget _buildRow(WordPair pair)
return ListTile(
title: Text(
pair.asPascalCase,
style: _biggerFont,
),
subtitle: RaisedButton(
child: Text('delete'),
onPressed: ()
setState(()
_suggestions.remove(pair);
);
));
@override
Widget build(BuildContext context)
return Scaffold(
appBar: AppBar(
title: Text('Startup Name Generator'),
),
body: _buildSuggestions(),
);
class RandomWords extends StatefulWidget
@override
RandomWordsState createState() => new RandomWordsState();
add a comment |
Assuming you've just used the main.dart
from the startup name generator tutorial, then you can just modify your _buildRow
function to add a delete button which will then call setState
and modify the _suggestions
list like this:
Widget _buildRow(WordPair pair)
return ListTile(
title: Text(
pair.asPascalCase,
style: _biggerFont,
),
subtitle: RaisedButton(
child: Text('delete'),
onPressed: ()
setState(()
_suggestions.remove(pair);
);
));
And here's the full main.dart
:
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget
@override
Widget build(BuildContext context)
return MaterialApp(
title: 'Startup Name Generator',
home: RandomWords(),
);
class RandomWordsState extends State<RandomWords>
final _suggestions = <WordPair>;
final _biggerFont = const TextStyle(fontSize: 18.0);
Widget _buildSuggestions()
return ListView.builder(
padding: const EdgeInsets.all(16.0),
itemBuilder: (context, i)
// Add a one-pixel-high divider widget before each row in theListView.
if (i.isOdd) return Divider();
final index = i ~/ 2;
if (index >= _suggestions.length)
_suggestions.addAll(generateWordPairs().take(10));
return _buildRow(_suggestions[index]);
);
Widget _buildRow(WordPair pair)
return ListTile(
title: Text(
pair.asPascalCase,
style: _biggerFont,
),
subtitle: RaisedButton(
child: Text('delete'),
onPressed: ()
setState(()
_suggestions.remove(pair);
);
));
@override
Widget build(BuildContext context)
return Scaffold(
appBar: AppBar(
title: Text('Startup Name Generator'),
),
body: _buildSuggestions(),
);
class RandomWords extends StatefulWidget
@override
RandomWordsState createState() => new RandomWordsState();
Assuming you've just used the main.dart
from the startup name generator tutorial, then you can just modify your _buildRow
function to add a delete button which will then call setState
and modify the _suggestions
list like this:
Widget _buildRow(WordPair pair)
return ListTile(
title: Text(
pair.asPascalCase,
style: _biggerFont,
),
subtitle: RaisedButton(
child: Text('delete'),
onPressed: ()
setState(()
_suggestions.remove(pair);
);
));
And here's the full main.dart
:
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget
@override
Widget build(BuildContext context)
return MaterialApp(
title: 'Startup Name Generator',
home: RandomWords(),
);
class RandomWordsState extends State<RandomWords>
final _suggestions = <WordPair>;
final _biggerFont = const TextStyle(fontSize: 18.0);
Widget _buildSuggestions()
return ListView.builder(
padding: const EdgeInsets.all(16.0),
itemBuilder: (context, i)
// Add a one-pixel-high divider widget before each row in theListView.
if (i.isOdd) return Divider();
final index = i ~/ 2;
if (index >= _suggestions.length)
_suggestions.addAll(generateWordPairs().take(10));
return _buildRow(_suggestions[index]);
);
Widget _buildRow(WordPair pair)
return ListTile(
title: Text(
pair.asPascalCase,
style: _biggerFont,
),
subtitle: RaisedButton(
child: Text('delete'),
onPressed: ()
setState(()
_suggestions.remove(pair);
);
));
@override
Widget build(BuildContext context)
return Scaffold(
appBar: AppBar(
title: Text('Startup Name Generator'),
),
body: _buildSuggestions(),
);
class RandomWords extends StatefulWidget
@override
RandomWordsState createState() => new RandomWordsState();
answered Nov 14 '18 at 18:46
RingilRingil
3,75021226
3,75021226
add a comment |
add a comment |
I fixed it by making the list of saved pairs a separate stateful widget. I knew this would make the list refresh each time I deleted a pair but I thought the link between the states of the two stateful widgets would be lost and any time I deleted a pair from the list of saved pairs, the favorite icon in the other stateful widget would not update. But amazingly I was wrong. The states are somehow connected. I assume its because they're two stateful widgets on the same stack. I'm beginning to really like flutter.
add a comment |
I fixed it by making the list of saved pairs a separate stateful widget. I knew this would make the list refresh each time I deleted a pair but I thought the link between the states of the two stateful widgets would be lost and any time I deleted a pair from the list of saved pairs, the favorite icon in the other stateful widget would not update. But amazingly I was wrong. The states are somehow connected. I assume its because they're two stateful widgets on the same stack. I'm beginning to really like flutter.
add a comment |
I fixed it by making the list of saved pairs a separate stateful widget. I knew this would make the list refresh each time I deleted a pair but I thought the link between the states of the two stateful widgets would be lost and any time I deleted a pair from the list of saved pairs, the favorite icon in the other stateful widget would not update. But amazingly I was wrong. The states are somehow connected. I assume its because they're two stateful widgets on the same stack. I'm beginning to really like flutter.
I fixed it by making the list of saved pairs a separate stateful widget. I knew this would make the list refresh each time I deleted a pair but I thought the link between the states of the two stateful widgets would be lost and any time I deleted a pair from the list of saved pairs, the favorite icon in the other stateful widget would not update. But amazingly I was wrong. The states are somehow connected. I assume its because they're two stateful widgets on the same stack. I'm beginning to really like flutter.
answered Nov 17 '18 at 10:18
CredoCredo
215
215
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%2f53305444%2fhow-to-refresh-a-route-page%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