getDashboardHostTemplate function

String getDashboardHostTemplate({
  1. required String projectName,
  2. required String className,
  3. required bool hasBottomBar,
  4. required bool hasDrawer,
  5. required List<String> tabNames,
  6. required List<String> drawerNames,
  7. String? isLoading,
})

Implementation

String getDashboardHostTemplate({
  required String projectName,
  required String className,
  required bool hasBottomBar,
  required bool hasDrawer,
  required List<String> tabNames,
  required List<String> drawerNames,
  String? isLoading,
}) {
  final List<String> pageClassNames = tabNames
      .map((e) =>
          e.split('_').map((s) => s[0].toUpperCase() + s.substring(1)).join() +
          'Page')
      .toList();

  final String items = tabNames.asMap().entries.map((entry) {
    final name = entry.value;
    final icon = _getIconForTab(name);
    return '''
        BottomNavigationBarItem(
          icon: Icon($icon),
          label: '$name',
        ),''';
  }).join('\n');

  final String pagesList = pageClassNames.map((e) => "const $e()").join(', ');

  return '''
CustomBody(
      scaffoldKey: context.read<${className}Bloc>().scaffoldKey,
      title: "Enterprise Dashboard",
      isLoading: ${isLoading ?? 'false'},
      ${hasDrawer ? '''appBarLeading: IconButton(
        onPressed: () {
          context.read<${className}Bloc>().scaffoldKey.currentState?.openDrawer();
        },
        icon: const Icon(Icons.menu),
      ),
       drawer: CustomSideDrawer(
        userName: "Peter Smith",
        userEmail: "peter@gmail.com",
        profileImage: "https://via.placeholder.com/150",
        drawerItems: [
          ${drawerNames.map((name) => "{'name': '$name', 'icon': ${_getIconForDrawer(name)}}").join(',\n          ')}
        ],
        onItemTap: (name) {
          Navigator.pop(context);
          // Handle navigation or actions
        },
      ),''' : ''}
      bottomNavigationBar: ${hasBottomBar ? '''Container(
        decoration: BoxDecoration(
          boxShadow: [
            BoxShadow(color: AppColors.black.withOpacity(0.05), blurRadius: 10, offset: const Offset(0, -5)),
          ],
        ),
        child: BottomNavigationBar(
          currentIndex: state.selectedIndex,
          onTap: (index) => context.read<${className}Bloc>().add(${className}ChangeTab(index)),
          type: BottomNavigationBarType.fixed,
          selectedItemColor: AppColors.primary,
          unselectedItemColor: AppColors.grey,
          showSelectedLabels: true,
          showUnselectedLabels: true,
          items: [
            $items
          ],
        ),
      )''' : 'const SizedBox()'},
      child: IndexedStack(
        index: state.selectedIndex,
        children: const [
          $pagesList
        ],
      ),
    )''';
}