forked from eatvio/eatvio_app
feat(profile): subscribers and subscriptions
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:eatvio_app/core/const.dart';
|
||||
import 'package:eatvio_app/core/widgets/loader.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/widgets/blog_post_widget.dart';
|
||||
import 'package:eatvio_app/features/profile/models/circumference_model.dart';
|
||||
import 'package:eatvio_app/features/profile/models/weight_model.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_state.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/pages/subs_screen.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/widgets/circumference_chart_widget.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/widgets/imt_chart_widget.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/widgets/weight_chart_widget.dart';
|
||||
@@ -14,7 +16,6 @@ import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:rive/rive.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
|
||||
class ProfileScreen extends StatefulWidget {
|
||||
@@ -56,7 +57,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
circumferencePoints = state.circumferencePoints!;
|
||||
weightPoints = state.weightPoints!;
|
||||
}
|
||||
return _profileScreen(state);
|
||||
return widget.author == null ? _myProfileScreen(state) : _profileScreen(state);
|
||||
} else if (state is ProfileStateError) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
@@ -70,15 +71,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
} else {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
height: 32,
|
||||
width: 32,
|
||||
child: RiveAnimation.asset(
|
||||
'assets/rive_animations/loading.riv',
|
||||
),
|
||||
),
|
||||
),
|
||||
body: const Loader(),
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -88,7 +81,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
_profileScreen(ProfileStateLoaded state) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.grey.shade200,
|
||||
appBar: widget.author == null ? AppBar(toolbarHeight: 0) : AppBar(),
|
||||
appBar: AppBar(),
|
||||
body: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -105,26 +98,56 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
children: [
|
||||
_header(state),
|
||||
if (state.profileDetails.additionalInfo.isNotEmpty) _additionalInfo(state),
|
||||
if (widget.author != null) const SizedBox(height: 8),
|
||||
if (widget.author != null) _messageAndSubscribe(),
|
||||
if (widget.author != null) const SizedBox(height: 16),
|
||||
const SizedBox(height: 8),
|
||||
_messageAndSubscribe(),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
_subscriptionsAndSubscribers(state),
|
||||
if(state.profile.badges.isNotEmpty) _badges(state),
|
||||
if (widget.author == null) const SizedBox(height: 16),
|
||||
if (state.profile.badges.isNotEmpty) _badges(state),
|
||||
_socialLinks(state),
|
||||
if (widget.author == null) const SizedBox(height: 16),
|
||||
_education(state),
|
||||
if (widget.author == null) const SizedBox(height: 16),
|
||||
_diplomasAndCertificates(state),
|
||||
if (widget.author == null) const SizedBox(height: 16),
|
||||
if (widget.author == null) _charts(),
|
||||
if (widget.author == null) const SizedBox(height: 16),
|
||||
_activePlans(state),
|
||||
if (widget.author == null) const SizedBox(height: 16),
|
||||
if (widget.author == null) _newBlogPostButton(),
|
||||
_blogPosts(state),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_myProfileScreen(ProfileStateLoaded state) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.grey.shade200,
|
||||
appBar: AppBar(toolbarHeight: 0),
|
||||
body: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.vertical(
|
||||
bottom: Radius.circular(16),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
_header(state),
|
||||
if (state.profileDetails.additionalInfo.isNotEmpty) _additionalInfo(state),
|
||||
],
|
||||
),
|
||||
),
|
||||
_subscriptionsAndSubscribers(state),
|
||||
if (state.profile.badges.isNotEmpty) Padding(padding: EdgeInsets.only(bottom: 16), child: _badges(state)),
|
||||
if (state.profile.role == 'consultant') Padding(padding: EdgeInsets.only(bottom: 16), child: _socialLinks(state)),
|
||||
if (state.profile.role == 'consultant') Padding(padding: EdgeInsets.only(bottom: 16), child: _education(state)),
|
||||
if (state.profile.role == 'consultant') Padding(padding: EdgeInsets.only(bottom: 16), child: _diplomasAndCertificates(state)),
|
||||
Padding(padding: EdgeInsets.only(bottom: 16), child: _charts()),
|
||||
if (state.profile.role == 'consultant') Padding(padding: EdgeInsets.only(bottom: 16), child: _activePlans(state)),
|
||||
_newBlogPostButton(),
|
||||
_blogPosts(state),
|
||||
],
|
||||
),
|
||||
@@ -511,7 +534,13 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
child: Row(
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () {},
|
||||
onTap: () => GoRouter.of(context).pushNamed(
|
||||
'subsScreen',
|
||||
extra: SubType.Subscriptions,
|
||||
pathParameters: {
|
||||
'slug': state.profile.slug,
|
||||
},
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Ink(
|
||||
padding: const EdgeInsets.all(8),
|
||||
@@ -555,7 +584,13 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
InkWell(
|
||||
onTap: () {},
|
||||
onTap: () => GoRouter.of(context).pushNamed(
|
||||
'subsScreen',
|
||||
extra: SubType.Subscribers,
|
||||
pathParameters: {
|
||||
'slug': state.profile.slug,
|
||||
},
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Ink(
|
||||
padding: const EdgeInsets.all(8),
|
||||
|
||||
69
lib/features/profile/presentation/pages/subs_screen.dart
Normal file
69
lib/features/profile/presentation/pages/subs_screen.dart
Normal file
@@ -0,0 +1,69 @@
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/widgets/loader.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/sub_cubit/sub_cubit.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/sub_cubit/sub_state.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/widgets/sub_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
enum SubType { Subscribers, Subscriptions }
|
||||
|
||||
class SubsScreen extends StatefulWidget {
|
||||
final SubType subType;
|
||||
final String slug;
|
||||
|
||||
const SubsScreen({
|
||||
super.key,
|
||||
required this.slug,
|
||||
required this.subType,
|
||||
});
|
||||
|
||||
@override
|
||||
State<SubsScreen> createState() => _SubsScreenState();
|
||||
}
|
||||
|
||||
class _SubsScreenState extends State<SubsScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<SubCubit>(
|
||||
create: (BuildContext context) => widget.subType == SubType.Subscriptions
|
||||
? (sl<SubCubit>()
|
||||
..getSubscriptions(
|
||||
widget.slug,
|
||||
))
|
||||
: (sl<SubCubit>()
|
||||
..getSubscribers(
|
||||
widget.slug,
|
||||
)),
|
||||
child: BlocBuilder<SubCubit, SubState>(
|
||||
builder: (BuildContext context, SubState state) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
widget.subType == SubType.Subscriptions ? 'Подписки' : 'Подписчики',
|
||||
),
|
||||
),
|
||||
body: _buildStates(state),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_buildStates(SubState state) {
|
||||
if (state is SubStateLoading) {
|
||||
return Loader();
|
||||
}
|
||||
if (state is SubStateError) {
|
||||
return Text(state.errorMessage);
|
||||
}
|
||||
if (state is SubStateLoaded) {
|
||||
return ListView.builder(
|
||||
itemBuilder: (context, index) => SubWidget(
|
||||
subModel: state.subList[index],
|
||||
),
|
||||
itemCount: state.subList.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user