This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
imagini/web_native/lib/blocs/home_bloc.dart

53 lines
1.5 KiB
Dart
Raw Normal View History

2021-02-21 17:31:03 +00:00
import 'dart:async';
import 'package:imagini/core/imagini_application.dart';
import 'package:imagini/api/imagini_api_repository.dart';
import 'package:imagini/graphql/imagini_graphql.dart';
import 'package:cached_network_image/cached_network_image.dart';
2021-02-21 17:31:03 +00:00
class HomeBloc{
final ImaginiApplication _application;
ImaginiAPIRepository _imaginiAPI;
final _mediaItemsController = StreamController<MediaItems$Query>.broadcast();
Stream<MediaItems$Query> get mediaItemsResult => _mediaItemsController.stream;
final _loginController = StreamController<bool>.broadcast();
Stream<bool> get loginResult => _loginController.stream;
final _authenticatedController = StreamController<bool>.broadcast();
Stream<bool> get authenticatedResult => _authenticatedController.stream;
HomeBloc(this._application){
_init();
}
void _init(){
_imaginiAPI = _application.imaginiAPI;
getMediaItems();
}
void dispose(){
_loginController.close();
_authenticatedController.close();
_mediaItemsController.close();
}
Future<CachedNetworkImage> getImage(String fileName, int derivedContentWidth){
return _imaginiAPI.getImage(fileName, derivedContentWidth);
2021-02-21 17:31:03 +00:00
}
getMediaItems(){
_mediaItemsController.addStream(_imaginiAPI.mediaItems());
}
checkAuthentication(){
_authenticatedController.addStream(_imaginiAPI.isAuthenticated());
}
attemptHome(String username, password, server){
_loginController.addStream(_imaginiAPI.login(username, password, server));
}
}