class OnBoardingPage extends StatelessWidget {
const OnBoardingPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ConstrainedBox(
constraints: _getConstraints(context),
child: Padding(
padding: _getPadding(context),
child: ScrollConfiguration(
behavior:
ScrollConfiguration.of(context).copyWith(scrollbars: false),
child: ListView(
children: [const AwardsSection()
],
),
),
),
),
),
);
}
}
class AwardsSection extends StatelessWidget {
const AwardsSection({super.key});
@override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: awards
.map((award) => Card(
elevation: 3,
surfaceTintColor: Colors.white,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8, vertical: 16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
// crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Image.asset(award.imageUrl),
const SizedBox(height: 16),
ResponsiveText(
text: award.title,
textStyle: getResponsiveTextStyle(
context, AppTextTheme.title)),
const SizedBox(
height: 32,
),
OutlinedButton(
style: OutlinedButton.styleFrom(
minimumSize: const Size.fromHeight(48)),
onPressed: () {},
child: const Text("Hello")) // <---- This I want full width in each card
],
),
),
))
.toList(),
),
],
);
}
}
final List<AwardModel> awards = [
AwardModel(imageUrl: 'images/award_1.png', title: "Stage 1 & 2 Winners"),
AwardModel(
imageUrl: "images/award_2.png", title: "Second place in 3/4 events"),
AwardModel(
imageUrl: "images/award_3.png", title: "Finalist in the virtual circuit")
];
class AwardModel {
String imageUrl;
String title;
AwardModel({required this.imageUrl, required this.title});
}
The following assertion was thrown during performLayout():
BoxConstraints forces an infinite width.
The offending constraints were:
BoxConstraints(w=Infinity, 40.0<=h<=Infinity)
The relevant error-causing widget was:
OutlinedButton
OutlinedButton:file:///C:/Users/krisarya/My%20Profile/Github-krishnaacharya-official/flutter-landing-page/app/lib/onboarding/presentation/widgets/award_section.dart:40:27
award_section.dart:40
When the exception was thrown, this was the stack:
dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:49 throw
packages/flutter/src/rendering/box.dart 519:9 throwError
packages/flutter/src/rendering/box.dart 569:11
packages/flutter/src/rendering/box.dart 576:14 debugAssertIsValid
packages/flutter/src/rendering/object.dart 2386:23 layout
packages/flutter/src/rendering/box.dart 2382:11 layout
packages/flutter/src/rendering/proxy_box.dart 279:7 performLayout
packages/flutter/src/rendering/object.dart 2493:7 layout
packages/flutter/src/rendering/box.dart 2382:11 layout
he following RenderObject was being processed when the exception was fired: RenderConstrainedBox#f151b relayoutBoundary=up17 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
creator: ConstrainedBox ← _InputPadding ← Semantics ← OutlinedButton ← Column ← Padding ← Semantics
← DefaultTextStyle ← AnimatedDefaultTextStyle ← _InkFeatures-[GlobalKey#ddc19 ink renderer] ←
NotificationListener ← CustomPaint ← ⋯
parentData: offset=Offset(0.0, 0.0) (can use size)
constraints: BoxConstraints(unconstrained)
size: MISSING
additionalConstraints: BoxConstraints(w=Infinity, 40.0<=h<=Infinity)
This RenderObject had the following descendants (showing up to depth 5):
child: RenderPhysicalShape#51eaf NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
child: RenderCustomPaint#a155c NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
child: _RenderInkFeatures#7a4e5 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
child: RenderSemanticsAnnotations#1ca50 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
child: RenderMouseRegion#7191b NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
════════════════════════════════════════════════════════════════════════════════════════════════════
在PerformLayout()过程中引发了以下断言:BoxConstraints强制无限宽。令人不快的约束是:BoxConstraints(w=无限,40.0<=h<=无限)当异常被抛出时,相关的导致错误的窗口小部件是:OutlinedButtonBoxConstraints_OutlinedButton:file:///C:/Users/krisarya/My%20Profile/Github-krishnaacharya-official/flutter-landing-page/app/lib/onboarding/presentation/widgets/award_section.dart:40:27_Section.Dart:40,这就是堆栈:dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:49抛出包/Ffltter/src/Rending/box.Dart 519:9掷出错误包/Ffltter/src/Rending/box.Dart 569:11包/Ffltter/src/Rending/box.Dart 576:14调试资产发出有效包/Ffltter/src/Rending/Object。Dart 2386:23布局包/Ffltter/src/Renping/box.dart 2382:11布局包/Ffltter/src/Rending/Proxy_box.dart 279:7性能布局包/Ffltter/src/Rending/Object。Dart 2493:7布局包/Ffltter/src/Rending/Box。Dart 2382:11布局下列RenderObject在异常激发时正在处理对象:RenderConstrainedBox#f151b relayout边界=up17需要-布局需要-绘制需要-合成-位-更新:创建者:ConstrainedBox←_Input填充←语义←Outline按钮←列←填充←语义←DefaultTextStyle←动画默认文本Style←_Ink功能-[GlobalKey#ddc19墨水渲染器]←通知侦听器←Custompaint←⋯ParentData:Offset=(0.0,Offset0.0)(可以使用大小)约束:BoxConstraints(无约束)大小:缺少附加约束:BoxConstraints(w=无限,40.0<=h<=无限)此渲染对象具有以下后代(显示至深度5):子对象:RenderPhysicalShape#51eaf Need-布局需求-绘制需要-合成-位-更新子对象:RenderCustomPaint#a155c需要-布局需要-绘制需要-合成-位-更新子对象:_RenderInkFeature#7a4e5需要-布局需要-合成-位-更新子对象:渲染语义注释#1ca50需要-布局需要-合成-位-更新子对象:渲染Mouseon区域#7191b需要-布局需要-绘制需要-更新════════════════════════════════════════════════════════════════════════════════════════════════════
更多回答
Try wrapping your outlined button widget with expanded, it should solve the problem like this
尝试使用Expand包装您的概述按钮小部件,它应该可以像这样解决问题
Expanded(
child: OutlinedButton(
style: OutlinedButton.styleFrom(
minimumSize: const Size.fromHeight(48)),
onPressed: () {},
child: const Text("Hello")
))
更多回答
You are crazy, you are suggesting me to use expanded inside listview. Thank you for your suggestion.
你疯了,你在建议我使用Expanded Inside Listview。谢谢你的建议。
No I am saying to use it in the cards.
不,我是说把它用在卡片上。
我是一名优秀的程序员,十分优秀!