proper-expanded-and-flexible
Same as proper_expanded_and_flexible in Pyramid Lint
- Group
- Correctness
- Path
lint/correctness/proper-expanded-and-flexible- Default
- On (recommended)
- Origin
- Pyramid Lint
- Domain
- flutter
- Rule
- 423 of 512
Require Expanded and Flexible to sit directly inside a flex widget.
Flags an Expanded or Flexible passed as the child: of a widget that is
not a Row, Column, or Flex. These widgets report their flex factor to a
surrounding flex container through the render tree; under any other parent
they have no flex parent to negotiate with and throw a layout error at
runtime. Put them in the children: of a Row, Column, or Flex, or
remove the wrapper. The rule reports only when the illegal parent is directly
visible at the construction site.
Invalid
import 'package:flutter/material.dart';
Widget a() => Container(child: Expanded(child: Text('a')));
Widget b() => Center(child: Flexible(child: Text('b')));
Widget c() => SizedBox(child: Expanded(child: SizedBox()));
Widget d() => Padding(
padding: EdgeInsets.zero,
child: Expanded(child: Text('d')),
);
Widget e() => const Align(child: Flexible(child: Text('e'))); Widget a() => Container(child: Expanded(child: Text('a'))); Widget b() => Center(child: Flexible(child: Text('b'))); Widget c() => SizedBox(child: Expanded(child: SizedBox())); padding: EdgeInsets.zero, child: Expanded(child: Text('d')), Widget e() => const Align(child: Flexible(child: Text('e')));Valid
import 'package:flutter/material.dart';
Widget a() => Row(children: [Expanded(child: Text('a'))]);
Widget b() => Column(children: [Flexible(child: Text('b'))]);
Widget c() =>
Flex(direction: Axis.horizontal, children: [Expanded(child: Text('c'))]);
Widget d() => Container(child: Text('d'));
Widget e() => Center(child: SizedBox(height: 8));
Widget f() => Row(children: [const Expanded(child: Text('f'))]);Configure proper-expanded-and-flexible
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"proper-expanded-and-flexible": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/proper-expanded-and-flexible: <reason>More correctness rules
- proper-from-environment
proper_from_environmentrecommendedRequire
fromEnvironmentto be evaluated in a const context. - proper-super-init-state
proper_super_init_staterecommendedflutterRequire
super.initState()to be the first statement of a resolved FlutterStatesubclass'sinitStateoverride. - require-super-disposerecommendedflutter
Require
super.dispose()in Flutter State dispose overrides. - sort-pub-dependencies
sort_pub_dependenciescross-fileRequire
pubspec.yamldependency sections to be sorted alphabetically. - test-types-in-equals
test_types_in_equalsrecommendedFlags casting the parameter of
operator ==instead of testing its type. - throw-in-finally
throw_in_finallyrecommendedFlags
throwinside afinallyblock. - type-literal-in-constant-pattern
type_literal_in_constant_patternrecommendedDon't use constant patterns whose expressions have the core
Typetype. - undeclared-dependenciescross-file
Report package imports and exports missing from the enclosing pubspec.