skip to Main Content

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…

2

Answers


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

    Login or Signup to reply.
  2. 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;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search