class _HomeViewState extends State<HomeView> {
ScrollController _scrollController = new ScrollController();
....
.......
@override
void initState() {
// TODO: implement initState
super.initState();
..
initScrollController();
}
initScrollController() {
_scrollController.addListener((){
if(_scrollController.offset > 135.0) {....
setState(() {
makeShareVisible(true, generateShareText(celebrations));
});
}else {
....
setState(() {
makeShareVisible(false, generateShareText(celebrations));
});
}
});
}
I have a stateful widget that displays incoming data from a stream. I subscribe in initState() and close in dispose() as usual, and all works fine. When the widget is off-screen, or otherwise not visible, the state continues to update--which works just fine--but I'd rather it didn't, because acquiring the data for its update is somewhat expensive, and I'd rather suspend that when it's not needed and resume when the widget becomes visible again. I've tried using "if (mounted)" in the updater, but that continues to run when the widget is off-screen. Is there any way to detect when the widget is physically visible?I suppose I could simply keep track of which page I'm on and only update when those pages containing the widget are active, but that wouldn't handle the case of the widget being scrolled away or covered by a popup.
--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
final RouteObserver<PageRoute> routeObserver = new RouteObserver<PageRoute>();
class MyClass extends StatefulWidget{
createState() => _MyClassState();
}
class _MyClassState extends State<MyClass> with RouteAware{
@override
void didChangeDependencies() {
super.didChangeDependencies();
routeObserver.subscribe(this, ModalRoute.of(context));
}
@override
void didPopNext() {
// Covering route was popped off the navigator.
print('Popped A route');
}
@override
void didPushNext() {
// Route was pushed onto navigator and is now topmost route.
print('Pushed A Route');
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return null;
}
}
I have a stateful widget that displays incoming data from a stream. I subscribe in initState() and close in dispose() as usual, and all works fine. When the widget is off-screen, or otherwise not visible, the state continues to update--which works just fine--but I'd rather it didn't, because acquiring the data for its update is somewhat expensive, and I'd rather suspend that when it's not needed and resume when the widget becomes visible again. I've tried using "if (mounted)" in the updater, but that continues to run when the widget is off-screen. Is there any way to detect when the widget is physically visible?I suppose I could simply keep track of which page I'm on and only update when those pages containing the widget are active, but that wouldn't handle the case of the widget being scrolled away or covered by a popup.
I have a stateful widget that displays incoming data from a stream. I subscribe in initState() and close in dispose() as usual, and all works fine. When the widget is off-screen, or otherwise not visible, the state continues to update--which works just fine--but I'd rather it didn't, because acquiring the data for its update is somewhat expensive, and I'd rather suspend that when it's not needed and resume when the widget becomes visible again. I've tried using "if (mounted)" in the updater, but that continues to run when the widget is off-screen. Is there any way to detect when the widget is physically visible?I suppose I could simply keep track of which page I'm on and only update when those pages containing the widget are active, but that wouldn't handle the case of the widget being scrolled away or covered by a popup.