Skip to content

use_sliver_prefix

v0.4.0 Warning Fix Widget 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([]));
}
}

To disable this rule:

plugins:
many_lints:
diagnostics:
use_sliver_prefix: false