我在进入下一页时如何保留导航栏有问题,我一直在使用 curved_navigation_bar
,当我点击仪表板栏时,它会转到下一页,但是问题是导航栏根本没有保留。如果有人能弄清楚就太好了,在此先感谢您!
导航栏页面
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 页面
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,
))
);
}
}
答案 0 :(得分:1)
更新:
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();
}
});
},
),
);
}
}