Files
tm_app/lib/views/profile/pages/m_profile_page.dart
T
amirrezaghabeli eb75952b8e profile tabs fixed
2026-04-19 12:37:39 +03:30

113 lines
3.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:tm_app/core/routes/app_routes.dart';
import 'package:tm_app/view_models/profile_view_model.dart';
import 'package:tm_app/views/profile/widgets/main_data_tab.dart';
import '../../../core/constants/common_strings.dart';
import '../../../core/theme/colors.dart';
import '../../../core/utils/app_toast.dart';
import '../../../core/utils/size_config.dart';
import '../../../view_models/auth_view_model.dart';
import '../../shared/tender_app_bar.dart';
import '../strings/profile_strings.dart';
import '../widgets/members_tab.dart';
import '../widgets/profile_tab_bar.dart';
import '../widgets/subject_tab.dart';
class MobileProfilePage extends StatefulWidget {
const MobileProfilePage({super.key});
@override
State<MobileProfilePage> createState() => _MobileProfilePageState();
}
class _MobileProfilePageState extends State<MobileProfilePage>
with SingleTickerProviderStateMixin {
late ProfileViewModel viewModel;
late final TabController tabController;
@override
void initState() {
super.initState();
viewModel = context.read<ProfileViewModel>();
tabController = TabController(length: 3, vsync: this);
viewModel.addListener(_profileListener);
// Load notification info saved in SharedPreferences
}
void _profileListener() {
if (viewModel.errorMessage != null) {
AppToast.error(context, viewModel.errorMessage!);
}
if (viewModel.loggedOut) {
context.read<AuthViewModel>().clearAuthFlow();
Router.neglect(context, () => const LoginScreenRoute().go(context));
}
}
@override
void dispose() {
viewModel.removeListener(_profileListener);
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.backgroundColor,
appBar: tenderMobileAppBar(title: ProfileStrings.profileTitle),
body: SafeArea(
child: Consumer<ProfileViewModel>(
builder: (context, viewModel, child) {
if (viewModel.isLoading) {
return const Center(
child: CircularProgressIndicator(color: AppColors.secondary50),
);
}
if (viewModel.errorMessage != null) {
return Center(child: Text(viewModel.errorMessage!));
}
if (viewModel.profileData == null) {
return const Center(child: Text(CommonStrings.noData));
}
return Padding(
padding: EdgeInsets.symmetric(
horizontal: 24.0.w(),
vertical: 16.0.h(),
),
child: Column(
children: [
ProfileTabBar(
controller: tabController,
titles: [
ProfileStrings.mainDataTab,
ProfileStrings.membersTab,
ProfileStrings.subjectTab,
],
),
Expanded(
child: TabBarView(
controller: tabController,
children: [
MainDataTab(
profileData: viewModel.profileData!,
onLogout: () => viewModel.logout(),
),
const MembersTab(),
const SubjectTab(),
],
),
),
],
),
);
},
),
),
);
}
}