Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
pending_collections_view.dart
Go to the documentation of this file.
1import 'package:easy_localization/easy_localization.dart';
2import 'package:flutter/material.dart';
3import 'package:flutter_bloc/flutter_bloc.dart';
4import 'package:flutter_screenutil/flutter_screenutil.dart';
5
6import '../../../../../../core/ui/widgets/loading.dart';
7import '../../../../../../core/ui/widgets/stats_card.dart';
8import '../../../../../../core/ui/theme/color_palette.dart';
9import '../../../../../../core/ui/widgets/empty_content.dart';
10import '../../../../../../core/common/entities/collection_entity.dart';
11import '../../../bloc/pending_collections/pending_collections_bloc.dart';
12import '../../../../../../core/ui/widgets/collection_item/collection_item.dart';
13import '../../../../../auth/presentation/bloc/authentication_bloc/authentication_bloc.dart';
14
16 const PendingCollectionsView({super.key});
17
18 @override
19 State<PendingCollectionsView> createState() => _PendingCollectionsViewState();
20}
21
22class _PendingCollectionsViewState extends State<PendingCollectionsView> {
23 @override
24 void initState() {
25 super.initState();
27 }
30 final authState = context.read<AuthenticationBloc>().state;
31 if (authState is AuthenticatedState) {
32 context.read<PendingCollectionsBloc>().add(
34 userId: authState.session.uid ?? 0,
35 ),
36 );
37 }
38 }
39
40 @override
41 Widget build(BuildContext context) {
42 return BlocBuilder<PendingCollectionsBloc, PendingCollectionsState>(
43 buildWhen: (previous, current) => current is PendingCollectionsLoading || current is PendingCollectionsLoaded || current is PendingCollectionsError,
44 builder: (context, state) {
45 if (state is PendingCollectionsLoaded) {
46 if (state.collections.isEmpty) {
47 return EmptyContent(text: "common.no_pending_collections".tr());
48 }
49 return ListView.builder(
50 physics: const AlwaysScrollableScrollPhysics(),
51 itemCount: state.collections.length + 1,
52 itemBuilder: (context, index) {
53 if (index == 0) {
54 return Padding(
55 padding: EdgeInsets.all(15.sp),
56 child: StatsCard(
57 title: "Pending Collections",
58 number: state.collections.length.toString(),
59 subtitle: _getCollectionQuantity(state.collections),
60 gradient: const LinearGradient(
61 begin: Alignment.topLeft,
62 end: Alignment.bottomRight,
63 colors: [ColorPalette.grey, ColorPalette.darkGrey],
64 ),
65 ),
66 );
67 }
68 return CollectionItem(
69 isPending: true,
70 number: '',
71 collection: state.collections[index - 1],
72 showNumber: false,
73 );
74 },
75 );
76 }
77 return const Loading();
78 },
79 );
80 }
81
82 String _getCollectionQuantity(List<CollectionEntity> collections) {
83 String quanitity = collections.fold<double>(
84 0, (prev, element) => prev + (element.volume ?? 0)
85 ).toInt().toString();
86 return '$quanitity L';
87 }
88}
override void initState()
class App extends StatefulWidget build(BuildContext context)
Definition app.dart:31
sealed class CheckInOutEvent extends Equatable userId
override State< PendingCollectionsView > createState()
const PendingCollectionsView({super.key})
sealed class CollectionsState extends Equatable collections
class Partner String
const LoadPendingCollectionsEvent({ required this.userId, })
const PendingCollectionsLoaded({required this.collections})
const PendingCollectionsView({super.key})
void _loadPendingCollections()
String _getCollectionQuantity(List< CollectionEntity > collections)
class SearchWeeklyCollectionsEvent extends WeeklyCollectionsEvent collection