i am pushing the new widget by below code:

Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (BuildContext context) => BigPhoto(widget.images)))
          },

After the new page opened then when I click to back button which android physical back button then the app closing instead of popping back. How can i fix it?

full implementation:

return Stack(
  children: <Widget>[
    StreamBuilder<int>(
      stream: bloc.currentItemStream,
      builder: (context, snapshot) {
        return GestureDetector(
          onTap: () => {
            Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (BuildContext context) => BigPhoto(widget.images, snapshot.data - 1)))
          },
          child: AspectRatio(
              aspectRatio: 411 / 308,
              child: PageView.builder(
                physics: BouncingScrollPhysics(),
                itemCount: widget.images.length,
                onPageChanged: (value) {
                  bloc.changeCurrentItemIndex(value + 1);
                },
                itemBuilder: (context, position) {
                  return FittedBox(
                    fit: BoxFit.cover,
                    child: Container(
                      child: Image.network(
                        "{widget.images[position]}",
                        fit: BoxFit.cover,
                      ),
                    ),
                  );
                },
              )),
        );
      }
    ),
    Positioned(
      left: 26,
      bottom: 9,
      child: StreamBuilder<int>(
          stream: bloc.currentItemStream,
          builder: (context, snapshot) {
            return Container(
              padding: const EdgeInsets.only(
                  bottom: 3, top: 3, left: 7, right: 7),
              decoration: BoxDecoration(
                border: Border.all(width: 3.0, color: Colors.white),
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(20.0)),
              ),
              child: Text(
                " ${snapshot.data} / ${widget.images.length}",
                style: TextStyle(
                    fontSize: 11.0,
                    fontFamily: 'Roboto-Regular',
                    backgroundColor: Colors.white),
              ),
            );
          }),
    ),
  ],
);


Solution 1: Sameh Khemira

I would suggest this solution: You can unable the return with the physical back button on the page that you are navigating to, by putting the build widget into a WillPopScoop widget and set onWillPop to false. And implement your own back button just like that.

Widget build(BuildContext context) {
WillPopScope(
  onWillPop: () async => false,
  child: Material(
      child: Scaffold(
          appBar: AppBar(
          leading: IconButton(
                  icon: Icon(Icons.arrow_back_ios),
                  onPressed: () {
                    _goBack(context);
                  })),
          body : Image.asset("YOUR_URL_IMAGE"));

the _goback() methode :

_goBack(BuildContext context) {
Navigator.pop(context); }