Added missing comments for the snackbar code, extracted snackbar related code from the screens constructors to a method
This commit is contained in:
parent
10aabed07e
commit
6abfc0beac
4 changed files with 38 additions and 23 deletions
|
|
@ -22,11 +22,17 @@ mixin UploadStatusMixin {
|
|||
/// An observable of the status of files being uploaded.
|
||||
Observable<UploadStatus> get uploadStatus => uploadStatusSer.status;
|
||||
|
||||
/// Disposes instance variables that are part of the mixin.
|
||||
Future<void> disposeUploadStatusMixin() async {
|
||||
await snackBarStatusSubject.drain();
|
||||
snackBarStatusSubject.close();
|
||||
}
|
||||
|
||||
/// Initializes the [snacBarStatusSubject].
|
||||
///
|
||||
/// The raw status coming from the [UploadStatusService] is transformed and
|
||||
/// turned into a stream that emits [true] when the snackbar should be visible
|
||||
/// and false otherwise. This is piped to [the snackBarStatusSubject].
|
||||
void initializeSnackBarStatus() {
|
||||
uploadStatusService.status
|
||||
.transform(StreamTransformer<UploadStatus, bool>.fromHandlers(
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ class _EventScreenState extends State<EventScreen>
|
|||
/// Needed for showing snackbars.
|
||||
BuildContext _scaffoldContext;
|
||||
|
||||
/// A stream subscription to the snackbar status.
|
||||
StreamSubscription _snackBarStatusSubscription;
|
||||
|
||||
initState() {
|
||||
|
|
@ -49,17 +50,7 @@ class _EventScreenState extends State<EventScreen>
|
|||
bloc.fetchTasks();
|
||||
bloc.fetchImagesPaths();
|
||||
_tabController = TabController(vsync: this, length: 2);
|
||||
_snackBarStatusSubscription = bloc.snackBarStatus.listen((bool visible) {
|
||||
if (visible) {
|
||||
showUploadStatusSnackBar(
|
||||
_scaffoldContext,
|
||||
bloc.uploadStatus,
|
||||
bloc.updateSnackBarStatus,
|
||||
);
|
||||
} else {
|
||||
Scaffold.of(_scaffoldContext).hideCurrentSnackBar();
|
||||
}
|
||||
});
|
||||
initializeSnackBarListener();
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
|
|
@ -204,6 +195,20 @@ class _EventScreenState extends State<EventScreen>
|
|||
);
|
||||
}
|
||||
|
||||
void initializeSnackBarListener() {
|
||||
_snackBarStatusSubscription = bloc.snackBarStatus.listen((bool visible) {
|
||||
if (visible) {
|
||||
showUploadStatusSnackBar(
|
||||
_scaffoldContext,
|
||||
bloc.uploadStatus,
|
||||
bloc.updateSnackBarStatus,
|
||||
);
|
||||
} else {
|
||||
Scaffold.of(_scaffoldContext).hideCurrentSnackBar();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_snackBarStatusSubscription.cancel();
|
||||
bloc.dispose();
|
||||
|
|
|
|||
|
|
@ -28,23 +28,14 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||
/// Needed for showing snackbars.
|
||||
BuildContext _scaffoldContext;
|
||||
|
||||
/// A stream subscription to the snackbar status.
|
||||
StreamSubscription _snackBarStatusSubscription;
|
||||
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
bloc.fetchTasks();
|
||||
_snackBarStatusSubscription = bloc.snackBarStatus.listen((bool visible) {
|
||||
if (visible) {
|
||||
showUploadStatusSnackBar(
|
||||
_scaffoldContext,
|
||||
bloc.uploadStatus,
|
||||
bloc.updateSnackBarStatus,
|
||||
);
|
||||
} else {
|
||||
Scaffold.of(_scaffoldContext).hideCurrentSnackBar();
|
||||
}
|
||||
});
|
||||
initializeSnackBarListener();
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
|
|
@ -138,6 +129,20 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||
);
|
||||
}
|
||||
|
||||
void initializeSnackBarListener() {
|
||||
_snackBarStatusSubscription = bloc.snackBarStatus.listen((bool visible) {
|
||||
if (visible) {
|
||||
showUploadStatusSnackBar(
|
||||
_scaffoldContext,
|
||||
bloc.uploadStatus,
|
||||
bloc.updateSnackBarStatus,
|
||||
);
|
||||
} else {
|
||||
Scaffold.of(_scaffoldContext).hideCurrentSnackBar();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_snackBarStatusSubscription.cancel();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue