Line data Source code
1 : import 'dart:async';
2 :
3 : import 'package:app_pym/domain/usecases/cartographie/load_page_and_place_batiments.dart';
4 : import 'package:bloc/bloc.dart';
5 : import 'package:flutter/foundation.dart';
6 : import 'package:flutter_unity_widget/flutter_unity_widget.dart';
7 : import 'package:freezed_annotation/freezed_annotation.dart';
8 : import 'package:geolocator/geolocator.dart';
9 : import 'package:injectable/injectable.dart';
10 :
11 : part 'ar_view_bloc.freezed.dart';
12 : part 'ar_view_event.dart';
13 : part 'ar_view_state.dart';
14 :
15 : @prod
16 : @injectable
17 : class ArViewBloc extends Bloc<ArViewEvent, ArViewState> {
18 : UnityWidgetController unityWidgetController;
19 : final LoadPageAndPlaceBatiments loadPageAndPlaceBatiment;
20 :
21 1 : ArViewBloc(this.loadPageAndPlaceBatiment);
22 :
23 1 : @override
24 : ArViewState get initialState => const ArViewState.initial();
25 :
26 : @override
27 0 : Future<void> close() async {
28 0 : await (unityWidgetController?.pause() as Future);
29 0 : return super.close();
30 : }
31 :
32 : @override
33 1 : Stream<ArViewState> mapEventToState(
34 : ArViewEvent event,
35 : ) async* {
36 2 : yield* event.map(
37 1 : fetchFromUnity: (e) async* {
38 : try {
39 1 : yield const ArViewState.loading();
40 2 : unityWidgetController = e.unityWidgetController;
41 2 : await Future<Position>.delayed(
42 : const Duration(seconds: 2),
43 4 : () => loadPageAndPlaceBatiment(LoadPageAndPlaceBatimentParams(
44 1 : controller: unityWidgetController,
45 1 : bearingBetweenCameraAndNorth: e.bearingBetweenCameraAndNorth,
46 : )),
47 : );
48 1 : add(const ArViewEvent.loaded());
49 1 : } on Exception catch (e) {
50 2 : yield ArViewState.error(e);
51 : }
52 : },
53 1 : loaded: (e) async* {
54 1 : yield const ArViewState.loaded();
55 : },
56 : );
57 : }
58 : }
|