import 'package:flutter/material.dart';
// import 'package:';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget
{ @override
Widget build(BuildContext context) {
return Center(
child: Container(
padding: EdgeInsets.only(left: 10.0,top: 40.0),
alignment: Alignment.center,
color: Colors.lightGreen,
child: Column(
children: <Widget>
[ Row(
children: <Widget>[
Expanded(child: Text(
"Spice jet",
textDirection: TextDirection.ltr,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 35.0,
fontFamily: 'railway',
fontWeight: FontWeight.w700,
color: Colors.white),)),
Expanded(child:Text(
"Spice jet",
textDirection: TextDirection.ltr,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 35.0,
fontFamily: 'railway',
fontWeight: FontWeight.w700,
color: Colors.white),
)
),
],),
Row(
children: <Widget>[
Expanded(
child: Text(
"Spice jet",
textDirection: TextDirection.ltr,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 35.0,
fontFamily: 'railway',
fontWeight: FontWeight.w700,
color: Colors.white),)),
Expanded(child:Text(
"Spice jet",
textDirection: TextDirection.ltr,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 35.0,
fontFamily: 'railway',
fontWeight: FontWeight.w700,
color: Colors.white),
)
),
],
),
futo()
],
)));
}}
class futo extends StatelessWidget {
@override
Widget build(BuildContext context)
{
AssetImage assetImage = AssetImage('assets/images/34.png');
Image image = Image(image: assetImage);
return Container(child: image,);
}
}
显示的错误是
√构建了build\host\output\apk\debug\app-debug.apk。调试服务侦听ws://127.0.0.1:55447/4v1zroR_P-8=/ws正在将文件同步到设备Infinix X680B...I/GED ( 4227):ged_boost_gpu_freq,level 100,eOrigin 2,final_idx 2,oppidx_max 2,oppidx_min 0
渲染库=====================================================时捕获到========异常在performLayout()过程中引发了以下断言:具有多个子级的水平RenderFlex的textDirection为空,因此布局顺序未定义。‘'package:flutter/src/rendering/flex.dart':断言失败:第453行pos 18:'textDirection != null’
要么断言表明框架本身存在错误,要么我们应该在此错误消息中提供更多信息,以帮助您确定和修复潜在原因。在任何一种情况下,请通过在GitHub:https://github.com/flutter/flutter/issues/new?template=2_bug.md上提交错误来报告此断言
The relevant error-causing widget was:
Row file:///D:/helloworld/lib/main.dart:15:17
When the exception was thrown, this was the stack:
#2 RenderFlex._debugHasNecessaryDirections (package:flutter/src/rendering/flex.dart:453:18)
#3 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:918:12)
#4 RenderObject.layout (package:flutter/src/rendering/object.dart:1779:7)
#5 ChildLayoutHelper.layoutChild (package:flutter/src/rendering/layout_helper.dart:54:11)
#6 RenderFlex._computeSizes (package:flutter/src/rendering/flex.dart:829:43)
...
The following RenderObject was being processed when the exception was fired: RenderFlex#8fff6 relayoutBoundary=up5 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
... constraints: BoxConstraints(0.0<=w<=350.0, 0.0<=h<=Infinity)
... size: MISSING
... direction: horizontal
... mainAxisAlignment: start
... mainAxisSize: max
... crossAxisAlignment: center
... verticalDirection: down
RenderObject: RenderFlex#8fff6 relayoutBoundary=up5 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
constraints: BoxConstraints(0.0<=w<=350.0, 0.0<=h<=Infinity)
size: MISSING
direction: horizontal
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: center
verticalDirection: down
child 1: RenderParagraph#ccbd1 NEEDS-LAYOUT NEEDS-PAINT parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
constraints: MISSING
size: MISSING
textAlign: start
textDirection: ltr
... softWrap: wrapping at box width
... overflow: clip
... maxLines: unlimited
... text: TextSpan
... inherit: true
... color: Color(0xffffffff)
... family: railway
... size: 35.0
... weight: 700
... decoration: TextDecoration.none
... "Spice jet"
... child 2: RenderParagraph#23d27 NEEDS-LAYOUT NEEDS-PAINT
... parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
... constraints: MISSING
... size: MISSING
... textAlign: start
... textDirection: ltr
... softWrap: wrapping at box width
... overflow: clip
... maxLines: unlimited
... text: TextSpan
... inherit: true
... color: Color(0xffffffff)
... family: railway
... size: 35.0
... weight: 700
... decoration: TextDecoration.none
... "Spice jet"
====================================================================================================
======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
RenderBox was not laid out: RenderFlex#8fff6 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1930 pos 12: 'hasSize'
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
The relevant error-causing widget was:
Column file:///D:/helloworld/lib/main.dart:13:20
When the exception was thrown, this was the stack:
#2 RenderBox.size (package:flutter/src/rendering/box.dart:1930:12)
#3 ChildLayoutHelper.layoutChild (package:flutter/src/rendering/layout_helper.dart:55:18)
#4 RenderFlex._computeSizes (package:flutter/src/rendering/flex.dart:829:43)
#5 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:931:32)
#6 RenderObject.layout (package:flutter/src/rendering/object.dart:1779:7)
...
The following RenderObject was being processed when the exception was fired: RenderFlex#494fd relayoutBoundary=up4 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: offset=Offset(0.0, 0.0) (can use size)
... constraints: BoxConstraints(0.0<=w<=350.0, 0.0<=h<=732.0)
... size: MISSING
... direction: vertical
... mainAxisAlignment: start
... mainAxisSize: max
... crossAxisAlignment: center
... verticalDirection: down
RenderObject: RenderFlex#494fd relayoutBoundary=up4 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0) (can use size)
constraints: BoxConstraints(0.0<=w<=350.0, 0.0<=h<=732.0)
size: MISSING
direction: vertical
mainAxisAlignment: start
mainAxisSize: max
crossAxisAlignment: center
verticalDirection: down
... child 1: RenderFlex#8fff6 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
... constraints: BoxConstraints(0.0<=w<=350.0, 0.0<=h<=Infinity)
... size: MISSING
... direction: horizontal
... mainAxisAlignment: start
... mainAxisSize: max
... crossAxisAlignment: center
... verticalDirection: down
... child 1: RenderParagraph#ccbd1 NEEDS-LAYOUT NEEDS-PAINT
... parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
... constraints: MISSING
... size: MISSING
... textAlign: start
... textDirection: ltr
... softWrap: wrapping at box width
... overflow: clip
... maxLines: unlimited
... text: TextSpan
... inherit: true
... color: Color(0xffffffff)
... family: railway
... size: 35.0
... weight: 700
... decoration: TextDecoration.none
... "Spice jet"
... child 2: RenderParagraph#23d27 NEEDS-LAYOUT NEEDS-PAINT
... parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
... constraints: MISSING
... size: MISSING
... textAlign: start
... textDirection: ltr
... softWrap: wrapping at box width
... overflow: clip
... maxLines: unlimited
... text: TextSpan
... inherit: true
... color: Color(0xffffffff)
... family: railway
... size: 35.0
... weight: 700
... decoration: TextDecoration.none
... "Spice jet"
... child 2: RenderFlex#3f52e NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
... constraints: MISSING
... size: MISSING
... direction: horizontal
... mainAxisAlignment: start
... mainAxisSize: max
... crossAxisAlignment: center
... verticalDirection: down
... child 1: RenderParagraph#40422 NEEDS-LAYOUT NEEDS-PAINT
... parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
... constraints: MISSING
... size: MISSING
... textAlign: start
... textDirection: ltr
... softWrap: wrapping at box width
... overflow: clip
... maxLines: unlimited
... text: TextSpan
... inherit: true
... color: Color(0xffffffff)
... family: railway
... size: 35.0
... weight: 700
... decoration: TextDecoration.none
... "Spice jet"
... child 2: RenderParagraph#62cfe NEEDS-LAYOUT NEEDS-PAINT
... parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
... constraints: MISSING
... size: MISSING
... textAlign: start
... textDirection: ltr
... softWrap: wrapping at box width
... overflow: clip
... maxLines: unlimited
... text: TextSpan
... inherit: true
... color: Color(0xffffffff)
... family: railway
... size: 35.0
... weight: 700
... decoration: TextDecoration.none
... "Spice jet"
... child 3: RenderSemanticsAnnotations#43cb8 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
... constraints: MISSING
... size: MISSING
... child: RenderImage#39fe6 NEEDS-LAYOUT NEEDS-PAINT
... parentData: <none>
... constraints: MISSING
... size: MISSING
... image: null
... alignment: Alignment.center
... invertColors: false
... filterQuality: low
====================================================================================================
======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
'package:flutter/src/rendering/shifted_box.dart': Failed assertion: line 348 pos 12: 'child!.hasSize': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
The relevant error-causing widget was:
Container file:///D:/helloworld/lib/main.dart:9:16
When the exception was thrown, this was the stack:
#2 RenderAligningShiftedBox.alignChild (package:flutter/src/rendering/shifted_box.dart:348:12)
#3 RenderPositionedBox.performLayout (package:flutter/src/rendering/shifted_box.dart:442:7)
#4 RenderObject.layout (package:flutter/src/rendering/object.dart:1779:7)
#5 RenderPadding.performLayout (package:flutter/src/rendering/shifted_box.dart:233:12)
#6 RenderObject.layout (package:flutter/src/rendering/object.dart:1779:7)
...
The following RenderObject was being processed when the exception was fired: RenderPositionedBox#6f70a relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: offset=Offset(0.0, 0.0) (can use size)
... constraints: BoxConstraints(0.0<=w<=350.0, 0.0<=h<=732.0)
... size: Size(350.0, 732.0)
... alignment: Alignment.center
... widthFactor: expand
... heightFactor: expand
RenderObject: RenderPositionedBox#6f70a relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
parentData: offset=Offset(0.0, 0.0) (can use size)
constraints: BoxConstraints(0.0<=w<=350.0, 0.0<=h<=732.0)
size: Size(350.0, 732.0)
alignment: Alignment.center
widthFactor: expand
heightFactor: expand
... child: RenderFlex#494fd relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: offset=Offset(0.0, 0.0) (can use size)
... constraints: BoxConstraints(0.0<=w<=350.0, 0.0<=h<=732.0)
... size: MISSING
... direction: vertical
... mainAxisAlignment: start
... mainAxisSize: max
... crossAxisAlignment: center
... verticalDirection: down
... child 1: RenderFlex#8fff6 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
... constraints: BoxConstraints(0.0<=w<=350.0, 0.0<=h<=Infinity)
... size: MISSING
... direction: horizontal
... mainAxisAlignment: start
... mainAxisSize: max
... crossAxisAlignment: center
... verticalDirection: down
... child 1: RenderParagraph#ccbd1 NEEDS-LAYOUT NEEDS-PAINT
... parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
... constraints: MISSING
... size: MISSING
... textAlign: start
... textDirection: ltr
... softWrap: wrapping at box width
... overflow: clip
... maxLines: unlimited
... text: TextSpan
... inherit: true
... color: Color(0xffffffff)
... family: railway
... size: 35.0
... weight: 700
... decoration: TextDecoration.none
... "Spice jet"
... child 2: RenderParagraph#23d27 NEEDS-LAYOUT NEEDS-PAINT
... parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
... constraints: MISSING
... size: MISSING
... textAlign: start
... textDirection: ltr
... softWrap: wrapping at box width
... overflow: clip
... maxLines: unlimited
... text: TextSpan
... inherit: true
... color: Color(0xffffffff)
... family: railway
... size: 35.0
... weight: 700
... decoration: TextDecoration.none
... "Spice jet"
... child 2: RenderFlex#3f52e NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
... constraints: MISSING
... size: MISSING
... direction: horizontal
... mainAxisAlignment: start
... mainAxisSize: max
... crossAxisAlignment: center
... verticalDirection: down
... child 1: RenderParagraph#40422 NEEDS-LAYOUT NEEDS-PAINT
... parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
... constraints: MISSING
... size: MISSING
... textAlign: start
... textDirection: ltr
... softWrap: wrapping at box width
... overflow: clip
... maxLines: unlimited
... text: TextSpan
... inherit: true
... color: Color(0xffffffff)
... family: railway
... size: 35.0
... weight: 700
... decoration: TextDecoration.none
... "Spice jet"
... child 2: RenderParagraph#62cfe NEEDS-LAYOUT NEEDS-PAINT
... parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
... constraints: MISSING
... size: MISSING
... textAlign: start
... textDirection: ltr
... softWrap: wrapping at box width
... overflow: clip
... maxLines: unlimited
... text: TextSpan
... inherit: true
... color: Color(0xffffffff)
... family: railway
... size: 35.0
... weight: 700
... decoration: TextDecoration.none
... "Spice jet"
... child 3: RenderSemanticsAnnotations#43cb8 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
... parentData: offset=Offset(0.0, 0.0); flex=null; fit=null
... constraints: MISSING
... size: MISSING
... child: RenderImage#39fe6 NEEDS-LAYOUT NEEDS-PAINT
... parentData: <none>
... constraints: MISSING
... size: MISSING
... image: null
... alignment: Alignment.center
... invertColors: false
... filterQuality: low
发布于 2021-08-01 16:21:56
塔巴,我想你错过了flutter App
的主要structure
。你需要用MaterialApp
把所有的东西都包装起来,然后每个页面都有Scaffold
。
在你的MyApp
上,这样做。
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Container(
padding: EdgeInsets.only(left: 10.0, top: 40.0),
alignment: Alignment.center,
color: Colors.lightGreen,
更好的方法是创建另一个专门用于MaterialApp
的小部件。
在main.dart
文件上
void main() {
runApp(
MyApp(),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
buttonTheme: ButtonThemeData(
textTheme: ButtonTextTheme.primary,
),
),
home: HomePage (),
);
}
}
然后创建另一个文件home.dart
或您喜欢的任何名称。
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(),
);
}
}
在创建另一个屏幕时,提供Scaffold
。但是嵌套的小部件不需要另一个Scaffold
。
发布于 2021-08-01 16:28:18
使用MaterialApp并尝试像这样更新。(如果您愿意,也可以添加Scaffold )
import 'package:flutter/material.dart';
// import 'package:';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Center(
child: Container(
padding: EdgeInsets.only(left: 10.0, top: 40.0),
alignment: Alignment.center,
color: Colors.lightGreen,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: Text(
"Spice jet",
textDirection: TextDirection.ltr,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 35.0,
fontFamily: 'railway',
fontWeight: FontWeight.w700,
color: Colors.white),
)),
Expanded(
child: Text(
"Spice jet",
textDirection: TextDirection.ltr,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 35.0,
fontFamily: 'railway',
fontWeight: FontWeight.w700,
color: Colors.white),
)),
],
),
Row(
children: <Widget>[
Expanded(
child: Text(
"Spice jet",
textDirection: TextDirection.ltr,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 35.0,
fontFamily: 'railway',
fontWeight: FontWeight.w700,
color: Colors.white),
)),
Expanded(
child: Text(
"Spice jet",
textDirection: TextDirection.ltr,
style: TextStyle(
decoration: TextDecoration.none,
fontSize: 35.0,
fontFamily: 'railway',
fontWeight: FontWeight.w700,
color: Colors.white),
)),
],
),
Futo()
],
))),
);
}
}
class Futo extends StatelessWidget {
@override
Widget build(BuildContext context) {
AssetImage assetImage = AssetImage('assets/images/34.png');
Image image = Image(image: assetImage);
return Container(
child: image,
);
}
}
https://stackoverflow.com/questions/68612165
复制相似问题