Flutter 学习
(1)问题:
I/flutter (14598): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (14598): The following assertion was thrown during performLayout():
I/flutter (14598): Horizontal RenderFlex with multiple children has a null textDirection, so the layout order is
I/flutter (14598): undefined.
I/flutter (14598): 'package:flutter/src/rendering/flex.dart': Failed assertion: line 439 pos 18: 'textDirection !=
I/flutter (14598): null'
I/flutter (14598):
I/flutter (14598): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (14598): more information in this error message to help you determine and fix the underlying cause.
I/flutter (14598): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (14598): https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter (14598):
I/flutter (14598): When the exception was thrown, this was the stack:
I/flutter (14598): #2 RenderFlex._debugHasNecessaryDirections (package:flutter/src/rendering/flex.dart:439:18)
I/flutter (14598): #3 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:636:12)
I/flutter (14598): #4 RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (14598): #5 RenderPositionedBox.performLayout (package:flutter/src/rendering/shifted_box.dart:385:13)
I/flutter (14598): #6 RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (14598): #7 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
I/flutter (14598): #8 RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (14598): #9 RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:259:13)
I/flutter (14598): #10 RenderObject.layout (package:flutter/src/rendering/object.dart:1632:7)
I/flutter (14598): #11 RenderView.performLayout (package:flutter/src/rendering/view.dart:151:13)
I/flutter (14598): #12 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1507:7)
I/flutter (14598): #13 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:766:18)
I/flutter (14598): #14 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:329:19)
I/flutter (14598): #15 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:701:13)
I/flutter (14598): #16 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:268:5)
I/flutter (14598): #17 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:988:15)
I/flutter (14598): #18 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:928:9)
I/flutter (14598): #19 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:749:7)
I/flutter (14598): #28 _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
I/flutter (14598): #29 _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
I/flutter (14598): #30 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
I/flutter (14598): (elided 10 frames from class _AssertionError and package dart:async)
I/flutter (14598):
I/flutter (14598): The following RenderObject was being processed when the exception was fired:
I/flutter (14598): RenderFlex#12397 relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (14598): creator: Row ← Center ← DecoratedBox ← ConstrainedBox ← Container ← MyApp ← [root]
I/flutter (14598): parentData: offset=Offset(0.0, 0.0) (can use size)
I/flutter (14598): constraints: BoxConstraints(0.0<=w<=360.0, 0.0<=h<=720.0)
I/flutter (14598): size: MISSING
I/flutter (14598): direction: horizontal
I/flutter (14598): mainAxisAlignment: spaceEvenly
I/flutter (14598): mainAxisSize: max
I/flutter (14598): crossAxisAlignment: center
I/flutter (14598): verticalDirection: down
I/flutter (14598): This RenderObject had the following descendants (showing up to depth 5):
I/flutter (14598): RenderSemanticsAnnotations#aebde NEEDS-LAYOUT NEEDS-PAINT
I/flutter (14598): RenderImage#545f5 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (14598): RenderSemanticsAnnotations#6ac3d NEEDS-LAYOUT NEEDS-PAINT
I/flutter (14598): RenderImage#1a269 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (14598): RenderSemanticsAnnotations#9b689 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (14598): RenderImage#982f3 NEEDS-LAYOUT NEEDS-PAINT
I/flutter (14598): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (14598): Another exception was thrown: 'package:flutter/src/rendering/shifted_box.dart': Failed assertion: line 314 pos 12: 'child.hasSize': is not true.
I/flutter (14598): Another exception was thrown: NoSuchMethodError: The method '<=' was called on null.
(2)场景:
return new Container(
height: 100.0 ,
decoration: new BoxDecoration(color: Colors.white),//装饰 否则页面为黑色
child: new Center(
// child: new Text(
// 'Hello world',
// style:new TextStyle(fontSize: 30,color: Colors.black),
// textDirection: TextDirection.ltr,
//
// ),
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new Image.asset('images/pic.jpg',),
new Image.asset('images/pic.jpg',),
new Image.asset('images/pic.jpg',)
],
),
),
);
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
textDirection: TextDirection.ltr,
children: <Widget>[
new Image.asset('images/pic.jpg',),
new Image.asset('images/pic.jpg',),
new Image.asset('images/pic.jpg',)
],
),
出现
I/flutter (14598): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter (14598): The following message was thrown during layout:
I/flutter (14598): A RenderFlex overflowed by 1941 pixels on the right.
I/flutter (14598):
I/flutter (14598): The overflowing RenderFlex has an orientation of Axis.horizontal.
I/flutter (14598): The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
I/flutter (14598): black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
I/flutter (14598): Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
I/flutter (14598): RenderFlex to fit within the available space instead of being sized to their natural size.
I/flutter (14598): This is considered an error condition because it indicates that there is content that cannot be
I/flutter (14598): seen. If the content is legitimately bigger than the available space, consider clipping it with a
I/flutter (14598): ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
I/flutter (14598): like a ListView.
I/flutter (14598): The specific RenderFlex in question is:
I/flutter (14598): RenderFlex#12397 relayoutBoundary=up1 OVERFLOWING
I/flutter (14598): creator: Row ← Center ← DecoratedBox ← ConstrainedBox ← Container ← MyApp ← [root]
I/flutter (14598): parentData: offset=Offset(0.0, 68.5) (can use size)
I/flutter (14598): constraints: BoxConstraints(0.0<=w<=360.0, 0.0<=h<=720.0)
I/flutter (14598): size: Size(360.0, 583.0)
I/flutter (14598): direction: horizontal
I/flutter (14598): mainAxisAlignment: spaceEvenly
I/flutter (14598): mainAxisSize: max
I/flutter (14598): crossAxisAlignment: center
I/flutter (14598): textDirection: ltr
I/flutter (14598): verticalDirection: down
I/flutter (14598): ◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
I/flutter (14598): ════════════════════════════════════════════════════════════════════════════════════════════
设置图片宽度
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
textDirection: TextDirection.ltr,
children: <Widget>[
new Image.asset('images/pic.jpg',width: 100.0),
new Image.asset('images/pic.jpg',width: 100.0),
new Image.asset('images/pic.jpg',width: 100.0)
],
),