0

I try to reload my page on Navigator.pop then I do something like this :

Flutter - How to get notified when the page I pushed was popped by back button?

But when in my parent page I do :

refresh() async{
  await _immagineBloc.getNomiImmagini(_deviceName);
  setState(() {
    _index = 0;
  });
}

This doesn't return inside selectPhoto init state :

Widget build(BuildContext context) {
  _tabs = getTabs(2);
  return StreamBuilder(
        stream:  _immagineBloc.immaginiName,
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            return new MaterialApp(
                home: DefaultTabController(
                  length: 2,
                  child: Scaffold(
                    appBar: AppBar(
                        centerTitle: true,
                        title: Text('App Drive'),
                        backgroundColor: Colors.blueAccent,
                        bottom: TabBar(
                            isScrollable: false,
                            indicatorColor: Colors.white,
                            onTap: (int index) {
                              _index = index;
                              setIndex(index);
                            },
                            tabs: _tabs)
                    ),
                    body: _index  == 0 ? selectPhoto(snapshot, refresh) : ImageOnServer(snapshot, _deviceName),
                  ),

How can in re enter inside init state of selectPhoto ?

The init state of class where I want to re enter after refresh method call :

 class selectPhoto extends StatefulWidget {
 @override
 final Function() notifyParent;
 selectPhoto(AsyncSnapshot<dynamic> snapshot, @required 
 this.notifyParent){
   _snapshot = snapshot;
 }
 AsyncSnapshot<dynamic> _snapshot;
 _selectPhotoState  createState() => _selectPhotoState (_snapshot);
 }

 class _selectPhotoState extends State<selectPhoto> {
    _selectPhotoState(AsyncSnapshot<dynamic> snapshot) {
    _snapshot = snapshot;
    @override
    void initState() {
       super.initState();
         _fetchNewMedia(_snapshot); // i wan't to re enter here on reload method enter
       }
    }

and in build i have :

 onPressed: () =>
                  Navigator.push(
                      context,
                      MaterialPageRoute(builder: (context) => photoSelection(_imagesIds, _deviceName, _imageNames))
                  ).then((val) {
                    if (val == 'pop') {
                      widget.notifyParent();
                      };
                  })
                        

Please Help ME !

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
matteo
  • 95
  • 1
  • 7

1 Answers1

0

Solved with adding this method to selectPhoto class :

void _reset() {
   Navigator.pushReplacement(
     context,
     PageRouteBuilder(
        transitionDuration: Duration.zero,
        pageBuilder: (_, __, ___) =>MyApp(),
     ),
   );
 }

And called inside :

 onPressed: () =>
              Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => photoSelection(_imagesIds, _deviceName, _imageNames))
              ).then((val) {
                if (val == 'pop') {
                  widget.notifyParent();
                  _reset();
                  };
              })

This return me to my parent widget

matteo
  • 95
  • 1
  • 7