You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter Clean Architecture下带BottomNavigationBar的HomeScreen架构咨询

Clean Architecture下Flutter HomeScreen(带BottomNavigationBar)的实现方案咨询

我正在用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 03:26:13