在 Flutter 中嵌套 Scaffold 是否正确?

Is it correct to have nested Scaffold in Flutter?

我的应用程序主页中有一个 PageView,我想要:

  1. AppBar根据页面变化
  2. BottomAppBar 已修复

我想到的2个解决方案是:

  1. 难点:拥有一个带有 appBar、body 和 bottomNavigationBar 的脚手架;使用 PageView 的 PageController 为 AppBar 内容设置动画...
  2. 有 2 个嵌套的脚手架:主脚手架带有 body 和 bottomNavigationBar,第二个脚手架在每个 PageView 的页面中,带有 AppBar...

所以我想知道,它有效,但嵌套脚手架在语法上“正确”吗?

非常感谢!

我也这么认为。 脚手架就像任何其他小部件 imo。 它非常方便,因为它为您提供了应用栏、正文等。 我通常将它作为 SafeArea 小部件的子项,以便该应用程序考虑到现代智能手机上的缺口。

转到这里:https://api.flutter.dev/flutter/material/Scaffold-class.html

有一个名为“疑难解答”的部分,您会在其中找到:

Nested Scaffolds

The Scaffold was designed to be the single top level container for a MaterialApp and it's typically not necessary to nest scaffolds. For example in a tabbed UI, where the bottomNavigationBar is a TabBar and the body is a TabBarView, you might be tempted to make each tab bar view a scaffold with a differently titled AppBar. It would be better to add a listener to the TabController that updates the AppBar.