How to retain navigation bar in flutter

Viewed 56

I'm having a trouble on how can I retain the navigation bar when going to the next page in flutter, I've been using curved_navigation_bar and when I click dashboard bar it goes to the next page, but the problem is the navigation bar did not retain at all. It would be great if anybody could figure out, thank you so much in advance!.

enter image description here enter image description here

Navigation bar page

Color color = Colors.deepOrangeAccent;
String disp ='';
class HomePage extends State<MyHomePage>{
  @override
  Widget build(BuildContext context){
    return Scaffold(
      backgroundColor: color,
      bottomNavigationBar: CurvedNavigationBar(
        backgroundColor: color,
        items: [
          Icon(Icons.home),
          Icon(Icons.dashboard),
          Icon(Icons.settings)
        ],
        onTap: (index){
          setState(() {
            if (index ==0){
              disp = 'Home';
              color = Colors.blueGrey;
            }
            else if (index ==1){
              disp = 'Dashboard';
              color = Colors.orange;
              Navigator.push(context, MaterialPageRoute(
                builder: (context) =>GoogleMapScreen(),
              ),);
             //----- Execute to Another Page -------
            }
            else{
              disp = 'Settings';
              color = Colors.green;
            }
          });
        },
      ),
    );
  }
}

GoogleMapScreen Page

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

class GoogleMapScreen extends StatefulWidget{
  @override
  _GoogleMapScreenState createState() => _GoogleMapScreenState();
}
class _GoogleMapScreenState extends State<GoogleMapScreen>{
  Set<Marker> _markers = {};
  void _onMapCreated(GoogleMapController controller) {
    setState(() {
      _markers.add(
        Marker(markerId: MarkerId('id-1'),
          position:  LatLng(8.9475, 125.5406),
          infoWindow: InfoWindow(
            title: 'Mackys house',
            snippet: 'A secret Place',
          )
        ),
      );
    });
  }
  @override
  Widget build(BuildContext context){
    return Scaffold(
        appBar: AppBar(
          title: Text('Google Map'),
        ),
        body: GoogleMap(
            onMapCreated:  _onMapCreated,
            markers: _markers,
            initialCameraPosition: CameraPosition(target: LatLng(0.0000, 000.0000),
              zoom: 15,
            ))
         );
       }
     }
1 Answers

UPDATED:

Widget _content = Container();
Color color = Colors.deepOrangeAccent;
String disp ='';
class HomePage extends State<MyHomePage>{
  @override
  Widget build(BuildContext context){
    return Scaffold(
      backgroundColor: color,
      body: _content,
      bottomNavigationBar: CurvedNavigationBar(
        backgroundColor: color,
        items: [
          Icon(Icons.home),
          Icon(Icons.dashboard),
          Icon(Icons.settings)
        ],
        onTap: (index){
          setState(() {
            if (index ==0){
              _content = Container();
            }
            else if (index ==1){
              _content = GoogleMapScreen();
            }
            else{
              _content = Container();
            }
          });
        },
      ),
    );
  }
}
Related