Another exception was thrown: Unexpected null value. Flutter

huangapple go评论65阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年4月19日 16:04:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76052074.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定