diff --git a/lib/feature/home/home.dart b/lib/feature/home/home.dart index 5c3ea11..0c03f54 100644 --- a/lib/feature/home/home.dart +++ b/lib/feature/home/home.dart @@ -13,18 +13,18 @@ class Home extends StatefulWidget { } class _HomeState extends State { - HomeBloc bloc; + HomeBloc _bloc; @override void initState() { super.initState(); - bloc = HomeBloc(); - bloc.loadDonations(); + _bloc = HomeBloc(); + _bloc.loadDonations(); } @override void dispose() { - bloc.dispose(); + _bloc.dispose(); super.dispose(); } @@ -41,7 +41,7 @@ class _HomeState extends State { StreamBuilder> _listFutureBuilder() { return StreamBuilder( - stream: bloc.controller.stream, + stream: _bloc.stream, builder: (BuildContext context, AsyncSnapshot> snapshot) { Widget widget = Center(child: CircularProgressIndicator()); diff --git a/lib/feature/home/home_bloc.dart b/lib/feature/home/home_bloc.dart index 9c70b65..56de0df 100644 --- a/lib/feature/home/home_bloc.dart +++ b/lib/feature/home/home_bloc.dart @@ -4,18 +4,20 @@ import 'package:flutter_workshop/model/donation/donation.dart'; import 'package:flutter_workshop/model/donation/donation_api.dart'; class HomeBloc { - final StreamController controller = StreamController>(); + final StreamController _controller = StreamController>(); + + get stream => _controller.stream; dispose() { - controller.close(); + _controller.close(); } loadDonations() async { try { final donations = await DonationApi().getDonations(); - controller.sink.add(donations); + _controller.sink.add(donations); } catch (error) { - controller.sink.addError(error); + _controller.sink.addError(error); } } } \ No newline at end of file diff --git a/lib/feature/login/login.dart b/lib/feature/login/login.dart index e1a70fe..cbb47a1 100644 --- a/lib/feature/login/login.dart +++ b/lib/feature/login/login.dart @@ -54,7 +54,7 @@ class _LoginState extends State { _passwordField(context), SizedBox(height: 60), StreamBuilder>( - stream: _bloc.controller.stream, + stream: _bloc.stream, builder: (context, AsyncSnapshot> snapshot) { bool isLoading = snapshot.hasData && snapshot.data.isLoading; diff --git a/lib/feature/login/login_bloc.dart b/lib/feature/login/login_bloc.dart index afb2cb8..541e42c 100644 --- a/lib/feature/login/login_bloc.dart +++ b/lib/feature/login/login_bloc.dart @@ -6,19 +6,21 @@ import 'package:flutter_workshop/model/login/login_response.dart'; import 'package:flutter_workshop/util/http_event.dart'; class LoginBloc { - final StreamController controller = + final StreamController _controller = StreamController>(); - dispose() => controller.close(); + get stream => _controller.stream; + + dispose() => _controller.close(); login(LoginRequest request) async { try { - controller.sink.add(HttpEvent(state: EventState.loading)); + _controller.sink.add(HttpEvent(state: EventState.loading)); final loginResponse = await LoginApi().login(request); - controller.sink.add(HttpEvent( + _controller.sink.add(HttpEvent( state: EventState.done, data: loginResponse)); } catch (error) { - controller.sink.addError(error); + _controller.sink.addError(error); } } }