将图像放入颤振中的颤振代码错误

时间:2021-08-01 16:08:09

标签: flutter flutter-layout fluent-nhibernate flutter-dependencies flutter-web

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\outputs\apk\debug\app-debug.apk。 调试服务监听 ws://127.0.0.1:55447/4v1zroR_P-8=/ws 正在将文件同步到设备 Infinix X680B... I/GED(4227):ged_boost_gpu_freq,级别 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

2 个答案:

答案 0 :(得分:0)

Tayba,我认为您错过了 structure 的主要 flutter App。您需要使用 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

答案 1 :(得分:0)

使用 MaterialApp 并尝试像这样更新。 (如果需要,您也可以添加脚手架

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,
    );
  }
}