fix: plans - like and bookmark in consultant profile (#582)

- decouple PlanWidget from feed PlansCubit via owner-provided callbacks
- add like/favorite actions to profile PlansCubit: slug lookup, optimistic
  update, rollback of the affected plan, per-slug debounce, isClosed guards
- pass slug through like/favorite/comments events; guard out-of-range index
  in feed plans handlers and deep-link about_plan sync
- capture post like intent before await in profile blog post widget
- replace null force-unwraps in profile screen, guard indexOf == -1
- tests: profile plan like/bookmark, slug sync, bounds guards, #700 regression
This commit is contained in:
2026-11-20 16:30:13 +03:00
parent 1e8c1ab2eb
commit 0df474b2b5
22 changed files with 2139 additions and 137 deletions

View File

@@ -331,6 +331,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
}
Scaffold _myProfileScreen(ProfileStateLoaded state) {
final consultantInfo = state.consultantInfo;
return Scaffold(
backgroundColor: Colors.grey.shade200,
appBar: AppBar(
@@ -360,7 +361,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_header(state),
if (state.profile.roles.contains('consultant'))
if (state.profile.roles.contains('consultant') &&
consultantInfo != null)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -386,7 +388,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
borderRadius: BorderRadius.circular(12),
),
child: Text(
'${state.consultantInfo!.ratingPlace}-й в рейтинге',
'${consultantInfo.ratingPlace}-й в рейтинге',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
@@ -396,11 +398,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
),
],
),
if (state
.consultantInfo!
.educationModel
.hasMedicalEducation ==
1)
if (consultantInfo.educationModel.hasMedicalEducation == 1)
const Row(
children: [
SizedBox(width: 16),
@@ -451,6 +449,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
if (!state.profile.roles.contains('consultant') || hidePlans) {
return const SizedBox.shrink();
}
final profileSlug = state.profile.slug;
return BlocBuilder<PlansCubit, PlansState>(
bloc: plansCubit,
builder: (BuildContext context, PlansState state) {
@@ -486,7 +485,15 @@ class _ProfileScreenState extends State<ProfileScreen> {
});
},
itemBuilder: (BuildContext context, int index) {
return PlanWidget(plan: state.plansList[index], index: index);
return PlanWidget(
plan: state.plansList[index],
index: index,
onLikeTap: (slug) => plansCubit.likePlan(slug),
onToggleFavorite: (slug, isFavorite) => isFavorite
? plansCubit.removePlanFromFavorite(slug)
: plansCubit.addPlanToFavorite(slug),
onPlanChanged: () => plansCubit.getPlans(profileSlug),
);
},
),
const SizedBox(height: 8),
@@ -895,10 +902,11 @@ class _ProfileScreenState extends State<ProfileScreen> {
}
SingleChildRenderObjectWidget _socialLinks(ProfileStateLoaded state) {
if (!state.profile.roles.contains('consultant') &&
state.consultantInfo != null) {
final consultantInfo = state.consultantInfo;
if (!state.profile.roles.contains('consultant') || consultantInfo == null) {
return const SizedBox.shrink();
}
final educationModel = consultantInfo.educationModel;
return Padding(
padding:
const EdgeInsets.symmetric(horizontal: 4) +
@@ -913,47 +921,34 @@ class _ProfileScreenState extends State<ProfileScreen> {
_socialLinkButton(
() {
launchUrl(
Uri.parse(
state.consultantInfo!.educationModel.vkLink ?? '',
),
Uri.parse(educationModel.vkLink ?? ''),
mode: LaunchMode.externalApplication,
);
},
'assets/icons/vk.svg',
state.consultantInfo!.educationModel.vkLink!.isEmpty
? true
: false,
educationModel.vkLink?.isEmpty ?? true,
),
const SizedBox(width: 12),
_socialLinkButton(
() {
launchUrl(
Uri.parse(
state.consultantInfo!.educationModel.tgLink ?? '',
),
Uri.parse(educationModel.tgLink ?? ''),
mode: LaunchMode.externalApplication,
);
},
'assets/icons/telegram.svg',
state.consultantInfo!.educationModel.tgLink!.isEmpty
? true
: false,
educationModel.tgLink?.isEmpty ?? true,
),
const SizedBox(width: 12),
_socialLinkButton(
() {
launchUrl(
Uri.parse(
state.consultantInfo!.educationModel.personalSiteLink ??
'',
),
Uri.parse(educationModel.personalSiteLink ?? ''),
mode: LaunchMode.externalApplication,
);
},
'assets/icons/web.svg',
state.consultantInfo!.educationModel.personalSiteLink!.isEmpty
? true
: false,
educationModel.personalSiteLink?.isEmpty ?? true,
),
],
),