Using a SliverFillRemaining with a CustomScrollView and SliverList
Scaffold(
appBar: AppBar(title: Text('SliverFillRemaining')),
body: CustomScrollView(
slivers: [
SliverFillRemaining(
hasScrollBody: false,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
FlutterLogo(size: 200),
Text(
'This is some longest text that should be centered'
'together with the logo',
textAlign: TextAlign.center,
),
],
),
),
],
),
);
SliverFillRemaining
will automatically size itself to fill the space between the bottom of the last list item and the bottom of the viewport. See the performLayout
method of SliverFillRemaining
for the code:
https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/rendering/sliver_fill.dart#L118
I don't think you can use it to achieve the effect you're going for, though you might be able to create a subclass that would work.
For anyone that is looking for an answer to this, I have a solution that has been working well whenever I needed something similar.
This is how I've managed it:
class ScrollOrFitBottom extends StatelessWidget {
final Widget scrollableContent;
final Widget bottomContent;
ScrollOrFitBottom({this.scrollableContent, this.bottomContent});
@override
Widget build(BuildContext context) {
return CustomScrollView(
slivers: <Widget>[
SliverFillRemaining(
hasScrollBody: false,
child: Column(
children: <Widget>[
Expanded(child: scrollableContent),
bottomContent
],
),
),
],
);
}
}
As the name says, it will scroll if there is too much content, or have something pushed to the bottom otherwise.
I think it is simple and self-explanatory, but let me know if you have any questions
Example: https://codepen.io/lazarohcm/pen/xxdWJxb