forked from eatvio/eatvio_app
84 lines
3.0 KiB
Dart
84 lines
3.0 KiB
Dart
import 'package:eatvio_app/core/app_export.dart';
|
|
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
|
import 'package:eatvio_app/features/profile/models/profile_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/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';
|
|
import 'package:eatvio_app/locator_service.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class ProfileScreen extends StatefulWidget {
|
|
final Author? author;
|
|
|
|
const ProfileScreen({super.key, this.author});
|
|
|
|
@override
|
|
State<ProfileScreen> createState() => _ProfileScreenState();
|
|
}
|
|
|
|
class _ProfileScreenState extends State<ProfileScreen> {
|
|
List<Circumference> chartData = [];
|
|
List<ChartPoint> chartPoints = [];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocProvider<ProfileCubit>(
|
|
create: (BuildContext context) {
|
|
if (widget.author == null)
|
|
return sl<ProfileCubit>()..getMyProfile();
|
|
else
|
|
return sl<ProfileCubit>()..getProfileBySlug(widget.author!.authorSlug);
|
|
},
|
|
child: BlocBuilder<ProfileCubit, ProfileState>(
|
|
builder: (BuildContext context, ProfileState state) {
|
|
if (state is ProfileStateLoaded) {
|
|
chartData = state.profile.circumferences;
|
|
chartPoints = state.profile.chartPoints;
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
toolbarHeight: 0,
|
|
),
|
|
body: SingleChildScrollView(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 16, bottom: 32),
|
|
child: CircleAvatar(
|
|
radius: 32,
|
|
backgroundImage: NetworkImage(state.profile.user.profilePhotoUrl),
|
|
),
|
|
),
|
|
CircumferenceChartWidget(chartData: chartData),
|
|
WeightChartWidget(chartPoints: chartPoints),
|
|
ImtChartWidget(chartPoints: chartPoints),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
} else if (state is ProfileStateError) {
|
|
return Scaffold(
|
|
appBar: AppBar(),
|
|
body: Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Text(state.errorMessage),
|
|
),
|
|
),
|
|
);
|
|
} else {
|
|
return Scaffold(
|
|
appBar: AppBar(),
|
|
body: Center(
|
|
child: CircularProgressIndicator(),
|
|
),
|
|
);
|
|
}
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|