fix: Resolve failed assertion error when updating profile data
When updating profile data in the ProfileScreen widget, a failed assertion error was occurring, with the message "renderObject.child == child is not true". After investigating the issue, it was determined that the error was related to a mismatch between the expected and actual data types, which was causing an issue with rendering the updated profile data in the UI.
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:inbox/core/utils/app_strings.dart';
import '../../../../../core/utils/app_colors.dart';
import '../../../controllers/auth/auth_cubit.dart';
import '../../../controllers/auth/auth_states.dart';
import '../widgets/my_profile_header.dart';
import '../widgets/profile_appbar.dart';
List<Tab> tabs = const [
Tab(text: AppStrings.posts),
Tab(text: AppStrings.videos),
];
class ProfileScreen extends StatelessWidget {
final bool fromSearch;
const ProfileScreen({Key? key, required this.fromSearch}) : super(key: key);
@override
Widget build(BuildContext context) {
return BlocBuilder<AuthCubit, AuthStates>(
builder: (context, state) {
var user = AuthCubit
.get(context)
.userEntity;
if (state is UpdateProfilePicSuccessState) {
AuthCubit.get(context).getCurrentUser();
} else if (state is GetCurrentUserSuccessState) {
user = AuthCubit
.get(context)
.userEntity;
}
return Scaffold(
appBar: ProfileAppBar(user: user!, fromSearch: fromSearch),
body: DefaultTabController(
length: 2,
child: NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) {
return [
SliverPersistentHeader(
pinned: false,
delegate: MyProfileHeader(user: user!),
),
];
},
body: Column(
children: [
Align(
alignment: AlignmentDirectional.centerStart,
child: TabBar(
unselectedLabelColor: AppColors.gray,
labelColor: AppColors.black,
isScrollable: true,
labelStyle: const TextStyle(fontWeight: FontWeight.w500),
indicatorSize: TabBarIndicatorSize.label,
tabs: tabs,
),
),
Expanded(
child: TabBarView(
children: [
Container(
color: Colors.redAccent,
),
Container(
color: Colors.blue,
),
],
),
)
],
),
),
),
);
},
);
}
}