Flutter Clean Architecture下带BottomNavigationBar的HomeScreen架构咨询
我正在用Clean Architecture开发Flutter应用,需要实现一个带BottomNavigationBar的HomeScreen,这个页面要导入不同feature下的多个页面。
项目文件结构
lib |- features |- feature_1 |- data |- domain |- presentation |- controllers |- screens |- screen_1.dart |- screen_2.dart |- widgets |- feature_2 |- data |- domain |- presentation |- controllers |- screens |- screen_1.dart |- screen_2.dart |- widgets |- feature_3 |- data |- domain |- presentation |- controllers |- screens |- screen_1.dart |- screen_2.dart |- widgets |- shared (basically core) |- constants |- widgets |- functions
HomeScreen代码示例
import 'feature_1/presentation/screens/screen_1.dart'; import 'feature_2/presentation/screens/screen_1.dart'; import 'feature_3/presentation/screens/screen_1.dart'; import 'feature_4/presentation/screens/screen_1.dart'; class HomeScreen extends StatelessWidget { const HomeScreen({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( extendBody: true, body: IndexedStack( index: index, children: const [ Feature1Screen(), Feature2Screen(), Feature3Screen(), Feature4Screen(), ], ), bottomNavigationBar: BottomNavigationWidget( index: index, onIndexTap: onTap, ), ); } }
我考虑了三种实现方案:
- 方案1:为HomeScreen单独创建一个feature,直接导入其他feature的页面。
- 方案2:将被BottomNavigationBar调用的各feature主页面移至新的单独feature中,是方案1的变体。
- 方案3:在shared(core)文件夹下创建features目录,将HomeScreen放置其中。
各方案存在的问题:
- 方案1:明显违反Clean Architecture规则。
- 方案2:会移除各feature的主页面,导致feature不完整。
- 方案3:我认为可行,但希望得到专业建议。
恳请各位提供帮助,谢谢!
内容的提问来源于stack exchange,提问作者Muhammad Talha
相关产品推荐
相关产品推荐

