Skip to content

use_sliver_prefix

v0.4.0WarningFixConfigurableWidget Best Practices

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.

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 it
class 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 clear
class 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([]));
}
}

This rule is in the pedantic preset, so it is enabled by preset: pedantic or by name:

many_lints.yaml
rules:
use_sliver_prefix: true

To turn it off again:

many_lints.yaml
rules:
use_sliver_prefix: false

To keep the rule on but skip certain paths, use per-rule exclude.

Projects with a state abstraction that does not extend Flutter’s State can opt that base class into this rule:

analysis_options.yaml
many_lints:
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