我想从我的应用导航至google_maps。但是,当我单击映射到googe_map页面的Iconbutton时,会出现黑屏。
这是Iconbutton的代码段。
leading: new IconButton(
tooltip: 'Previous choice',
icon: const Icon(
Icons.location_on,
size: 45,
),
onPressed: () {
print('button clicked');
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => MapAdd(),
));
},
),
编辑:MapAdd()的代码。当我将此代码作为独立实体运行时,它会运行并显示地图,但是当我将其与其他页面结合使用时,当我通过IconButton导航到该页面时,就会出现空白屏幕。
class MapAdd extends StatefulWidget {
@override
_MapAddState createState() => _MapAddState();
}
class _MapAddState extends State<MapAdd> {
Completer<GoogleMapController> _controller = Completer();
GoogleMapController mapController;
static const LatLng _center = const LatLng(27.7172, 85.3240);
final Set<Marker> _markers = {};
LatLng _lastMapPosition = _center;
MapType _currentMapType = MapType.normal;
@override
void initState() {
super.initState();
PermissionHandler()
.checkPermissionStatus(PermissionGroup.locationWhenInUse)
.then(_updateStatus);
}
void _onMapTypeButtonPressed() {
setState(() {
_currentMapType = _currentMapType == MapType.normal
? MapType.satellite
: MapType.normal;
});
}
void _onAddMarkerButtonPressed() {
setState(() {
_markers.add(Marker(
// This marker id can be anything that uniquely identifies each marker.
markerId: MarkerId(_lastMapPosition.toString()),
draggable: true,
position: _lastMapPosition,
infoWindow: InfoWindow(
title: 'Really cool place',
snippet: '5 Star Rating',
),
icon: BitmapDescriptor.defaultMarker,
));
});
}
void _onCameraMove(CameraPosition position) {
_lastMapPosition = position.target;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
),
),
body: Stack(
children: <Widget>[
Container(
child: GoogleMap(
onMapCreated: (GoogleMapController controller) {
mapController = controller;
},
initialCameraPosition: CameraPosition(
target: _center,
zoom: 11.0,
),
mapType: _currentMapType,
markers: _markers,
rotateGesturesEnabled: true,
scrollGesturesEnabled: true,
tiltGesturesEnabled: true,
onCameraMove: _onCameraMove,
),
),
],
),
),
);
}
}
编辑:当我删除按钮和文本字段时,导航有效。但是,当我在“ body:Stack”中添加以下部分时,它不起作用:
Padding(
padding: const EdgeInsets.all(18.0),
child: Column(
children: <Widget>[
TextField(
textInputAction: TextInputAction.search,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
hintText: "Select Delivery Address",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(25.0)),
contentPadding: EdgeInsets.only(left: 15.0, top: 15.0),
suffixIcon: IconButton(
icon: Icon(Icons.search),
onPressed: () {
print("Map button clicked");
},
iconSize: 30.0,
)),
),
SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FloatingActionButton(
onPressed: _onMapTypeButtonPressed,
materialTapTargetSize: MaterialTapTargetSize.padded,
backgroundColor: Colors.green,
child: const Icon(Icons.map, size: 36.0),
),
],
),
SizedBox(height: 16.0),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FloatingActionButton(
onPressed: _onAddMarkerButtonPressed,
materialTapTargetSize: MaterialTapTargetSize.padded,
backgroundColor: Colors.green,
child: const Icon(Icons.add_location, size: 36.0),
),
],
),
],
),
),