英文:
Another exception was thrown: Unexpected null value. Flutter
问题
以下是您的代码的中文翻译:
这是我的代码:
class ListItems extends StatelessWidget {
final String child;
const ListItems({super.key, required this.child});
@override
Widget build(BuildContext context) {
return Sizer(builder: ((context, orientation, deviceType) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.blueGrey,
height: 25.h,
child: Text(child),
),
);
}));
}
}
希望这能帮助您!如果您需要进一步的翻译或帮助,请告诉我。
英文:
Here is my code:
class ListItems extends StatelessWidget {
final String child; const ListItems({super.key, required this.child});
@override Widget build(BuildContext context) { return Sizer(builder: ((context, orientation, deviceType) { return Padding( padding: const EdgeInsets.all(8.0), child: Container( color: Colors.blueGrey, height: 25.h, child: Text(child), ), ); })); } }
答案1
得分: 0
由于deviceType
未传递给ListItems
类中的Sizer
小部件,因此请尝试提供设备类型或从Sizer
小部件中删除设备参数。
class ListItems extends StatelessWidget {
final String child;
const ListItems({Key? key, required this.child}) : super(key: key);
@override
Widget build(BuildContext context) {
return Sizer(
builder: ((context, orientation, [deviceType = DeviceType.mobile]) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: ConstrainedBox(
constraints: const BoxConstraints(
minHeight: 100,
maxHeight: 100,
),
child: Container(
color: Colors.blueGrey,
child: Center(child: Text(child)),
),
),
);
}),
);
}
}
希望这有所帮助!
英文:
Since the is deviceType
is not being passed into the Sizer
widget in the ListItems
class. So try providing device type or remove the device parameter from Sizer
widget.
class ListItems extends StatelessWidget {
final String child;
const ListItems({Key? key, required this.child}) : super(key: key);
@override
Widget build(BuildContext context) {
return Sizer(
builder: ((context, orientation, [deviceType = DeviceType.mobile]) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: ConstrainedBox(
constraints: const BoxConstraints(
minHeight: 100,
maxHeight: 100,
),
child: Container(
color: Colors.blueGrey,
child: Center(child: Text(child)),
),
),
);
}),
);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论