From d8cbed2cd18ef3763a3ac912cd0cc88fd91e8b6a Mon Sep 17 00:00:00 2001 From: AYM1607 Date: Tue, 23 Apr 2019 02:01:35 -0500 Subject: [PATCH] Several fixes and formatting. Fixed a bug where a stream subscription wasn't being closed by the Carousel widget --- lib/src/blocs/events_bloc.dart | 35 +++++++++++++++++++++++++++ lib/src/screens/events_screen.dart | 15 ++++++++++-- lib/src/widgets/app_bar.dart | 24 ++++++++++++------ lib/src/widgets/avatar.dart | 2 +- lib/src/widgets/carousel.dart | 5 ++++ lib/src/widgets/event_list_tile.dart | 0 lib/src/widgets/home_app_bar.dart | 4 +-- lib/src/widgets/populated_drawer.dart | 1 + 8 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 lib/src/blocs/events_bloc.dart create mode 100644 lib/src/widgets/event_list_tile.dart diff --git a/lib/src/blocs/events_bloc.dart b/lib/src/blocs/events_bloc.dart new file mode 100644 index 0000000..505e737 --- /dev/null +++ b/lib/src/blocs/events_bloc.dart @@ -0,0 +1,35 @@ +import 'dart:async'; + +import 'package:rxdart/rxdart.dart'; + +import '../models/event_model.dart'; +import '../resources/firestore_provider.dart'; +import '../resources/google_sign_in_provider.dart'; +import '../services/auth_service.dart'; + +export '../services/auth_service.dart' show FirebaseUser; + +class EventsBloc { + /// An instance of the auth service. + AuthService _auth = authService; + + /// An instance of the firestore provider. + FirestoreProvider _firestore = firestoreProvider; + + /// A subject of list of event model. + final _events = BehaviorSubject>(); + + /// An observable of the current logged in user. + Observable get userStream => _auth.userStream; + + /// Initiates the fetching process of events linked to the current user. + Future fetchEvents() async { + final userModel = await _auth.getCurrentUserModel(); + _firestore.getUserEvents(userModel.id).pipe(_events); + } + + dispose() async { + await _events.drain(); + _events.close(); + } +} diff --git a/lib/src/screens/events_screen.dart b/lib/src/screens/events_screen.dart index a8d8bed..c349705 100644 --- a/lib/src/screens/events_screen.dart +++ b/lib/src/screens/events_screen.dart @@ -1,7 +1,18 @@ -import 'package:flutter/material.dart'; +import 'package:flutter/material.dart' hide AppBar; + +import '../widgets/app_bar.dart'; +import '../widgets/populated_drawer.dart'; class EventsScreen extends StatelessWidget { Widget build(BuildContext context) { - return Scaffold(); + return Scaffold( + drawer: PopulatedDrawer( + selectedScreen: Screen.events, + ), + appBar: AppBar( + title: 'My Events', + hasDrawer: true, + ), + ); } } diff --git a/lib/src/widgets/app_bar.dart b/lib/src/widgets/app_bar.dart index 7f98b3a..9b97853 100644 --- a/lib/src/widgets/app_bar.dart +++ b/lib/src/widgets/app_bar.dart @@ -37,13 +37,7 @@ class AppBar extends StatelessWidget implements PreferredSizeWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - IconButton( - icon: Icon( - FontAwesomeIcons.arrowLeft, - color: Color.fromRGBO(112, 112, 112, 1), - ), - onPressed: () => Navigator.of(context).pop(), - ), + buildButton(context), SizedBox( height: 10, ), @@ -86,4 +80,20 @@ class AppBar extends StatelessWidget implements PreferredSizeWidget { ), ); } + + Widget buildButton(BuildContext context) { + return IconButton( + icon: hasDrawer + ? Icon( + FontAwesomeIcons.bars, + ) + : Icon( + FontAwesomeIcons.arrowLeft, + color: Color.fromRGBO(112, 112, 112, 1), + ), + onPressed: hasDrawer + ? () => Scaffold.of(context).openDrawer() + : () => Navigator.of(context).pop(), + ); + } } diff --git a/lib/src/widgets/avatar.dart b/lib/src/widgets/avatar.dart index dc4d8c9..0aa51dc 100644 --- a/lib/src/widgets/avatar.dart +++ b/lib/src/widgets/avatar.dart @@ -20,7 +20,7 @@ class Avatar extends StatelessWidget { width: size, decoration: BoxDecoration( color: Colors.white, - borderRadius: BorderRadius.circular(30), + borderRadius: BorderRadius.circular(size / 2), ), child: Center( child: Icon( diff --git a/lib/src/widgets/carousel.dart b/lib/src/widgets/carousel.dart index 256c093..2009ea6 100644 --- a/lib/src/widgets/carousel.dart +++ b/lib/src/widgets/carousel.dart @@ -177,4 +177,9 @@ class _CarouselState extends State { ), ); } + + void dispose() { + _subscription.cancel(); + super.dispose(); + } } diff --git a/lib/src/widgets/event_list_tile.dart b/lib/src/widgets/event_list_tile.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/src/widgets/home_app_bar.dart b/lib/src/widgets/home_app_bar.dart index 6e8775d..dcc96e8 100644 --- a/lib/src/widgets/home_app_bar.dart +++ b/lib/src/widgets/home_app_bar.dart @@ -60,7 +60,7 @@ class HomeAppBar extends StatelessWidget implements PreferredSizeWidget { } Widget buildTopSection(BuildContext context) { - final scaffolContext = Scaffold.of(context); + final scaffoldState = Scaffold.of(context); return Row( children: [ @@ -68,7 +68,7 @@ class HomeAppBar extends StatelessWidget implements PreferredSizeWidget { width: 20, ), IconButton( - onPressed: () => scaffolContext.openDrawer(), + onPressed: () => scaffoldState.openDrawer(), icon: Icon( FontAwesomeIcons.bars, size: 24, diff --git a/lib/src/widgets/populated_drawer.dart b/lib/src/widgets/populated_drawer.dart index 115a853..4b344aa 100644 --- a/lib/src/widgets/populated_drawer.dart +++ b/lib/src/widgets/populated_drawer.dart @@ -108,6 +108,7 @@ class PopulatedDrawer extends StatelessWidget { return result; } return GestureDetector( + behavior: HitTestBehavior.opaque, onTap: action, child: result, );