用颤动建立一个简单的表

时间:2019-03-07 09:07:42

标签: flutter

我正努力只用我的应用程序中的表进行视图。

我试图创建一个带有表的容器,如下所示:

@override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(report['name'])),
      body: Container(
        child: Table(children: [
                  TableRow(children: [
                    Text("r1"),
                    Text("r2"),
                    Text("r3")
                  ]),
                  TableRow(children: [
                    Text("c1"),
                    Text("c2"),
                    Text("c3")
                  ])
        ])
      )
    );
  }

但是我收到一个很长的错误,不知道该怎么办。有想法吗?

I/flutter ( 5913): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 5913): The following assertion was thrown during performLayout():
I/flutter ( 5913): 'package:flutter/src/rendering/table.dart': Failed assertion: line 882 pos 16: 'tableWidth >=
I/flutter ( 5913): targetWidth': is not true.
I/flutter ( 5913): 
I/flutter ( 5913): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter ( 5913): more information in this error message to help you determine and fix the underlying cause.
I/flutter ( 5913): In either case, please report this assertion by filing a bug on GitHub:
I/flutter ( 5913):   https://github.com/flutter/flutter/issues/new?template=BUG.md
I/flutter ( 5913): 
I/flutter ( 5913): When the exception was thrown, this was the stack:
I/flutter ( 5913): #2      RenderTable._computeColumnWidths (package:flutter/src/rendering/table.dart:882:16)
I/flutter ( 5913): #3      RenderTable.performLayout (package:flutter/src/rendering/table.dart:1000:33)
I/flutter ( 5913): #4      RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #5      MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:142:11)
I/flutter ( 5913): #6      _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:339:7)
I/flutter ( 5913): #7      MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:212:7)
I/flutter ( 5913): #8      RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:356:14)
I/flutter ( 5913): #9      RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #10     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #11     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #12     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #13     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1188:11)
I/flutter ( 5913): #14     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #15     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #16     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #17     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #18     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #19     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #20     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #21     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #22     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #23     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #24     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #25     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #26     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #27     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #28     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #29     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #30     RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:2881:13)
I/flutter ( 5913): #31     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #32     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
I/flutter ( 5913): #33     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #34     __RenderTheatre&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #35     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #36     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #37     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #38     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #39     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #40     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #41     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #42     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #43     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #44     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
I/flutter ( 5913): #45     RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
I/flutter ( 5913): #46     RenderView.performLayout (package:flutter/src/rendering/view.dart:147:13)
I/flutter ( 5913): #47     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1509:7)
I/flutter ( 5913): #48     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:768:18)
I/flutter ( 5913): #49     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:281:19)
I/flutter ( 5913): #50     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:677:13)
I/flutter ( 5913): #51     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
I/flutter ( 5913): #52     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter ( 5913): #53     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter ( 5913): #54     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:751:7)
I/flutter ( 5913): #56     _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
I/flutter ( 5913): #57     _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
I/flutter ( 5913): #58     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
I/flutter ( 5913): (elided 3 frames from class _AssertionError and package dart:async)
I/flutter ( 5913): 
I/flutter ( 5913): The following RenderObject was being processed when the exception was fired:
I/flutter ( 5913):   RenderTable#20b29 relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5913):   creator: Table ← Container ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ← CustomMultiChildLayout
I/flutter ( 5913):   ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#5a2a3
I/flutter ( 5913):   ink renderer] ← NotificationListener<LayoutChangedNotification> ← PhysicalModel ←
I/flutter ( 5913):   AnimatedPhysicalModel ← ⋯
I/flutter ( 5913):   parentData: offset=Offset(0.0, 0.0); id=_ScaffoldSlot.body (can use size)
I/flutter ( 5913):   constraints: BoxConstraints(0.0<=w<=1024.0, 0.0<=h<=640.0)
I/flutter ( 5913):   size: MISSING
I/flutter ( 5913):   default column width: FlexColumnWidth(1.0)
I/flutter ( 5913):   table size: 7×2
I/flutter ( 5913):   column offsets: unknown
I/flutter ( 5913):   row offsets: []
I/flutter ( 5913): This RenderObject had the following descendants (showing up to depth 5):
I/flutter ( 5913):   RenderParagraph#f5a27 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5913):   RenderParagraph#eb645 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5913):   RenderParagraph#d2e6f NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5913):   RenderParagraph#69137 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5913):   RenderParagraph#69e3f NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5913):   RenderParagraph#9a868 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5913):   RenderParagraph#6acd5 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5913):   RenderParagraph#3af4f NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5913):   RenderParagraph#6bc48 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5913):   RenderParagraph#16992 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5913):   RenderParagraph#18f98 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5913):   RenderParagraph#d593f NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5913):   RenderParagraph#1d8f7 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5913):   RenderParagraph#e0527 NEEDS-LAYOUT NEEDS-PAINT
I/flutter ( 5913): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter ( 5913): Another exception was thrown: RenderBox was not laid out: RenderTable#20b29 relayoutBoundary=up1 NEEDS-PAINT
I/flutter ( 5913): Another exception was thrown: 'package:flutter/src/rendering/table.dart': Failed assertion: line 1127 pos 12: '_rowTops.length == rows + 1': is not true.

1 个答案:

答案 0 :(得分:0)

您需要保留在表格单元格中 像这样-

              TableRow(
             children: [
              TableCell(
               child:Column(
                 children:<widget>[ 
                    Text("r1"),
                    Text("r2"),
                    Text("r3")     
                      ]
                  )
                 )
              ]),