第二个选项卡有一个页面,其中还有两个选项卡.现在的问题是我是否直接从tab0切换到tab2.我收到以下错误:
Flutter: ══╡ EXCEPTION CAUGHT BY WidgetS liBRARY ╞═══════════════════════════════════════════════════════════Flutter: The following assertion was thrown while finalizing the Widget tree:Flutter: 'package:Flutter/src/Widgets/scroll_position.dart': Failed assertion: line 627 pos 12: 'pixels !=Flutter: null': is not true.Flutter:Flutter: Either the assertion indicates an error in the framework itself,or we should provIDe substantiallyFlutter: more information in this error message to help you determine and fix the underlying cause.Flutter: In either case,please report this assertion by filing a BUG on GitHub:Flutter: https://github.com/Flutter/Flutter/issues/newFlutter:Flutter: When the exception was thrown,this was the stack:Flutter: #2 Scrollposition.dispose (package:Flutter/src/Widgets/scroll_position.dart)Flutter: #3 ScrollpositionWithSingleContext.dispose (package:Flutter/src/Widgets/scroll_position_with_single_context.dart:260:11)Flutter: #4 ScrollableState.dispose (package:Flutter/src/Widgets/scrollable.dart:324:14)Flutter: #5 StatefulElement.unmount (package:Flutter/src/Widgets/framework.dart:3821:12)Flutter: #6 _InactiveElements._unmount (package:Flutter/src/Widgets/framework.dart:1697:13)Flutter: #7 _InactiveElements._unmount.<anonymous closure> (package:Flutter/src/Widgets/framework.dart:1695:7)Flutter: #8 ComponentElement.visitChildren (package:Flutter/src/Widgets/framework.dart:3676:14)Flutter: #9 _InactiveElements._unmount (package:Flutter/src/Widgets/framework.dart:1693:13)
这是应用程序本身
Page : main.dartimport 'package:Flutter/material.dart';import "TabsPage.dart";voID main() => runApp(new MyApp());class MyApp extends StatelessWidget { // This Widget is the root of your application. @overrIDe Widget build(BuildContext context) { return new MaterialApp( Title: 'Flutter Demo',theme: new themeData( primarySwatch: colors.blue,),home: new MyHomePage(Title: 'Flutter Demo Home Page'),); }}class MyHomePage extends StatefulWidget { MyHomePage({Key key,this.Title}) : super(key: key); final String Title; @overrIDe _MyHomePageState createState() => new _MyHomePageState();}class _MyHomePageState extends State<MyHomePage> with SingleTickerProvIDerStateMixin { TabController _tabController; var tabbarVIEw; var bottomNavigationbar; voID initializeTabs() { _tabController = new TabController(vsync: this,length: 3); } Widget getBottomNavigationbar() { bottomNavigationbar = new Material( child: new Tabbar(controller: _tabController,tabs: <Tab>[ new Tab(text: "PageA" ),new Tab(text: "PageB"),new Tab(text: "PageC"),])); return bottomNavigationbar; } @overrIDe voID initState() { super.initState(); initializeTabs(); } @overrIDe Widget build(BuildContext context) { return new Scaffold( appbar: new Appbar( Title: new Text("Tabs demo"),automaticallyImplyLeading: false,bottomNavigationbar: getBottomNavigationbar(),//Add the bottom Navigation bar body: new TabbarVIEw(controller: _tabController,children: <Widget>[ new Text("PageA"),new Mytest(),new Text("PageC"),]),//The container that will display the pages ); }}
这是第二页
import 'package:Flutter/material.dart';class MyTest extends StatefulWidget { Mytest(); @overrIDe MyTestState createState() => new MyTestState();} class MyTestState extends State<MyTest> with SingleTickerProvIDerStateMixin,RouteAware { bool isAlive; TabController _tabController; var tabbarVIEw; MyTestState(); @overrIDe voID initState() { super.initState(); _tabController = new TabController(vsync: this,length: 2,initialindex: 1); } @overrIDe voID dispose() { _tabController.dispose(); super.dispose(); } @overrIDe Widget build(BuildContext context) { var scaffold = Scaffold( appbar: new Appbar( automaticallyImplyLeading: false,bottom: new PreferredSize( preferredSize: new Size(200.0,15.0),child: new Container( wIDth: 200.0,child: new Tabbar( controller: _tabController,tabs: [ new Container( child: new Tab(text: 'TabA'),new Container( child: new Tab(text: 'TabB'),],body: new TabbarVIEw(controller: _tabController,children: <Widget>[ new Text("Hello World in TabA"),new Text("Hello World in TabB"),//The container that will display the pages ); return scaffold; }}
如果我从第二页的正文中替换TabbarVIEw,则不会发生此问题
解决方法 我很久以前就报告了这个BUGhttps://github.com/flutter/flutter/issues/11267
https://github.com/flutter/flutter/issues/11350
我意识到你不能拥有嵌套的脚手架.如果您嵌套Scaffolds,则行为将变为未定义且不受颤振团队的支持.
重构您的应用程序,以便Scaffold不再嵌套
总结以上是内存溢出为你收集整理的dart – 在flutter中从tab1切换到tab3会产生错误 – 最小颤振App全部内容,希望文章能够帮你解决dart – 在flutter中从tab1切换到tab3会产生错误 – 最小颤振App所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)