bloc_provider
하위 위젯에 bloc을 제공합니다 (O(1)), 그리고 bloc은 bloc_provider가 내부적으로 보유한 상태에 따라 적절하게 해제됩니다.
하위 위젯에 bloc을 제공합니다 (O(1)), 그리고 bloc_provider가 내부적으로 보유한 상태에 따라 적절하게 정리됩니다.
아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
Provides BLoC(Business Logic Component) to descendant widget (O(1)), and the bloc is disposed automatically by the state which the bloc_provider holds internally.
bloc_provider was one of the good choice for BLoC pattern until early 2019, but I now recommend to use these instead.
bloc_provider will now be minimally maintained.
class CounterBloc implements Bloc {
final _countController = BehaviorSubject<int>.seeded(0);
final _incrementController = PublishSubject<void>();
CounterBloc() {
_incrementController
.scan<int>((sum, _v, _i) => sum + 1, 0)
.pipe(_countController);
}
ValueStream<int> get count => _countController;
Sink<void> get increment => _incrementController.sink;
@override
void dispose() async {
await _incrementController.close();
await _countController.close();
}
}
void main() => runApp(
// Create and provide the bloc.
BlocProvider<CounterBloc>(
creator: (_context, _bag) => CounterBloc(),
child: App(),
),
);
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Access the bloc with O(1) computation complexity.
final bloc = BlocProvider.of<CounterBloc>(context);
return MaterialApp(
home: Scaffold(
body: Center(
child: StreamBuilder<int>(
stream: bloc.count,
initialData: bloc.count.value,
builder: (context, snap) => Text(
'count: ${snap.data}',
style: Theme.of(context).textTheme.title,
),
),
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add),
onPressed: () => bloc.increment.add(null),
),
),
);
}
}
of method, which is used for accessing the bloc is O(1).
Please file feature requests and bugs at the issue tracker.
의존성 목록 4 개
{"sdk":"flutter"}{"sdk":"flutter"}any>=0.26.0 <1.0.0사용 목적에 따라 검색하고 개발 활동을 비교한 뒤 원본 저장소에서 요구 사항을 확인하세요.
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗