Home > front end >  should I specify size in int or double for SizedBox?
should I specify size in int or double for SizedBox?

Time:01-19

When specifying widget size in flutter should I use int or double? For example, should it be SizedBox(width:8), or SizedBox(width:8.0)?

I tried looking into flutter docs, but could find anything about this, so instead I looked for examples: https://docs.flutter.dev/development/ui/layout and https://api.flutter.dev/flutter/widgets/SizedBox-class.html, but they seem to be inconsistent...

CodePudding user response:

When you want to set round value, you don't need to use double but otherwise you need it.

CodePudding user response:

If you go inside the SizedBox you will see a Double waiting there. When you type 8, SizedBox treats it as 8.0 anyway.

Inside SizedBox it is

const SizedBox({ super.key, this.width, this.height, super.child });
const SizedBox.expand({ super.key, super.child })
    : width = double.infinity,
      height = double.infinity;
  • Related