我有使用IndexedStack的BottomNavigationBar,以便在更改页面时不会重新加载我的googleMaps。在第一页中,我有一个按钮,在第二页中,我有googleMaps。当我按下按钮时,我希望页面更改为第二页,然后在其中调用函数。例如,缩放到新位置。
我正在使用范围模型来处理状态。
我已经找到了一种更改页面的方法,但是我不确定该如何使用GoogleMapsController。我将其提升为ScopedModel类,但现在在打开新路线并关闭它并尝试进行更改时遇到错误,请按一下按钮以转到地图上的某个位置:
I/flutter ( 8784): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter ( 8784): The following NoSuchMethodError was thrown while handling a gesture:
I/flutter ( 8784): The method 'animateCamera' was called on null.
I/flutter ( 8784): Receiver: null
I/flutter ( 8784): Tried calling: animateCamera(Instance of 'CameraUpdate')
I/flutter ( 8784):
I/flutter ( 8784): When the exception was thrown, this was the stack:
I/flutter ( 8784): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5)
I/flutter ( 8784): #1 AppStateModel.goToMapLocation
package:restapoints/state/app_state.dart:57
I/flutter ( 8784): #2 RestaurantInfoPageState.build.<anonymous closure>.<anonymous closure>
package:restapoints/pages/restaurant_page.dart:56
I/flutter ( 8784): #3 _InkResponseState._handleTap
package:flutter/…/material/ink_well.dart:507
I/flutter ( 8784): #4 _InkResponseState.build.<anonymous closure>
package:flutter/…/material/ink_well.dart:562
I/flutter ( 8784): #5 GestureRecognizer.invokeCallback
package:flutter/…/gestures/recognizer.dart:102
I/flutter ( 8784): #6 TapGestureRecognizer._checkUp
package:flutter/…/gestures/tap.dart:242
I/flutter ( 8784): #7 TapGestureRecognizer.acceptGesture
package:flutter/…/gestures/tap.dart:204
I/flutter ( 8784): #8 GestureArenaManager.sweep
package:flutter/…/gestures/arena.dart:156
I/flutter ( 8784): #9 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent
package:flutter/…/gestures/binding.dart:184
I/flutter ( 8784): #10 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent
package:flutter/…/gestures/binding.dart:158
I/flutter ( 8784): #11 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent
package:flutter/…/gestures/binding.dart:138
I/flutter ( 8784): #12 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue
package:flutter/…/gestures/binding.dart:101
I/flutter ( 8784): #13 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket
package:flutter/…/gestures/binding.dart:85
I/flutter ( 8784): #14 _invoke1 (dart:ui/hooks.dart:168:13)
I/flutter ( 8784): #15 _dispatchPointerDataPacket (dart:ui/hooks.dart:122:5)
I/flutter ( 8784):
I/flutter ( 8784): Handler: onTap
I/flutter ( 8784): Recognizer:
I/flutter ( 8784): TapGestureRecognizer#5de3a(debugOwner: GestureDetector, state: ready, won arena, finalPosition:
I/flutter ( 8784): Offset(320.8, 298.5), sent tap down)
I/flutter ( 8784): ════════════════════════════════════════════════════════════════════════════════════════════════════
谢谢!
答案 0 :(得分:0)
这是创建窗口小部件时调用的第一个方法,它必须为StatefullWidget
@override
void initState() {
// You can call your zooom to new location function here
super.initState();
}
答案 1 :(得分:0)
通过将ScopedModel移到小部件树顶部解决了此错误:
AppStateModel model = AppStateModel();
runApp(
ScopedModel<AppStateModel>(
model: model,
child: MaterialApp(
home: HomeWidget(),
),
),
);
因此,对于任何在tabNav中重新加载googlemaps遇到麻烦的人,请使用索引堆栈并将所有页面包装到Navigator中。然后将GooglemapsController提升到ScopedModel并将ScopedModel(或任何其他状态管理模型)放置到应用程序的根目录。