Files
syncrow-app/lib/features/menu/view/menu_view.dart
Mohammad Salameh 88588d9fa8 Refactor menu view to use sections and buttons
Extracted menu sections and buttons into separate data structures for better
organization and readability in the menu view. Updated MenuList widget to
dynamically render buttons based on the new data structure.
2024-04-23 15:11:01 +03:00

199 lines
5.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/auth/bloc/auth_cubit.dart';
import 'package:syncrow_app/features/menu/bloc/menu_cubit.dart';
import 'package:syncrow_app/features/menu/view/widgets/menu_list.dart';
import 'package:syncrow_app/features/menu/view/widgets/profile_tab.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
import 'package:syncrow_app/generated/assets.dart';
import 'package:syncrow_app/navigation/routing_constants.dart';
import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
class MenuView extends StatelessWidget {
const MenuView({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (BuildContext context) => MenuCubit(),
child: BlocBuilder<MenuCubit, MenuState>(
builder: (context, state) {
return BlocBuilder<AuthCubit, AuthState>(
builder: (context, state) {
return Padding(
padding: EdgeInsets.only(
top: Constants.appBarHeight,
bottom: Constants.bottomNavBarHeight,
left: Constants.defaultPadding,
right: Constants.defaultPadding,
),
child: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
child: Column(
children: [
const ProfileTab(),
for (var section in menuSections)
MenuList(
section: section,
),
const SizedBox(
height: 15,
),
InkWell(
onTap: () {
AuthCubit.get(context).logout();
Navigator.of(context).pushNamedAndRemoveUntil(
Routes.authLogin, (route) => false);
},
child: Row(
children: [
Expanded(
child: DefaultContainer(
child: Center(
child: BodyLarge(
text: 'Logout',
style: context.bodyLarge.copyWith(
color: Colors.red,
),
),
),
),
),
],
),
)
],
),
),
);
},
);
},
),
);
}
}
List<Map<String, Object>> menuSections = [
//Home Management
{
'title': 'Home Management',
'color': ColorsManager.primaryColor,
'buttons': [
{
'title': 'Create a Home',
'Icon': Assets.homeManagementIconsCreateHome,
'page': null
},
{
'title': 'Join a Home',
'Icon': Assets.homeManagementIconsJoinAHome,
'page': null
},
{
'title': 'Manage Your Home',
'Icon': Assets.homeManagementIconsManageYourHome,
'page': null
},
],
},
//General Settings
{
'title': 'General Settings',
'color': const Color(0xFF0030CB),
'buttons': [
{
'title': 'Voice Assistant',
'Icon': Assets.generalSettingsIconsVoiceAssistant,
'page': null
},
{
'title': 'Temperature unit',
'Icon': Assets.generalSettingsIconsTemperatureUnit,
'page': null
},
{
'title': 'Touch tone on panel',
'Icon': Assets.generalSettingsIconsTouchTone,
'page': null
},
{
'title': 'Language',
'Icon': Assets.generalSettingsIconsLanguage,
'page': null
},
{
'title': 'Network Diagnosis',
'Icon': Assets.generalSettingsIconsNetworkDiagnosis,
'page': null
},
{
'title': 'Clear Cache',
'Icon': Assets.generalSettingsIconsClearCache,
'page': null
},
],
},
//Messages Center
{
'title': 'Messages Center',
'color': const Color(0xFF0088FF),
'buttons': [
{
'title': 'Alerts',
'Icon': Assets.messagesCenterIconsAlerts,
'page': null
},
{
'title': 'Messages',
'Icon': Assets.messagesCenterIconsMessages,
'page': null
},
{'title': 'FAQs', 'Icon': Assets.messagesCenterIconsFAQs, 'page': null},
{
'title': 'Help & Feedback',
'Icon': Assets.messagesCenterIconsHelpAndFeedbacks,
'page': null
},
],
},
//Security And Privacy
{
'title': 'Security And Privacy',
'color': const Color(0xFF8AB9FF),
'buttons': [
{
'title': 'Security',
'Icon': Assets.securityAndPrivacyIconsSecurty,
'page': null
},
{
'title': 'Privacy',
'Icon': Assets.securityAndPrivacyIconsPrivacy,
'page': null
},
],
},
//Legal Information
{
'title': 'Legal Information',
'color': const Color(0xFF001B72),
'buttons': [
{'title': 'About', 'Icon': Assets.leagalInfoIconsAbout, 'page': null},
{
'title': 'Privacy Policy',
'Icon': Assets.leagalInfoIconsPrivacyPolicy,
'page': null
},
{
'title': 'User Agreement',
'Icon': Assets.leagalInfoIconsUserAgreement,
'page': null
},
],
},
];