Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hoc081098/did_change_dependencies

Return a Stream that emits null and done event when didChangeDependencies is called for the first time.
https://github.com/hoc081098/did_change_dependencies

dart-streams did-change-dependencies flutter-rx flutter-rxdart flutter-stream flutter-streams rxdart rxdart-bloc rxdart-debug-operator rxdart-ext rxdart-extension rxdart-extensions rxdart-flutter rxdart-helper

Last synced: 23 days ago
JSON representation

Return a Stream that emits null and done event when didChangeDependencies is called for the first time.

Awesome Lists containing this project

README

        

# did_change_dependencies
## Author: [Petrus Nguyễn Thái Học](https://github.com/hoc081098)

Return a `Stream` that emits null and done event when `State.didChangeDependencies` is called for the first time.

![Dart CI](https://github.com/hoc081098/did_change_dependencies/workflows/Flutter%20CI/badge.svg)
[![Pub](https://img.shields.io/pub/v/did_change_dependencies)](https://pub.dev/packages/did_change_dependencies)
[![Pub](https://img.shields.io/pub/v/did_change_dependencies?include_prereleases)](https://pub.dev/packages/did_change_dependencies)
[![codecov](https://codecov.io/gh/hoc081098/did_change_dependencies/branch/master/graph/badge.svg)](https://codecov.io/gh/hoc081098/did_change_dependencies)
[![GitHub](https://img.shields.io/github/license/hoc081098/did_change_dependencies?color=4EB1BA)](https://opensource.org/licenses/MIT)
[![Style](https://img.shields.io/badge/style-pedantic-40c4ff.svg)](https://github.com/dart-lang/pedantic)

## Example



```dart
import 'dart:async';

import 'package:did_change_dependencies/did_change_dependencies.dart';
import 'package:flutter/material.dart';
import 'package:rxdart_ext/rxdart_ext.dart';

class Bloc {
Stream message$ = Stream.empty(); // just demo
}

class MyPage extends StatefulWidget {
const MyPage({Key? key}) : super(key: key);

@override
_MyPageState createState() => _MyPageState();
}

class _MyPageState extends State with DidChangeDependenciesStream {
final bloc = Bloc();
final subscriptions = >[];

@override
void initState() {
super.initState();

final handle = (String msg) {
// safe to access ScaffoldMessengerState.
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(msg)),
);
};
subscriptions <<
didChangeDependencies$
.exhaustMap((value) => bloc.message$)
.listen(handle);

subscriptions <<
didChangeDependencies$.listen((event) {
// do something when `didChangeDependencies` is called for the first time.
});
}

@override
void dispose() {
super.dispose();
subscriptions.forEach((s) => s.cancel());
}

@override
Widget build(BuildContext context) {
return Container();
}
}

extension _ListExt on List {
void operator <<(T t) => add(t);
}
```