use_sliver_prefix
This rule warns when a widget’s build method returns a sliver widget (like SliverList, SliverAppBar, SliverToBoxAdapter) but the class name does not start with Sliver. Slivers and non-sliver widgets are not interchangeable, so making the distinction visible in the name prevents layout errors.
Why use this rule
Section titled “Why use this rule”If you drop a sliver-returning widget into a Column or Row, Flutter throws a confusing runtime error about “RenderSliver” not being a “RenderBox”. A Sliver prefix on the class name makes it immediately obvious that the widget belongs inside a CustomScrollView, not a regular box layout. This naming convention is used throughout the Flutter framework itself.
See also: Slivers
// Returns a sliver but name does not indicate itclass MyAdapter extends StatelessWidget { @override Widget build(BuildContext context) { return SliverToBoxAdapter(child: Text('hello')); }}
class ProductList extends StatelessWidget { @override Widget build(BuildContext context) { return SliverList(delegate: SliverChildListDelegate([])); }}// Sliver prefix makes the contract clearclass SliverMyAdapter extends StatelessWidget { @override Widget build(BuildContext context) { return SliverToBoxAdapter(child: Text('hello')); }}
class SliverProductList extends StatelessWidget { @override Widget build(BuildContext context) { return SliverList(delegate: SliverChildListDelegate([])); }}Turning this rule off
Section titled “Turning this rule off”This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:
rules: use_sliver_prefix: trueTo turn it off again:
rules: use_sliver_prefix: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Options
Section titled “Options”Projects with a state abstraction that does not extend Flutter’s State can
opt that base class into this rule:
many_lints: rules: use_sliver_prefix: state_base_classes: [AppState]rules: use_sliver_prefix: state_base_classes: [AppState]| Option | Type | Default | Description |
|---|---|---|---|
state_base_classes |
list of strings | [] |
Additional non-State base classes whose subclasses should be treated as state classes |
Related rules
Section titled “Related rules”always_pass_global_key— Don’t create a GlobalKey inside build.avoid_conditional_hooks— Never call hooks inside conditionals, loops, or ternaries.avoid_deep_widget_nesting— Keep a widget tree within a nesting budget.avoid_flexible_outside_flex— Only use Flexible and Expanded as direct children of Row, Column, or Flex.