LCOV - code coverage report
Current view: top level - lib/presentation/blocs/mobility/stop_details - stop_details_bloc.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 32 0.0 %
Date: 2020-06-26 11:36:11 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:app_pym/core/constants/mobility.dart';
       2             : import 'package:app_pym/domain/entities/mobility/stop_time.dart';
       3             : import 'package:app_pym/domain/entities/mobility/trip.dart';
       4             : import 'package:flutter/foundation.dart';
       5             : import 'package:flutter/material.dart';
       6             : import 'package:flutter_bloc/flutter_bloc.dart';
       7             : import 'package:freezed_annotation/freezed_annotation.dart';
       8             : import 'package:injectable/injectable.dart';
       9             : 
      10             : part 'stop_details_bloc.freezed.dart';
      11             : part 'stop_details_event.dart';
      12             : part 'stop_details_state.dart';
      13             : 
      14             : @prod
      15             : @injectable
      16             : class StopDetailsBloc extends Bloc<StopDetailsEvent, StopDetailsState> {
      17           0 :   @override
      18           0 :   StopDetailsState get initialState => StopDetailsState.initial();
      19             : 
      20             :   @override
      21           0 :   Stream<StopDetailsState> mapEventToState(
      22             :     StopDetailsEvent event,
      23             :   ) async* {
      24           0 :     yield* event.when(
      25           0 :       show: (id, trips, isBus) async* {
      26           0 :         yield state.loading();
      27             :         try {
      28           0 :           final List<String> infos = id.split(
      29             :               "_"); // id au format bus_direction(aller/partir)_sens(aller/retour)_nom
      30           0 :           final String stop_name = infos[0];
      31             :           final String destination = isBus
      32             :               ? MobilityConstants.pymStop
      33             :               : MobilityConstants.gareGardanne;
      34           0 :           final Direction direction = infos[1] == "Direction.Aller"
      35             :               ? Direction.Aller
      36             :               : Direction.Partir;
      37           0 :           final Sens sens = infos[2] == "Sens.Aller" ? Sens.Aller : Sens.Retour;
      38             : 
      39           0 :           final List<StopTime> trip = direction.index == sens.index
      40           0 :               ? trips[sens.index].stop_time
      41           0 :               : trips[6 + sens.index].stop_time;
      42           0 :           final String last_stop = trip.last.stop.stop_name;
      43           0 :           final List<String> arrivalTimes = [];
      44             :           // Le top 3 des horaires du marker
      45           0 :           for (int i = 0; i < 3; i++) {
      46           0 :             if (direction.index == sens.index) {
      47           0 :               arrivalTimes.add(trips[2 * i + sens.index]
      48           0 :                   .stop_time
      49           0 :                   .firstWhere(
      50           0 :                       (stop_time) => stop_time.stop.stop_name == stop_name)
      51           0 :                   .arrival_time);
      52             :             } else {
      53           0 :               arrivalTimes.add(trips[6 + 2 * i + sens.index]
      54           0 :                   .stop_time
      55           0 :                   .firstWhere(
      56           0 :                       (stop_time) => stop_time.stop.stop_name == stop_name)
      57           0 :                   .arrival_time);
      58             :             }
      59             :           }
      60           0 :           yield state.loaded(
      61             :             isBus,
      62             :             stop_name,
      63             :             last_stop,
      64             :             arrivalTimes,
      65             :             trip,
      66             :             destination,
      67             :           );
      68           0 :         } on Exception catch (e) {
      69           0 :           yield state.error(e);
      70             :         }
      71             :       },
      72           0 :       hide: () async* {
      73           0 :         yield StopDetailsState.initial();
      74             :       },
      75             :     );
      76             :   }
      77             : }

Generated by: LCOV version 1.13