RenderBox 没有布局:RenderFlex#4a60a 需要绘制(NEEDS-PAINT),需要合成位更新(NEEDS-COMPOSITING-BITS-UPDATE)。
运行代码时,在DEBUG Console
中找到以下显示的错误:\n在2,804ms内重新启动应用。\n[38;5;248m════════渲染库捕获的异常═════════════════════════════════[39;49m\n[38;5;244m在执行布局过程中抛出以下断言:[39;49m\nLeading widget consumes entire tile width. Please use a sized widget.\n\'package:flutter/src/material/list_tile.dart\':\nFailed assertion: line 1353 pos 7: \'tileWidth != leadingSize.width\'\n[38;5;248m无论是断言表明在框架本身中存在错误,还是我们应该提供更多的信息在这个错误消息来帮助您确定和修复潜在的原因。\n在任一情况下,请通过在GitHub上提交一个错误报告来报告这个断言:\n https://github.com/flutter/flutter/issues/new?template=BUG.md\n[39;49m\n[38;5;244m相关的错误引起的小部件是[39;49m\n [38;5;248mListTile[39;49m\n[38;5;244m当抛出异常时,这是堆栈[39;49m\n[38;5;244m#2 _RenderListTile.performLayout[39;49m\n[38;5;244m#3 RenderObject.layout[39;49m\n[38;5;244m#4 RenderPadding.performLayout[39;49m\n[38;5;244m#5 RenderObject.layout[39;49m\n[38;5;244m#6 RenderProxyBoxMixin.performLayout[39;49m\n[38;5;244m...[39;49m\n[38;5;244m处理异常时正在处理的RenderObject是:_RenderListTile#a7a4d relayoutBoundary=up9 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE[39;49m\n[38;5;244mRenderObject: _RenderListTile#a7a4d relayoutBoundary=up9 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE[39;49m\n [38;5;244mparentData: offset=Offset(0.0, 0.0) (can use size)[39;49m\n [38;5;244mconstraints: BoxConstraints(w=0.0, 0.0<=h<=Infinity)[39;49m\n [38;5;244msize: MISSING[39;49m\n [38;5;244mtitle: RenderParagraph#47706 NEEDS-LAYOUT NEEDS-PAINT[39;49m\n [38;5;244mparentData: offset=Offset(0.0, 0.0)[39;49m\n [38;5;244mconstraints: MISSING[39;49m\n [38;5;244msize: MISSING[39;49m\n [38;5;244mtextAlign: left[39;49m\n [38;5;244mtextDirection: ltr[39;49m\n [38;5;244msoftWrap: wrapping at box width[39;49m\n [38;5;244moverflow: clip[39;49m\n [38;5;244mlocale: en_US[39;49m\n [38;5;244mmaxLines: unlimited[39;49m\n [38;5;244mtext: TextSpan[39;49m\n [38;5;244mdebugLabel: (((englishLike subhead 2014).merge(blackCupertino subtitle1)).copyWith).merge(unknown)[39;49m\n [38;5;244minherit: false[39;49m\n [38;5;244mcolor: MaterialColor(primary value: Color(0xff03a9f4))[39;49m\n [38;5;244mfamily: WorkSans[39;49m\n [38;5;244msize: 16.0[39;49m\n [38;5;244mweight: 600[39;49m\n [38;5;244mbaseline: alphabetic[39;49m\n [38;5;244mdecoration: TextDecoration.none[39;49m\n [38;5;244m\"Sign Out\"[39;49m\n [38;5;244mtrailing: RenderSemanticsAnnotations#705a3 relayoutBoundary=up10 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE[39;49m\n [38;5;244mparentData: offset=Offset(0.0, 0.0) (can use size)[39;49m\n [38;5;244mconstraints: BoxConstraints(w=0.0, 0.0<=h<=56.0)[39;49m\n [38;5;244msize: Size(0.0, 24.0)[39;49m\n [38;5;244mchild: RenderExcludeSemantics#60a3d relayoutBoundary=up11 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE[39;49m\n [38;5;244mparentData: (can use size)[39;49m\n [38;5;244mconstraints: BoxConstraints(w=0.0, 0.0<=h<=56.0)[39;49m\n [38;5;244msize: Size(0.0, 24.0)[39;49m\n [38;5;244mexcluding: true[39;49m\n [38;5;244mchild: RenderConstrainedBox#bc3b1 relayoutBoundary=up12 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE[39;49m\n [38;5;244mparentData: (can use size)[39;49m\n [38;5;244mconstraints: BoxConstraints(w=0.0, 0.0<=h<=56.0)[39;49m\n [38;5;244msize: Size(0.0, 24.0)[39;49m\n [38;5;244madditionalConstraints: BoxConstraints(w=24.0, h=24.0)[39;49m\n [38;5;244mchild: RenderPositionedBox#c7d80 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE[39;49m\n [38;5;244mparentData: (can use size)[39;49m\n [38;5;244mconstraints: BoxConstraints(w=0.0, h=24.0)[39;49m\n [38;5;244msize: Size(0.0, 24.0)[39;49m\n [38;5;244malignment: center[39;49m\n [38;5;244mtextDirection: ltr[39;49m\n [38;5;244mwidthFactor: expand[39;49m\n [38;5;244mheightFactor: expand[39;49m\n[38;5;248m════════════════════════════════════════════════════════════════════════════════[39;49m\n[38;5;248m════════渲染库捕获的异常═════════════════════════════════[39;49m\nRenderBox was not laid out: _RenderListTile#a7a4d relayoutBoundary=up9 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n\'package:flutter/src/rendering/box.dart\':\nFailed assertion: line 1694 pos 12: \'hasSize\'\n[38;5;244m相关的错误引起的小部件是[39;49m\n [38;5;248mListTile[39;49m\n[38;5;248m════════════════════════════════════════════════════════════════════════════════[39;49m\n[38;5;248m════════渲染库捕获的异常═════════════════════════════════[39;49m\nRenderBox was not laid out: RenderPadding#0b562 relayoutBoundary=up8 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n\'package:flutter/src/rendering/box.dart\':\nFailed assertion: line 1694 pos 12: \'hasSize\'\n[38;5;244m相关的错误引起的小部件是[39;49m\n [38;5;248mListTile[39;49m\n[38;5;248m════════════════════════════════════════════════════════════════════════════════[39;49m\n[38;5;248m════════渲染库捕获的异常═════════════════════════════════[39;49m\nRenderBox was not laid out: RenderSemanticsAnnotations#7c546 relayoutBoundary=up7 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n\'package:flutter/src/rendering/box.dart\':\nFailed assertion: line 1694 pos 12: \'hasSize\'\n[38;5;244m相关的错误引起的小部件是[39;49m\n [38;5;248mListTile[39;49m\n[38;5;248m════════════════════════════════════════════════════════════════════════════════[39;49m\n[38;5;248m════════渲染库捕获的异常═════════════════════════════════[39;49m\nRenderBox was not laid out: RenderPointerListener#6507d relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n\'package:flutter/src/rendering/box.dart\':\nFailed assertion: line 1694 pos 12: \'hasSize\'\n[38;5;244m相关的错误引起的小部件是[39;49m\n [38;5;248mListTile[39;49m\n[38;5;248m════════════════════════════════════════════════════════════════════════════════[39;49m\n[38;5;248m════════渲染库捕获的异常═════════════════════════════════[39;49m\nRenderBox was not laid out: RenderSemanticsGestureHandler#d89dc relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n\'package:flutter/src/rendering/box.dart\':\nFailed assertion: line 1694 pos 12: \'hasSize\'\n[38;5;244m相关的错误引起的小部件是[39;49m\n [38;5;248mListTile[39;49m\n[38;5;248m════════════════════════════════════════════════════════════════════════════════[39;49m\n[38;5;248m════════渲染库捕获的异常═════════════════════════════════[39;49m\nRenderBox was not laid out: RenderMouseRegion#b5666 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n\'package:flutter/src/rendering/box.dart\':\nFailed assertion: line 1694 pos 12: \'hasSize\'\n[38;5;244m相关的错误引起的小部件是[39;49m\n [38;5;248mListTile[39;49m\n[38;5;248m════════════════════════════════════════════════════════════════════════════════[39;49m\n[38;5;248m════════渲染库捕获的异常═════════════════════════════════[39;49m\nRenderBox was not laid out: RenderSemanticsAnnotations#ace43 relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n\'package:flutter/src/rendering/box.dart\':\nFailed assertion: line 1694 pos 12: \'hasSize\'\n[38;5;244m相关的错误引起的小部件是[39;49m\n [38;5;248mColumn[39;49m\n[38;5;248m════════════════════════════════════════════════════════════════════════════════[39;49m\n[38;5;248m════════渲染库捕获的异常═════════════════════════════════[39;49m\nRenderBox was not laid out: RenderFlex#4e86c relayoutBoundary=up2 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n\'package:flutter/src/rendering/box.dart\':\nFailed assertion: line 1694 pos 12: \'hasSize\'\n[38;5;244m相关的错误引起的小部件是[39;49m\n [38;5;248mContainer[39;49m\n[38;5;248m════════════════════════════════════════════════════════════════════════════════[39;49m\n[38;5;248m════════渲染库捕获的异常═════════════════════════════════[39;49m\nRenderBox was not laid out: RenderFlex#48686 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n\'package:flutter/src/rendering/box.dart\':\nFailed assertion: line 1694 pos 12: \'hasSize\'\n[38;5;244m相关的错误引起的小部件是[39;49m\n [38;5;248mScaffold[39;49m\n[38;5;248m════════════════════════════════════════════════════════════════════════════════[39;49m\n
\n这是我的完整代码:\nimport \'package:flutter/rendering.dart\';\nimport \'../providers/properties.dart\';\nimport \'../providers/cities.dart\';\nimport \'../providers/property.dart\';\nimport \'package:flutter/material.dart\';\nimport \'package:provider/provider.dart\';\nimport \'../widgets/properties_grid.dart\';\nimport \'../app_theme.dart\';\nclass MyHomePage extends StatefulWidget {\n const MyHomePage({Key key}) : super(key: key);\n @override\n _MyHomePageState createState() => _MyHomePageState();\n}\nclass _MyHomePageState extends State with TickerProviderStateMixin {\n int currentTab = 0;\n ScrollController _scrollController = ScrollController();\n bool _showBottomBar = true;\n _scrollListener() {\n if (_scrollController.position.userScrollDirection ==\n ScrollDirection.reverse) {\n setState(() {\n _showBottomBar = false;\n });\n } else if (_scrollController.position.userScrollDirection ==\n ScrollDirection.forward) {\n setState(() {\n _showBottomBar = true;\n });\n }\n }\n var _showOnlyFavorites = false;\n AnimationController animationController;\n bool multiple = true;\n @override\n void initState() {\n animationController = AnimationController(\n duration: const Duration(milliseconds: 2000), vsync: this);\n _scrollController.addListener(_scrollListener);\n super.initState();\n }\n Future getData() async {\n await Future.delayed(const Duration(milliseconds: 0));\n return true;\n }\n @override\n void dispose() {\n animationController.dispose();\n super.dispose();\n }\n @override\n Widget build(BuildContext context) {\n // final properties = Provider.of(context, listen: false);\n return Scaffold(\n resizeToAvoidBottomPadding: false,\n extendBody: true,\n floatingActionButton: FloatingActionButton(\n child: Icon(Icons.add),\n onPressed: () {},\n ),\n floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,\n bottomNavigationBar: AnimatedContainer(\n duration: Duration(milliseconds: 500),\n child: _showBottomBar\n ? BottomAppBar(\n elevation: 0,\n shape: CircularNotchedRectangle(),\n notchMargin: 10,\n child: Container(\n height: 60,\n child: Row(\n mainAxisAlignment: MainAxisAlignment.spaceBetween,\n children: [\n Row(\n crossAxisAlignment: CrossAxisAlignment.start,\n children: [\n MaterialButton(\n padding: EdgeInsets.all(0),\n minWidth: 155,\n onPressed: () {\n setState(() {\n // currentScreen =\n // Chat(); // if user taps on this dashboard tab will be active\n currentTab = 1;\n });\n },\n child: Column(\n mainAxisAlignment: MainAxisAlignment.center,\n children: [\n Icon(\n Icons.home,\n color: currentTab == 1\n ? Colors.blue\n : Colors.grey,\n ),\n Text(\n \'Home\',\n style: TextStyle(\n color: currentTab == 1\n ? Colors.blue\n : Colors.grey,\n ),\n ),\n ],\n ),\n )\n ],\n ),\n // Right Tab bar icons\n Row(\n crossAxisAlignment: CrossAxisAlignment.start,\n children: [\n MaterialButton(\n padding: EdgeInsets.all(0),\n minWidth: 60,\n onPressed: () {\n setState(() {\n // currentScreen =\n // Settings(); // if user taps on this dashboard tab will be active\n currentTab = 3;\n });\n },\n child: Column(\n mainAxisAlignment: MainAxisAlignment.center,\n children: [\n Icon(\n Icons.view_list,\n color: currentTab == 3\n ? Colors.blue\n : Colors.grey,\n ),\n Text(\n \'Property List\',\n style: TextStyle(\n color: currentTab == 3\n ? Colors.blue\n : Colors.grey,\n ),\n ),\n ],\n ),\n ),\n MaterialButton(\n padding: EdgeInsets.all(0),\n minWidth: 77,\n onPressed: () {\n setState(() {\n // currentScreen =\n // Settings(); // if user taps on this dashboard tab will be active\n currentTab = 4;\n });\n },\n child: Column(\n mainAxisAlignment: MainAxisAlignment.center,\n children: [\n Icon(\n Icons.location_searching,\n color: currentTab == 4\n ? Colors.blue\n : Colors.grey,\n ),\n Text(\n \'Map\',\n style: TextStyle(\n color: currentTab == 4\n ? Colors.blue\n : Colors.grey,\n ),\n ),\n ],\n ),\n ),\n ],\n )\n ],\n ),\n ),\n )\n : Container(\n color: Colors.white,\n width: MediaQuery.of(context).size.width,\n ),\n ),\n backgroundColor: AppTheme.white,\n body: Stack(\n children: [\n FutureBuilder(\n future: getData(),\n builder: (BuildContext context, AsyncSnapshot snapshot) {\n if (!snapshot.hasData) {\n return const SizedBox();\n } else {\n return Padding(\n padding:\n EdgeInsets.only(top: MediaQuery.of(context).padding.top),\n child: Column(\n mainAxisAlignment: MainAxisAlignment.center,\n crossAxisAlignment: CrossAxisAlignment.start,\n children: [\n appBar(),\n Expanded(\n child: FutureBuilder(\n future: getData(),\n builder: (BuildContext context,\n AsyncSnapshot snapshot) {\n if (!snapshot.hasData) {\n return const SizedBox();\n } else {\n return ChangeNotifierProvider(\n create: (context) => Properties(),\n child: PropertiesGrid(_showOnlyFavorites),\n );\n }\n },\n ),\n ),\n ],\n ),\n );\n }\n },\n ),\n ],\n ),\n );\n }\n Widget appBar() {\n return SizedBox(\n height: AppBar().preferredSize.height,\n child: Row(\n mainAxisAlignment: MainAxisAlignment.center,\n children: [\n Padding(\n padding: const EdgeInsets.only(top: 8, left: 8),\n child: Container(\n width: AppBar().preferredSize.height - 8,\n height: AppBar().preferredSize.height - 8,\n ),\n ),\n Expanded(\n child: Center(\n child: Padding(\n padding: const EdgeInsets.only(top: 4),\n child:\n Image.asset(\'assets/images/logo.png\', fit: BoxFit.contain),\n ),\n ),\n ),\n Padding(\n padding: const EdgeInsets.only(top: 8, right: 8),\n child: Container(\n width: AppBar().preferredSize.height - 8,\n height: AppBar().preferredSize.height - 8,\n color: Colors.white,\n child: Material(\n color: Colors.transparent,\n child: InkWell(\n borderRadius:\n BorderRadius.circular(AppBar().preferredSize.height),\n child: Icon(\n Icons.location_on,\n color: AppTheme.dark_grey,\n ),\n onTap: () {\n setState(() {\n multiple = !multiple;\n });\n },\n ),\n ),\n ),\n ),\n ],\n ),\n );\n }\n}\n
\n我希望有人能够帮我解决这个问题:)...\n也许我认为SizedBox
的高度有问题,就像这个问题Flutter: RenderBox was not laid out中所提到的,但是我尝试添加高度后仍然遇到了同样的问题...