我已经面临这个问题一个星期了,但无法解决。我有一个带有3个选项卡的TabBarView,所有这些选项卡都是使用带文本的statefulwidgets构建的。我已经用只带有文本小部件的类重新创建了问题。
E/flutter ( 5455): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The getter 'focusScopeNode' was called on null.
E/flutter ( 5455): Receiver: null
E/flutter ( 5455): Tried calling: focusScopeNode
E/flutter ( 5455): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
E/flutter ( 5455): #1 Route.didPush.<anonymous closure> (package:flutter/src/widgets/navigator.dart:139:17)
E/flutter ( 5455): #2 _rootRunUnary (dart:async/zone.dart:1134:38)
E/flutter ( 5455): #3 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter ( 5455): #4 _FutureListener.handleValue (dart:async/future_impl.dart:139:18)
E/flutter ( 5455): #5 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:680:45)
E/flutter ( 5455): #6 Future._propagateToListeners (dart:async/future_impl.dart:709:32)
E/flutter ( 5455): #7 Future._completeWithValue (dart:async/future_impl.dart:524:5)
E/flutter ( 5455): #8 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:554:7)
E/flutter ( 5455): #9 _rootRun (dart:async/zone.dart:1126:13)
E/flutter ( 5455): #10 _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter ( 5455): #11 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
E/flutter ( 5455): #12 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
E/flutter ( 5455): #13 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
E/flutter ( 5455): #14 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
E/flutter ( 5455):
我已经阅读了 https://github.com/flutter/flutter/issues/45539 还有这个 Flutter - NoSuchMethodError: The getter 'focusScopeNode' was called on null 但是我仍然找不到解决问题的方法,也许我还没有找到正确的实现方法。
调试告诉我这是发生问题的确切时间: 在flutter系统类navigator.dart中
@protected
@mustCallSuper
TickerFuture didPush() {
return TickerFuture.complete()..then<void>((void _) {
navigator.focusScopeNode.requestFocus(); // HERE IS WHERE HELL IS UNLEASHED
});
}
我的课程是 1.创建tabbarview的类:
class Lounge extends StatefulWidget {
const Lounge({ Key key }) : super(key: key);
@override
_LoungeState createState() => _LoungeState();
}
class _LoungeState extends State<Lounge> with SingleTickerProviderStateMixin {
TabController _tabController;
List<Widget> myWidgetList;
List<Tab> myTabs = <Tab>[
new Tab(icon: Icon(Icons.people)),
new Tab(icon: Icon(Icons.location_on)),
new Tab(icon: Icon(Icons.edit)),
];
@override
void initState() {
super.initState();
_tabController = TabController(vsync: this, length: myTabs.length);
myWidgetList = <Widget>[Explore(),MyMap(),Edit()];
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: TabBar(
controller: _tabController,
tabs: myTabs,
),
),
body: TabBarView(
physics: NeverScrollableScrollPhysics(),
controller: _tabController,
children: myWidgetList
)
);
}
}
构建选项卡的所有选项卡Material Widgets如下所示(探索是第一个)
class Explore extends StatefulWidget{
@override
_ExploreState createState()=> _ExploreState();
}
class _ExploreState extends State<Explore> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Explore questionsets',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(backgroundColor: Colors.blue[50],
body: Center(
child: Text("explore")
),
)
);
}
}
我什至看到了这个https://gitmemory.com/issue/flutter/flutter/42829/552941774 这似乎不是我想采取的方式(尽管这是唯一可行的方法)。对你的帮助表示感谢。谢谢!