feat(time_card): refactor TimeCardPage to use StatelessWidget and optimize Bloc initialization
feat(time_card): change GetTimeCardsUseCase to lazy singleton in StaffTimeCardModule feat(clock_in): update use cases to lazy singleton in StaffClockInModule
This commit is contained in:
@@ -57,10 +57,10 @@ class StaffClockInModule extends Module {
|
||||
);
|
||||
|
||||
// Use Cases
|
||||
i.add<GetTodaysShiftUseCase>(GetTodaysShiftUseCase.new);
|
||||
i.add<GetAttendanceStatusUseCase>(GetAttendanceStatusUseCase.new);
|
||||
i.add<ClockInUseCase>(ClockInUseCase.new);
|
||||
i.add<ClockOutUseCase>(ClockOutUseCase.new);
|
||||
i.addLazySingleton<GetTodaysShiftUseCase>(GetTodaysShiftUseCase.new);
|
||||
i.addLazySingleton<GetAttendanceStatusUseCase>(GetAttendanceStatusUseCase.new);
|
||||
i.addLazySingleton<ClockInUseCase>(ClockInUseCase.new);
|
||||
i.addLazySingleton<ClockOutUseCase>(ClockOutUseCase.new);
|
||||
|
||||
// Validators
|
||||
i.addLazySingleton<CompositeClockInValidator>(
|
||||
|
||||
@@ -1,41 +1,26 @@
|
||||
// ignore_for_file: always_specify_types, depend_on_referenced_packages, dead_code, dead_null_aware_expression, unused_local_variable, unused_import, sort_constructors_first, prefer_final_fields, prefer_const_constructors, deprecated_member_use, implicit_call_tearoffs, implementation_imports
|
||||
import 'package:core_localization/core_localization.dart';
|
||||
import 'package:design_system/design_system.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_modular/flutter_modular.dart';
|
||||
import 'package:core_localization/core_localization.dart';
|
||||
import 'package:design_system/design_system.dart';
|
||||
import 'package:krow_core/core.dart';
|
||||
import '../blocs/time_card_bloc.dart';
|
||||
import '../widgets/month_selector.dart';
|
||||
import '../widgets/shift_history_list.dart';
|
||||
import '../widgets/time_card_skeleton/time_card_skeleton.dart';
|
||||
import '../widgets/time_card_summary.dart';
|
||||
import 'package:staff_time_card/src/presentation/blocs/time_card_bloc.dart';
|
||||
import 'package:staff_time_card/src/presentation/widgets/month_selector.dart';
|
||||
import 'package:staff_time_card/src/presentation/widgets/shift_history_list.dart';
|
||||
import 'package:staff_time_card/src/presentation/widgets/time_card_skeleton/time_card_skeleton.dart';
|
||||
import 'package:staff_time_card/src/presentation/widgets/time_card_summary.dart';
|
||||
|
||||
/// The main page for displaying the staff time card.
|
||||
class TimeCardPage extends StatefulWidget {
|
||||
class TimeCardPage extends StatelessWidget {
|
||||
/// Creates a [TimeCardPage].
|
||||
const TimeCardPage({super.key});
|
||||
|
||||
@override
|
||||
State<TimeCardPage> createState() => _TimeCardPageState();
|
||||
}
|
||||
|
||||
class _TimeCardPageState extends State<TimeCardPage> {
|
||||
late final TimeCardBloc _bloc;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_bloc = Modular.get<TimeCardBloc>();
|
||||
_bloc.add(LoadTimeCards(DateTime.now()));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Translations t = Translations.of(context);
|
||||
return Scaffold(
|
||||
appBar: UiAppBar(title: t.staff_time_card.title, showBackButton: true),
|
||||
body: BlocProvider.value(
|
||||
value: _bloc,
|
||||
body: BlocProvider<TimeCardBloc>.value(
|
||||
value: Modular.get<TimeCardBloc>()..add(LoadTimeCards(DateTime.now())),
|
||||
child: BlocConsumer<TimeCardBloc, TimeCardState>(
|
||||
listener: (BuildContext context, TimeCardState state) {
|
||||
if (state is TimeCardError) {
|
||||
@@ -72,22 +57,24 @@ class _TimeCardPageState extends State<TimeCardPage> {
|
||||
children: <Widget>[
|
||||
MonthSelector(
|
||||
selectedDate: state.selectedMonth,
|
||||
onPreviousMonth: () => _bloc.add(
|
||||
ChangeMonth(
|
||||
DateTime(
|
||||
state.selectedMonth.year,
|
||||
state.selectedMonth.month - 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
onNextMonth: () => _bloc.add(
|
||||
ChangeMonth(
|
||||
DateTime(
|
||||
state.selectedMonth.year,
|
||||
state.selectedMonth.month + 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
onPreviousMonth: () =>
|
||||
ReadContext(context).read<TimeCardBloc>().add(
|
||||
ChangeMonth(
|
||||
DateTime(
|
||||
state.selectedMonth.year,
|
||||
state.selectedMonth.month - 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
onNextMonth: () =>
|
||||
ReadContext(context).read<TimeCardBloc>().add(
|
||||
ChangeMonth(
|
||||
DateTime(
|
||||
state.selectedMonth.year,
|
||||
state.selectedMonth.month + 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: UiConstants.space6),
|
||||
TimeCardSummary(
|
||||
|
||||
@@ -30,7 +30,7 @@ class StaffTimeCardModule extends Module {
|
||||
);
|
||||
|
||||
// UseCases
|
||||
i.add<GetTimeCardsUseCase>(GetTimeCardsUseCase.new);
|
||||
i.addLazySingleton<GetTimeCardsUseCase>(GetTimeCardsUseCase.new);
|
||||
|
||||
// Blocs
|
||||
i.add<TimeCardBloc>(TimeCardBloc.new);
|
||||
|
||||
Reference in New Issue
Block a user