Skip to content

Instantly share code, notes, and snippets.

@pawelsa
pawelsa / gist:db34ac0ad8e6eb40097f4ef5b8e66082
Created December 20, 2023 16:48
Removed hidden files from zip
zip -d Archive.zip "__MACOSX*"
@pawelsa
pawelsa / gist:ee3846ef1890f92f004924396d1dc270
Created December 20, 2023 13:29
create firebase flutter configs
flutterfire configure --project="<name of firebase project (general, not app)>" --out="lib/prod_options.dart" -i <ios bundle id -a <android app id> -y
@pawelsa
pawelsa / gist:381fc85d82658e153e1f476ecfa2c087
Created December 19, 2023 10:00
Remove all files from version control according to .gitignore
git rm --cached `git ls-files -i -c --exclude-from=.gitignore`
Widget _buildBody(StreamData<List<ContentData>> streamData){
return Stack(
children: [
ListView.builder(
itemCount: streamData.data.length,
itemBuilder: (context, index) {
final item = streamData.data[index];
return CardItem(
onTap: () => _onCardTap(context, item),
content: item,
final LoadingStatus _upcomingMoviesLoadingStatus = LoadingStatus();
Future<Result> getUpcomingMovies(int page) {
_upcomingMoviesLoadingStatus.isLoading = true;
return _movieApi.getUpcoming(page).then((content) {
if (content is ContentListResponse) {
final result = _getMoviesWithResp(content, false);
_upcomingMoviesLoadingStatus.isLoading = false;
return result;
}
extension LoadingStatusStreamExtension<T> on Stream<T> {
DataStream<T> withLoading(LoadingStatus loadingStatus) {
return combineLatest<bool, StreamData<T>>(loadingStatus.listen(),
(data, isLoading) {
if (isLoading) {
return LoadingData(data);
}
return ReadyData(data);
});
}
final LoadingStatus _upcomingMoviesLoadingStatus = LoadingStatus();
DataStream<List<ContentDetailData>> observeDetailedUpcoming() =>
_movieDao.observeAllUpcoming().asyncMap(getDetailsFromDb).combineLatest<bool,
StreamData<List<ContentDetailData>>>(_upcomingMoviesLoadingStatus.listen(),
(data, isLoading) {
if (isLoading) {
return LoadingData(data);
}
return ReadyData(data);
});
class LoadingStatus {
BehaviorSubject<bool>? _loadingController;
bool _isLoading = false;
bool _streamedInitialEvent = false;
set isLoading(bool isLoading) {
_isLoading = isLoading;
_publishLoadingState();
}
@freezed
class StreamData<T> with _$StreamData<T> {
factory StreamData.ready(T data) = ReadyData<T>;
factory StreamData.loading(T data) = LoadingData<T>;
}
@pawelsa
pawelsa / result.dart
Created June 26, 2022 17:57
Results that can be returned from repositories
@freezed
class ErrorCause with _$ErrorCause {
const factory ErrorCause.noInternet() = NoInternetError;
const factory ErrorCause.databaseSave() = DatabaseSaveError;
const factory ErrorCause.unknown() = UnknownError;
}
@freezed