Flutter SliverPersistentHeader 导致 "bottom overflow when scroll"
Flutter SliverPersistentHeader is causing "bottom overflow when scroll"
我有一个 SliverPersistentHeader
当用户滚动屏幕时会导致 bottom overflowed
。
我该如何解决?
return CustomScrollView(
slivers: <Widget>[
SliverPersistentHeader(
pinned: false,
delegate: DynamicSliverHeaderDelegate(
maxHeight: 256,
minHeight: 186,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_topo(context, grupo),
_infoGrupo(context, grupo),
],
),
),
),
// TODO: Lista do grupo
SliverFillViewport(
delegate: SliverChildListDelegate(
[
Container(
padding: EdgeInsets.only(top: 100),
color: Colors.green.withOpacity(0.2),
child: Column(
children: <Widget>[
Text('TODO... A construir'),
],
),
),
],
),
),
],
);
// .....
class DynamicSliverHeaderDelegate extends SliverPersistentHeaderDelegate {
final Widget child;
final double maxHeight;
final double minHeight;
const DynamicSliverHeaderDelegate({
@required this.child,
this.maxHeight = 250,
this.minHeight = 80,
});
@override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
return child;
}
// @override
// bool shouldRebuild(DynamicSliverHeaderDelegate oldDelegate) => true;
@override
bool shouldRebuild(DynamicSliverHeaderDelegate oldDelegate) {
return maxHeight != oldDelegate.maxHeight ||
minHeight != oldDelegate.minHeight ||
child != oldDelegate.child;
}
@override
double get maxExtent => maxHeight;
@override
double get minExtent => minHeight;
}
通过用 SingleChildScrollView´ with
NeverScrollableScrollPhysics` physics.
包装 DynamicSliverHeaderDelegate
子列解决了这个问题
return CustomScrollView(
slivers: <Widget>[
SliverPersistentHeader(
pinned: false,
delegate: DynamicSliverHeaderDelegate(
maxHeight: 256,
minHeight: 186,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_topo(context, grupo),
_infoGrupo(context, grupo),
],
),
),
),
// TODO: Lista do grupo
// ...
],
);
完整的修复是:
return CustomScrollView(
slivers: <Widget>[
SliverPersistentHeader(
pinned: false,
delegate: DynamicSliverHeaderDelegate(
maxHeight: 256,
minHeight: 186,
child: SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_topo(context, grupo),
_infoGrupo(context, grupo),
],
),
),
),
),
// TODO: Lista do grupo
// ...
],
);
}
我有一个 SliverPersistentHeader
当用户滚动屏幕时会导致 bottom overflowed
。
我该如何解决?
return CustomScrollView(
slivers: <Widget>[
SliverPersistentHeader(
pinned: false,
delegate: DynamicSliverHeaderDelegate(
maxHeight: 256,
minHeight: 186,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_topo(context, grupo),
_infoGrupo(context, grupo),
],
),
),
),
// TODO: Lista do grupo
SliverFillViewport(
delegate: SliverChildListDelegate(
[
Container(
padding: EdgeInsets.only(top: 100),
color: Colors.green.withOpacity(0.2),
child: Column(
children: <Widget>[
Text('TODO... A construir'),
],
),
),
],
),
),
],
);
// .....
class DynamicSliverHeaderDelegate extends SliverPersistentHeaderDelegate {
final Widget child;
final double maxHeight;
final double minHeight;
const DynamicSliverHeaderDelegate({
@required this.child,
this.maxHeight = 250,
this.minHeight = 80,
});
@override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
return child;
}
// @override
// bool shouldRebuild(DynamicSliverHeaderDelegate oldDelegate) => true;
@override
bool shouldRebuild(DynamicSliverHeaderDelegate oldDelegate) {
return maxHeight != oldDelegate.maxHeight ||
minHeight != oldDelegate.minHeight ||
child != oldDelegate.child;
}
@override
double get maxExtent => maxHeight;
@override
double get minExtent => minHeight;
}
通过用 SingleChildScrollView´ with
NeverScrollableScrollPhysics` physics.
DynamicSliverHeaderDelegate
子列解决了这个问题
return CustomScrollView(
slivers: <Widget>[
SliverPersistentHeader(
pinned: false,
delegate: DynamicSliverHeaderDelegate(
maxHeight: 256,
minHeight: 186,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_topo(context, grupo),
_infoGrupo(context, grupo),
],
),
),
),
// TODO: Lista do grupo
// ...
],
);
完整的修复是:
return CustomScrollView(
slivers: <Widget>[
SliverPersistentHeader(
pinned: false,
delegate: DynamicSliverHeaderDelegate(
maxHeight: 256,
minHeight: 186,
child: SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_topo(context, grupo),
_infoGrupo(context, grupo),
],
),
),
),
),
// TODO: Lista do grupo
// ...
],
);
}