单击PopupMenubutton的特定菜单项时会抛出以下异常,但始终只是第二次:
‘package:Flutter/src/Widgets/navigator.dart’: Failed assertion: line
1846 pos 12: ‘!_deBUGLocked’: is not true.
这里设置:
为了指定菜单项,已经定义了以下类:
class PopupMenuChoice { const PopupMenuChoice({this.Title,this.pageRoute}); final String Title; final MaterialPageRoute pageRoute;}
在Appbar的actions属性中定义PopupMenubutton:
new PopupMenubutton<PopupMenuChoice>( itemBuilder: (BuildContext context) { return _popupMenus.map((PopupMenuChoice choice) { return new PopupMenuItem<PopupMenuChoice>( value: choice,child: new Text(choice.Title),); }).toList(); },onSelected: _popupMenuSelected,),
相应的小部件在下面的类中定义(Appbar在此类的“return new Scaffold”中创建):
class RandomWordsstate extends State<RandomWords> { final _suggestions = <WordPair>[]; final _saved = new Set<WordPair>(); final _popupMenus = <PopupMenuChoice>[]; ...}
正如您所看到的,有用于保存WordPair对象的私有变量,还有用于菜单选项的私有变量.
_popupMenus列表在“构建覆盖”中设置:
@overrIDeWidget build(BuildContext context) { // Setup page routes if (_popupMenus.where((p) => p.Title == 'Saved Suggestions').length == 0) { final _pageRouteSavedSuggestions = new MaterialPageRoute( builder: (context) { final tiles = _saved.map( (pair) { return new ListTile( Title: new Text( pair.asPascalCase,style: _biggerFont,); },); final divIDed = ListTile .divIDeTiles( context: context,tiles: tiles,) .toList(); return new Scaffold( appbar: new Appbar( Title: new Text('Saved Suggestions'),body: new ListVIEw(children: divIDed),); },); _popupMenus.add(new PopupMenuChoice( Title: 'Saved Suggestions',pageRoute: _pageRouteSavedSuggestions)); } if (_popupMenus.where((p) => p.Title == 'TEST Page').length == 0) { final _pageRouteTest = new MaterialPageRoute( builder: (context) { return new Scaffold( appbar: new Appbar( Title: new Text('TEST Page'),body: new Text('Some content...'),); _popupMenus.add( new PopupMenuChoice(Title: 'TEST Page',pageRoute: _pageRouteTest)); } ...
在PopupMenuChoice定义的MaterialPageRoute中,私有变量可能是访问权限(例如_saved).
这里是onSelected的PopupMenubutton的相应事件处理程序:
voID _popupMenuSelected(PopupMenuChoice choice) { Navigator.of(context).push(choice.pageRoute);}
任何人都可以解释为什么抛出这个异常?它怎么能被阻止?
谢谢,
罗杰
在特定菜单项上单击第二次时,调试控制台中的其他信息:
解决方法 你有没有尝试过:E/Flutter (17133): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)]
Unhandled exception: E/Flutter (17133):
‘package:Flutter/src/Widgets/routes.dart’: Failed assertion: line 177
pos 12: ‘!_TransitionCompleter.isCompleted’: Cannot install a
MaterialPageRoute after disposing it. E/Flutter (17133): #0
_AssertionError._doThrowNew (dart:core/runtime/liberrors_patch.dart:37:39) E/Flutter (17133): #1
_AssertionError._throwNew (dart:core/runtime/liberrors_patch.dart:33:5) E/Flutter (17133): #2
TransitionRoute.install (package:Flutter/src/Widgets/routes.dart)
E/Flutter (17133): #3 ModalRoute.install
(package:Flutter/src/Widgets/routes.dart:740:11) E/Flutter (17133): #4
NavigatorState.push
(package:Flutter/src/Widgets/navigator.dart:1444:11) E/Flutter
(17133): #5 RandomWordsstate.build._popupMenuSelected
(file:///D:/Flutter%20Projects/startup_namer/lib/main.dart:166:29)
E/Flutter (17133): #6
_PopupMenubuttonState.showbuttonMenu. (package:Flutter/src/material/popup_menu.dart) E/Flutter (17133): #7
_RootZone.runUnary (dart:async/zone.dart:1381:54) E/Flutter (17133): #8 _FutureListener.handleValue (dart:async/future_impl.dart:129:18) E/Flutter (17133): #9
Future._propagatetoListeners.handleValueCallback
(dart:async/future_impl.dart:633:45) E/Flutter (17133): #10
Future._propagatetoListeners (dart:async/future_impl.dart:662:32)
E/Flutter (17133): #11 Future._completeWithValue
(dart:async/future_impl.dart:477:5) E/Flutter (17133): #12
Future._asyncComplete.
(dart:async/future_impl.dart:507:7) E/Flutter (17133): #13
_microtaskLoop (dart:async/schedule_microtask.dart:41:21) E/Flutter (17133): #14 _startMicrotaskLoop
(dart:async/schedule_microtask.dart:50:5)
voID _popupMenuSelected(PopupMenuChoice choice) { Navigator.push(context,choice.pageRoute);}总结
以上是内存溢出为你收集整理的颤动:使用navigator.dart时失败断言全部内容,希望文章能够帮你解决颤动:使用navigator.dart时失败断言所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)