-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
url_page_bloc.dart
38 lines (31 loc) · 1.09 KB
/
url_page_bloc.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import 'dart:async';
import 'package:bloc/bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import '../../services/network_service.dart';
import '../../telemetry.dart';
part 'url_page_bloc.freezed.dart';
part 'url_page_event.dart';
part 'url_page_state.dart';
class UrlPageBloc extends Bloc<UrlPageEvent, UrlPageState> {
final wishSimulatorUrl = 'https://gi-wish-simulator.uzairashraf.dev';
final mapUrl = 'https://genshin-impact-map.appsample.com';
final NetworkService _networkService;
UrlPageBloc(this._networkService) : super(const UrlPageState.loading());
@override
Stream<UrlPageState> mapEventToState(
UrlPageEvent event,
) async* {
final s = await event.map(
init: (e) async {
final isInternetAvailable = await _networkService.isInternetAvailable();
await trackUrlOpened(e.loadMap, e.loadWishSimulator, isInternetAvailable);
return UrlPageState.loaded(
hasInternetConnection: isInternetAvailable,
mapUrl: mapUrl,
wishSimulatorUrl: wishSimulatorUrl,
);
},
);
yield s;
}
}