Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
today_schedule_screen.dart
Go to the documentation of this file.
1import 'package:easy_localization/easy_localization.dart';
2import 'package:fluentui_system_icons/fluentui_system_icons.dart';
3import 'package:flutter_bloc/flutter_bloc.dart';
4import 'package:go_router/go_router.dart';
5import 'package:flutter/material.dart';
6
7import '../../../../../core/common/enums/collection_status.dart';
8// import '../../../../../core/services/service_locator.dart';
9import '../../../../../core/ui/widgets/empty_content.dart';
10import '../../../../../core/ui/widgets/error_widget.dart';
11import '../../../../../core/ui/widgets/loading.dart';
12// import '../../../../auth/data/datasources/local_datasource/token_local_datasource.dart';
13import '../../../../auth/presentation/bloc/authentication_bloc/authentication_bloc.dart';
14import '../../../../../core/ui/widgets/custom_scaffold.dart';
15import '../../../../../core/ui/widgets/tab_selector.dart';
16import '../../../../../core/ui/theme/color_palette.dart';
17import '../../../../../core/ui/widgets/collection_item/collection_item.dart';
18import 'widgets/stats_section/stats_section.dart';
19import 'views/collections_map_view.dart'; // Add this import
20import '../../../../../core/router/routes.dart';
21import '../../bloc/collections_bloc/collections_bloc.dart';
22
23class TodayScheduleScreen extends StatefulWidget {
24 const TodayScheduleScreen({super.key});
25
26 @override
27 State<TodayScheduleScreen> createState() => _TodayScheduleScreenState();
28}
29
30class _TodayScheduleScreenState extends State<TodayScheduleScreen> {
31 final scrollController = ScrollController();
32 bool isToDoSelected = true;
33 bool isMapView = false;
34
35 void _toggleTab(bool isToDo) {
36 setState(() {
37 isToDoSelected = isToDo;
38 });
40 }
41
42 void _toggleView() {
43 setState(() {
44 scrollController.animateTo(
45 0,
46 duration: Duration(milliseconds: 500),
47 curve: Curves.easeInOut,
48 );
50 });
51 }
52
54 final authState = context.read<AuthenticationBloc>().state;
55
56 if (authState is AuthenticatedState) {
57 context.read<CollectionsBloc>().add(
59 userId: authState.session.uid ?? 0,
60 notForToday: false,
61 type: isToDoSelected ? 'todo' : null,
62 ),
63 );
64 }
65 }
66
67 @override
68 void initState() {
69 super.initState();
71 }
72
73 @override
74 Widget build(BuildContext context) {
75 return BlocBuilder<CollectionsBloc, CollectionsState>(
76 buildWhen: (_, current) => current is CollectionsLoaded || current is CollectionsError || current is CollectionsLoading,
77 builder: (context, state) {
78 return CustomScaffold(
79 onRefresh: () => _loadCollections(),
80 title: 'today_schedule.title'.tr(),
81 backgroundColor: ColorPalette.antiFlashWhite,
82 actions: [
83 // MaterialButton(
84 // onPressed: () async {
85 // final tokenLocaldataDource = sl<TokenLocalDataSource>();
86 // await tokenLocaldataDource.deleteToken();
87 // await tokenLocaldataDource.saveToken(token: "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJkcml2ZXJAYWlkcmEudGVjaCIsImlhdCI6MTc0MzY4ODQ3NCwiZXhwIjoxNzQzNjkyMDc0fQ.b-FLS_JSy6xcLvG4hdZQNDtB7EAYQMgr-642BGHrAlZF4YCWrE8UC4-ubIjq3j8D2X1_TgTPe3zrsDvt3oG9YA");
88 // },
89 // child: Text("inject expired token"),
90 // ),
92 IconButton(
93 icon: Icon(isMapView ? FluentIcons.list_16_regular : FluentIcons.map_16_regular),
95 tooltip: isMapView ? 'Switch to List View' : 'Switch to Map View',
96 ),
97 ],
98 body: CustomScrollView(
99 controller: scrollController,
100 physics: (isMapView && isToDoSelected)
101 ? NeverScrollableScrollPhysics()
102 : AlwaysScrollableScrollPhysics(),
103 slivers: [
104 SliverToBoxAdapter(
105 child: TabSelector(
106 onTabSelected: _toggleTab,
107 firstTabName: 'today_schedule.todo'.tr(),
108 secondTabName: 'today_schedule.completed'.tr(),
109 initialSelection: isToDoSelected,
110 ),
111 ),
112 if (!isMapView || !isToDoSelected)
113 StatsSection(state: state, isToDoSelected: isToDoSelected),
114 if (state is CollectionsLoading) const SliverFillRemaining(child: Loading())
115 else if (state is CollectionsLoaded)
116 state.collections.isEmpty ? const SliverFillRemaining(
117 child: EmptyContent(text: 'No collections for today'),
118 ) : isMapView && isToDoSelected ?
119 SliverFillRemaining(
120 child: CollectionsMapView(collections: state.collections),
121 ) :
122 SliverList(
123 delegate: SliverChildBuilderDelegate(
124 (context, index) {
125 final collection = state.collections[index];
126 return InkWell(
127 onTap: () {
128 context.push(
129 Routes.collectionDetailsScreen.route,
130 extra: collection,
131 );
132 },
133 child: CollectionItem(
134 isCompleted: collection.status == CollectionStatus.done,
135 showNumber: collection.status == CollectionStatus.done ? false : true,
137 number: (index + 1).toString(),
138 ),
139 );
140 },
141 childCount: state.collections.length,
142 ),
143 )
144 else if (state is CollectionsError)
145 SliverFillRemaining(
146 child: CustomErrorWidget(
147 message: "Connection failed",
148 onReload: _loadCollections,
149 ),
150 ),
151 ],
152 ),
153 );
154 },
155 );
156 }
157}
override void initState()
class App extends StatefulWidget build(BuildContext context)
Definition app.dart:31
AuthGuard _()
sealed class CheckInOutEvent extends Equatable userId
static const antiFlashWhite
override State< TodayScheduleScreen > createState()
const TodayScheduleScreen({super.key})
CollectionStatus
const LoadCollectionsEvent({ required this.userId, required this.notForToday, required this.type, })
final String type
final bool notForToday
const CollectionsLoaded({required this.collections})
sealed class CollectionsState extends Equatable collections
final Widget child
final String message
Definition failures.dart:0
final VoidCallback onPressed
final String tooltip
Routes
Definition routes.dart:30
final VoidCallback onTap
final String title
void _toggleTab(bool value)
class TodayScheduleScreen extends StatefulWidget scrollController
void _toggleView()
bool isToDoSelected
void _loadCollections()
class SearchWeeklyCollectionsEvent extends WeeklyCollectionsEvent collection