我有一个main.dart文件,我正在其中构建一个HomePage()带有抽屉、列表图块和地图的文件。我已经在另一个 dart 文件中实现了谷歌地图插件(参见下面的代码),我只是MapPage()在HomePage().
现在,当我通过调用函数按下抽屉中的列表图块之一时,我需要为相机设置动画goToLoyola(),所以我的问题是,如何从 访问此函数HomePage()?
抱歉,我觉得我的问题很糟糕,但我是新人,仍在学习颤振。谢谢。
class MapPage extends StatefulWidget {
@override
_MapPageState createState() => _MapPageState();
}
class _MapPageState extends State<MapPage> {
GoogleMapController _controller;
LatLng _currentLocation;
CameraPosition _initialCameraLocation;
StreamSubscription _locationSubscription;
Location _location = new Location();
String error;
goToLoyola() {
_controller.animateCamera(CameraUpdate.newCameraPosition(_loyolaCampus));
}
@override
void initState() {
super.initState();
initPlatformState();
_locationSubscription =
_location.onLocationChanged().listen((newLocalData) {
setState(() {
_currentLocation =
LatLng(newLocalData.latitude, newLocalData.longitude);
_initialCameraLocation = CameraPosition(
target: _currentLocation,
zoom: CAMERA_ZOOM,
tilt: CAMERA_TILT,
bearing: CAMERA_BEARING, …Run Code Online (Sandbox Code Playgroud)