Several fixes and formatting. Fixed a bug where a stream subscription wasn't being closed by the Carousel widget
This commit is contained in:
parent
bc74590303
commit
d8cbed2cd1
8 changed files with 74 additions and 12 deletions
35
lib/src/blocs/events_bloc.dart
Normal file
35
lib/src/blocs/events_bloc.dart
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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 {
|
class EventsScreen extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold();
|
return Scaffold(
|
||||||
|
drawer: PopulatedDrawer(
|
||||||
|
selectedScreen: Screen.events,
|
||||||
|
),
|
||||||
|
appBar: AppBar(
|
||||||
|
title: 'My Events',
|
||||||
|
hasDrawer: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,13 +37,7 @@ class AppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
IconButton(
|
buildButton(context),
|
||||||
icon: Icon(
|
|
||||||
FontAwesomeIcons.arrowLeft,
|
|
||||||
color: Color.fromRGBO(112, 112, 112, 1),
|
|
||||||
),
|
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
|
||||||
),
|
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 10,
|
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(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class Avatar extends StatelessWidget {
|
||||||
width: size,
|
width: size,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
borderRadius: BorderRadius.circular(30),
|
borderRadius: BorderRadius.circular(size / 2),
|
||||||
),
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Icon(
|
child: Icon(
|
||||||
|
|
|
||||||
|
|
@ -177,4 +177,9 @@ class _CarouselState extends State<Carousel> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dispose() {
|
||||||
|
_subscription.cancel();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
0
lib/src/widgets/event_list_tile.dart
Normal file
0
lib/src/widgets/event_list_tile.dart
Normal file
|
|
@ -60,7 +60,7 @@ class HomeAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildTopSection(BuildContext context) {
|
Widget buildTopSection(BuildContext context) {
|
||||||
final scaffolContext = Scaffold.of(context);
|
final scaffoldState = Scaffold.of(context);
|
||||||
|
|
||||||
return Row(
|
return Row(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
|
|
@ -68,7 +68,7 @@ class HomeAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||||
width: 20,
|
width: 20,
|
||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
onPressed: () => scaffolContext.openDrawer(),
|
onPressed: () => scaffoldState.openDrawer(),
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
FontAwesomeIcons.bars,
|
FontAwesomeIcons.bars,
|
||||||
size: 24,
|
size: 24,
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,7 @@ class PopulatedDrawer extends StatelessWidget {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
onTap: action,
|
onTap: action,
|
||||||
child: result,
|
child: result,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue