sized_ box_ shrink_ expand
Details about the 'sized_box_shrink_expand' diagnostic produced by the Dart analyzer.
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.10.3. Report an issue.