Search code examples
flutterflutter-container

Another exception was thrown: Unexpected null value. Flutter


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

Solution

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