sized_ box_ shrink_ expand
Use 'SizedBox.{0}' to avoid needing to specify the 'height' and 'width'.
Description
#
The analyzer produces this diagnostic when a SizedBox constructor
invocation specifies the values of both height and width
as either
0.0 or double.infinity.
Examples
#
The following code produces this diagnostic because both the height and
width are 0.0:
import 'package:flutter/material.dart';
Widget build() {
return SizedBox(
height: 0.0,
width: 0.0,
child: const Text(''),
);
}
The following code produces this diagnostic because both the height and
width are double.infinity:
import 'package:flutter/material.dart';
Widget build() {
return SizedBox(
height: double.infinity,
width: double.infinity,
child: const Text(''),
);
}
Common fixes
#If both are 0.0, then use SizedBox.shrink:
import 'package:flutter/material.dart';
Widget build() {
return SizedBox.shrink(
child: const Text(''),
);
}
If both are double.infinity, then use SizedBox.expand:
import 'package:flutter/material.dart';
Widget build() {
return SizedBox.expand(
child: const Text(''),
);
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.