Last active
August 18, 2021 16:35
-
-
Save zs-dima/0d716c564048fe553f9fccb55f82a59c to your computer and use it in GitHub Desktop.
BlocPager to discuss
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 'package:bloc/bloc.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:pager/pager.dart'; | |
typedef BlocPagerCondition<State extends Object> = bool Function(State state); | |
class BlocPager<State extends Object> extends StatelessWidget { | |
final IStateObservable<State> bloc; | |
final PagerWidgetBuilder<State> builder; | |
final BlocPagerCondition<State>? buildWhen; | |
const BlocPager({ | |
Key? key, | |
required this.bloc, | |
required this.builder, | |
this.buildWhen, | |
}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
Stream<State> stream = bloc.stream; | |
if (buildWhen != null) stream = stream.where((state) => buildWhen!(state)); | |
return Pager<State>( | |
initialData: bloc.state, | |
stream: stream.distinct(), | |
builder: builder, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment