Several fixes and formatting. Fixed a bug where a stream subscription wasn't being closed by the Carousel widget

This commit is contained in:
Mariano Uvalle 2019-04-23 02:01:35 -05:00
parent bc74590303
commit d8cbed2cd1
8 changed files with 74 additions and 12 deletions

View file

@ -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<List<EventModel>>();
/// An observable of the current logged in user.
Observable<FirebaseUser> get userStream => _auth.userStream;
/// Initiates the fetching process of events linked to the current user.
Future<void> fetchEvents() async {
final userModel = await _auth.getCurrentUserModel();
_firestore.getUserEvents(userModel.id).pipe(_events);
}
dispose() async {
await _events.drain();
_events.close();
}
}

View file

@ -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,
),
);
}
}

View file

@ -37,13 +37,7 @@ class AppBar extends StatelessWidget implements PreferredSizeWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
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(),
);
}
}

View file

@ -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(

View file

@ -177,4 +177,9 @@ class _CarouselState extends State<Carousel> {
),
);
}
void dispose() {
_subscription.cancel();
super.dispose();
}
}

View file

View file

@ -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: <Widget>[
@ -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,

View file

@ -108,6 +108,7 @@ class PopulatedDrawer extends StatelessWidget {
return result;
}
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: action,
child: result,
);