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.
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([])); }}Configuration
Section titled “Configuration”To disable this rule:
plugins: many_lints: diagnostics: use_sliver_prefix: false