flutter

Add a single widget as a sliver in Flutter

Scaffold(
  body: CustomScrollView(
    slivers: <Widget>[
      SliverToBoxAdapter(
        child: Container(
          child: Text('This is a single widget'),
        ),
      )
    ],
  ),
);

If you want to add a single widget or child as slivers, you can use SliverToBoxAdapter sliver widget and pass your widget as its child.

This will only add a particular widget if there is a requirement. Like if you want to add a heading before sliverlist widget you can use it for that purpose.

Was this helpful?