当我将我创建的Tutorial类包含在Column类的子类中时,会出现此错误:
Launching lib/main.dart on iPhone XR in debug mode...
Starting Xcode build...
Xcode build done. 20.7s
Syncing files to device iPhone XR...
flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during performResize():
flutter: Horizontal viewport was given unbounded height.
flutter: Viewports expand in the cross axis to fill their container and constrain their children to match
flutter: their extent in the cross axis. In this case, a horizontal viewport was given an unlimited amount of
flutter: vertical space in which to expand.
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 RenderViewport.performResize.<anonymous closure> (package:flutter/src/rendering/viewport.dart:1170:15)
flutter: #1 RenderViewport.performResize (package:flutter/src/rendering/viewport.dart:1182:6)
flutter: #2 RenderObject.layout (package:flutter/src/rendering/object.dart:1619:9)
flutter: #3 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #4 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #5 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #6 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #7 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #8 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #9 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #10 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #11 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #12 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #13 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
flutter: #14 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #15 RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:738:15)
flutter: #16 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #17 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #18 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #19 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #20 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #21 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #22 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #23 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
flutter: #24 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #25 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #26 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #27 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #28 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #29 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #30 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #31 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #32 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #33 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #34 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #35 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #36 RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:2881:13)
flutter: #37 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #38 RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
flutter: #39 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #40 __RenderTheatre&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #41 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #42 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #43 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #44 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #45 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #46 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #47 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #48 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #49 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #50 _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:104:13)
flutter: #51 RenderObject.layout (package:flutter/src/rendering/object.dart:1634:7)
flutter: #52 RenderView.performLayout (package:flutter/src/rendering/view.dart:147:13)
flutter: #53 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1509:7)
flutter: #54 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:768:18)
flutter: #55 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:281:19)
flutter: #56 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:677:13)
flutter: #57 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
flutter: #58 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
flutter: #59 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
flutter: #60 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:751:7)
flutter: #62 _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
flutter: #63 _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
flutter: #64 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
flutter: (elided one frame from package dart:async)
flutter:
flutter: The following RenderObject was being processed when the exception was fired:
flutter: RenderViewport#64551 NEEDS-LAYOUT NEEDS-PAINT
flutter: creator: Viewport ← _ScrollableScope ← IgnorePointer-[GlobalKey#608ab] ← Semantics ← Listener ←
flutter: _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#19222] ←
flutter: _ScrollSemantics-[GlobalKey#0390f] ← Scrollable ← NotificationListener<ScrollNotification> ←
flutter: PageView ← Stack ← ⋯
flutter: parentData: <none> (can use size)
flutter: constraints: BoxConstraints(0.0<=w<=414.0, 0.0<=h<=Infinity)
flutter: size: MISSING
flutter: axisDirection: right
flutter: crossAxisDirection: down
flutter: offset: _PagePosition#edc3e(offset: null, range: null..null, viewport: null, ScrollableState,
flutter: PageScrollPhysics -> AlwaysScrollableScrollPhysics -> BouncingScrollPhysics,
flutter: IdleScrollActivity#95217, ScrollDirection.idle)
flutter: anchor: 0.0
flutter: This RenderObject had the following child:
flutter: RenderSliverFillViewport#5d322 NEEDS-LAYOUT NEEDS-PAINT
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: Another exception was thrown: RenderBox was not laid out: RenderViewport#64551 NEEDS-LAYOUT NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderViewport#64551 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#cca00 relayoutBoundary=up6 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#498e5 relayoutBoundary=up5 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderPointerListener#a32d0 relayoutBoundary=up4 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#cbf64 relayoutBoundary=up3 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: _RenderScrollSemantics#11d99 relayoutBoundary=up2 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderStack#d9de7 relayoutBoundary=up1 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderFlex#554a3 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#1d6d0 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#b279d NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderIgnorePointer#e430d NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderStack#e8e8f NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderDecoratedBox#a3175 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderFractionalTranslation#4ca11 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderFractionalTranslation#0d592 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#6ed00 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#7d38e NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderOffstage#4e5b5 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderStack#4e841 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: _RenderTheatre#f534f NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#85a31 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderAbsorbPointer#a08a9 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderPointerListener#f45f1 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#5f6ee NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#6ed00 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#5f6ee
flutter: Another exception was thrown: NoSuchMethodError: The getter 'visible' was called on null.
flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#5dcca
flutter: Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#6ed00 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderCustomPaint#5f6ee
我的代码是:
import 'package:flutter/material.dart';
import 'Components/Tutorial.dart';
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
Widget build(BuildContext context) {
return Container(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(38.0),
child: Text(
'Title',
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.none
),
),
),
Tutorial()
],
),
);
}
}
仅当我在列中插入教程时才会发生这种情况。我尝试了很多事情,但我不明白为什么会撞车!
以及带有Tutorial类的文件:
Import 'dart:math';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
class DotsIndicator extends AnimatedWidget {
DotsIndicator({
this.controller,
this.itemCount,
this.onPageSelected,
this.color: Colors.white,
}) : super(listenable: controller);
/// The PageController that this DotsIndicator is representing.
final PageController controller;
/// The number of items managed by the PageController
final int itemCount;
/// Called when a dot is tapped
final ValueChanged<int> onPageSelected;
/// The color of the dots.
///
/// Defaults to `Colors.white`.
final Color color;
// The base size of the dots
static const double _kDotSize = 8.0;
// The increase in the size of the selected dot
static const double _kMaxZoom = 2.0;
// The distance between the center of each dot
static const double _kDotSpacing = 25.0;
Widget _buildDot(int index) {
double selectedness = Curves.easeOut.transform(
max(
0.0,
1.0 - ((controller.page ?? controller.initialPage) - index).abs(),
),
);
double zoom = 1.0 + (_kMaxZoom - 1.0) * selectedness;
return Container(
width: _kDotSpacing,
child: Center(
child: Material(
color: color,
type: MaterialType.circle,
child: Container(
width: _kDotSize * zoom,
height: _kDotSize * zoom,
child: InkWell(
onTap: () => onPageSelected(index),
),
),
),
),
);
}
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List<Widget>.generate(itemCount, _buildDot),
);
}
}
class Tutorial extends StatefulWidget {
@override
State createState() => TutorialState();
}
class TutorialState extends State<Tutorial> {
final _controller = PageController(viewportFraction: 0.5);
static const _kDuration = const Duration(milliseconds: 300);
static const _kCurve = Curves.ease;
final _kArrowColor = Colors.black.withOpacity(0.8);
static onTap(index) {
print("$index selected.");
}
final List<Widget> _pages = <Widget>[
FlutterLogo(colors: Colors.blue),
FlutterLogo(style: FlutterLogoStyle.stacked, colors: Colors.red),
FlutterLogo(style: FlutterLogoStyle.horizontal, colors: Colors.green),
];
Widget _buildPageItem(BuildContext context, int index) {
return Page(page: _pages[index], idx: index);
}
@override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
PageView.builder(
physics: AlwaysScrollableScrollPhysics(),
controller: _controller,
itemCount: _pages.length,
itemBuilder: (BuildContext context, int index) {
return _buildPageItem(context, index % _pages.length);
},
),
Positioned(
bottom: 0.0,
left: 0.0,
right: 0.0,
child: Container(
color: Colors.grey[800].withOpacity(0.5),
padding: const EdgeInsets.all(20.0),
child: Center(
child: DotsIndicator(
controller: _controller,
itemCount: _pages.length,
onPageSelected: (int page) {
_controller.animateToPage(
page,
duration: _kDuration,
curve: _kCurve,
);
},
),
),
),
),
],
);
}
}
class Page extends StatelessWidget {
final page;
final idx;
Page({
@required this.page,
@required this.idx,
});
onTap() {
print("${this.idx} selected.");
}
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0)
);
}
}
这是什么错误?我在做什么错了?
答案 0 :(得分:0)
尝试将列更改为列表视图
ListView(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(38.0),
child: Text(
'Title',
style: TextStyle(
color: Colors.white, decoration: TextDecoration.none),
),
),
Tutorial()
],
)
答案 1 :(得分:0)