Created
August 4, 2019 06:23
-
-
Save SAGARSURI/ed4619fe4ef85329a943cfdeac17580c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:typed_data'; | |
import 'package:esys_flutter_share/esys_flutter_share.dart'; | |
import 'bloc_base.dart'; | |
import '../repositories/repository.dart'; | |
import 'package:rxdart/rxdart.dart'; | |
import '../models/photos.dart'; | |
import '../repositories/state.dart'; | |
class HomeScreenBloc extends BlocBase { | |
static Repository _repository = Repository(); | |
PublishSubject<String> _query; | |
init() { | |
_query = PublishSubject<String>(); | |
} | |
Observable<Photos> get photosList => _query.stream | |
.debounceTime(Duration(milliseconds: 300)) | |
.where((String value) => value.isNotEmpty) | |
.distinct() | |
.transform(streamTransformer); | |
final streamTransformer = StreamTransformer<String, Photos>.fromHandlers( | |
handleData: (query, sink) async { | |
State state = await _repository.imageData(query); | |
if (state is SuccessState) { | |
sink.add(state.value); | |
} else { | |
sink.addError((state as ErrorState).msg); | |
} | |
}); | |
Function(String) get changeQuery => _query.sink.add; | |
@override | |
void dispose() { | |
_query.close(); | |
} | |
String getDescription(Result result) { | |
return (result.description == null || result.description.isEmpty) | |
? result.altDescription | |
: result.description; | |
} | |
void shareImage(String url) { | |
_repository.getImageToShare(url).then((Uint8List value) async { | |
await Share.file("Share via:","image.png",value,"image/png"); | |
}); | |
} | |
} | |
final bloc = HomeScreenBloc(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment