import 'package:flutter/material.dart'; import 'package:flutter_custom_toolbox/flutter_toolbox.dart'; import 'package:midisynth/cubit/activity/activity_cubit.dart'; import 'package:midisynth/models/activity/activity.dart'; import 'package:midisynth/ui/pages/editor.dart'; import 'package:midisynth/ui/pages/home.dart'; import 'package:midisynth/ui/pages/player.dart'; class ActivityPageItem { final String code; final Icon icon; final Widget Function({required Activity currentActivity})? builder; const ActivityPageItem({ required this.code, required this.icon, required this.builder, }); } class ActivityPage { static const bool displayBottomNavBar = true; static const indexHome = 0; static final pageHome = ActivityPageItem( code: 'page_home', icon: Icon(UniconsLine.home), builder: ({required Activity currentActivity}) { return PageHome(); }, ); static const indexEditor = 1; static final pageEditor = ActivityPageItem( code: 'page_editor', icon: Icon(UniconsLine.edit), builder: ({required Activity currentActivity}) { return PageEditor(); }, ); static const indexPlayer = 2; static final pagePlayer = ActivityPageItem( code: 'page_player', icon: Icon(UniconsLine.play), builder: ({required Activity currentActivity}) { return PagePlayer(); }, ); static final Map<int, ActivityPageItem> items = { indexHome: pageHome, indexEditor: pageEditor, indexPlayer: pagePlayer, }; static int defaultPageIndex = indexHome; static bool isIndexAllowed(int pageIndex) { return items.keys.contains(pageIndex); } static Widget getWidget(int pageIndex) { return BlocBuilder<ActivityCubit, ActivityState>( builder: (BuildContext context, ActivityState activityState) { final Activity currentActivity = activityState.currentActivity; if (items.keys.contains(pageIndex)) { return items[pageIndex]?.builder!(currentActivity: currentActivity) ?? Text('oups'); } else { return getWidget(defaultPageIndex); } }, ); } }