PoeMcMoe
PoeMcMoe

Reputation: 73

should I specify size in int or double for SizedBox?

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...

Upvotes: 0

Views: 294

Answers (2)

Alakba
Alakba

Reputation: 251

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;

Upvotes: 1

eamirho3ein
eamirho3ein

Reputation: 17940

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

Upvotes: 1

Related Questions