flutter Scaffold persistentFooterButtons抖动
时间: 2024-01-16 20:03:05 浏览: 24
在Flutter中,如果在Scaffold组件中使用persistentFooterButtons属性,并且其中的按钮不足以填满底部区域时,会出现抖动的问题。这是由于Scaffold的布局机制导致的。
要解决这个问题,你可以尝试以下方法之一:
1. 使用Column来包裹persistentFooterButtons属性,将其作为子组件传递给Scaffold的bottomNavigationBar属性,这样可以确保按钮始终位于底部位置,而不会抖动:
```dart
Scaffold(
// other properties
bottomNavigationBar: Column(
mainAxisSize: MainAxisSize.min,
children: [
Divider(height: 0),
persistentFooterButtons,
],
),
)
```
2. 使用CustomScrollView来替代Scaffold,然后在slivers属性中使用SliverPersistentFooter来实现类似的效果:
```dart
CustomScrollView(
slivers: [
// other slivers
SliverPersistentFooter(
delegate: _MyFooterDelegate(persistentFooterButtons),
),
],
)
```
其中,_MyFooterDelegate是一个自定义的SliverPersistentHeaderDelegate,用于渲染persistentFooterButtons。
这些方法都可以解决抖动问题,你可以根据自己的需求选择其中一种方法来实现。希望能帮到你!如果有任何疑问,请随时提问。