Browse Source

neon_files, neon_news, neon_notes, neon_notifications: make buildPage bloc independent

pull/363/head
Nikolas Rimikis 2 years ago
parent
commit
00c3235fa1
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 8
      packages/neon/neon_files/lib/neon_files.dart
  2. 20
      packages/neon/neon_files/lib/pages/main.dart
  3. 8
      packages/neon/neon_news/lib/neon_news.dart
  4. 21
      packages/neon/neon_news/lib/pages/main.dart
  5. 8
      packages/neon/neon_notes/lib/neon_notes.dart
  6. 16
      packages/neon/neon_notes/lib/pages/main.dart
  7. 8
      packages/neon/neon_notifications/lib/neon_notifications.dart
  8. 17
      packages/neon/neon_notifications/lib/pages/main.dart

8
packages/neon/neon_files/lib/neon_files.dart

@ -62,13 +62,7 @@ class FilesApp extends AppImplementation<FilesBloc, FilesAppSpecificOptions> {
);
@override
Widget buildPage(final BuildContext context, final AppsBloc appsBloc) {
final bloc = Provider.of<FilesBloc>(context, listen: false);
return FilesMainPage(
bloc: bloc,
);
}
Widget buildPage(final BuildContext context, final AppsBloc appsBloc) => const FilesMainPage();
@override
BehaviorSubject<int>? getUnreadCounter(final AppsBloc appsBloc) => null;

20
packages/neon/neon_files/lib/pages/main.dart

@ -2,22 +2,22 @@ part of '../neon_files.dart';
class FilesMainPage extends StatefulWidget {
const FilesMainPage({
required this.bloc,
super.key,
});
final FilesBloc bloc;
@override
State<FilesMainPage> createState() => _FilesMainPageState();
}
class _FilesMainPageState extends State<FilesMainPage> {
late FilesBloc bloc;
@override
void initState() {
super.initState();
bloc = Provider.of<FilesBloc>(context, listen: false);
widget.bloc.errors.listen((final error) {
bloc.errors.listen((final error) {
NeonException.showSnackbar(context, error);
});
}
@ -25,10 +25,10 @@ class _FilesMainPageState extends State<FilesMainPage> {
@override
Widget build(final BuildContext context) => Scaffold(
body: FilesBrowserView(
bloc: widget.bloc.browser,
filesBloc: widget.bloc,
bloc: bloc.browser,
filesBloc: bloc,
onPickFile: (final details) async {
final sizeWarning = widget.bloc.options.downloadSizeWarning.value;
final sizeWarning = bloc.options.downloadSizeWarning.value;
if (sizeWarning != null && details.size > sizeWarning) {
// ignore: use_build_context_synchronously
if (!(await showConfirmationDialog(
@ -42,7 +42,7 @@ class _FilesMainPageState extends State<FilesMainPage> {
return;
}
}
widget.bloc.openFile(details.path, details.etag!, details.mimeType);
bloc.openFile(details.path, details.etag!, details.mimeType);
},
),
floatingActionButton: FloatingActionButton(
@ -50,8 +50,8 @@ class _FilesMainPageState extends State<FilesMainPage> {
await showDialog(
context: context,
builder: (final context) => FilesChooseCreateDialog(
bloc: widget.bloc,
basePath: widget.bloc.browser.path.value,
bloc: bloc,
basePath: bloc.browser.path.value,
),
);
},

8
packages/neon/neon_news/lib/neon_news.dart

@ -68,13 +68,7 @@ class NewsApp extends AppImplementation<NewsBloc, NewsAppSpecificOptions> {
);
@override
Widget buildPage(final BuildContext context, final AppsBloc appsBloc) {
final bloc = Provider.of<NewsBloc>(context, listen: false);
return NewsMainPage(
bloc: bloc,
);
}
Widget buildPage(final BuildContext context, final AppsBloc appsBloc) => const NewsMainPage();
@override
BehaviorSubject<int> getUnreadCounter(final AppsBloc appsBloc) => appsBloc.getAppBloc<NewsBloc>(this).unreadCounter;

21
packages/neon/neon_news/lib/pages/main.dart

@ -2,24 +2,23 @@ part of '../neon_news.dart';
class NewsMainPage extends StatefulWidget {
const NewsMainPage({
required this.bloc,
super.key,
});
final NewsBloc bloc;
@override
State<NewsMainPage> createState() => _NewsMainPageState();
}
class _NewsMainPageState extends State<NewsMainPage> {
late int _index = widget.bloc.options.defaultCategoryOption.value.index;
late NewsBloc bloc;
late int _index = bloc.options.defaultCategoryOption.value.index;
@override
void initState() {
super.initState();
final bloc = Provider.of<NewsBloc>(context, listen: false);
widget.bloc.errors.listen((final error) {
bloc.errors.listen((final error) {
NeonException.showSnackbar(context, error);
});
}
@ -28,21 +27,21 @@ class _NewsMainPageState extends State<NewsMainPage> {
Widget build(final BuildContext context) {
final views = [
NewsArticlesView(
bloc: widget.bloc.mainArticlesBloc,
newsBloc: widget.bloc,
bloc: bloc.mainArticlesBloc,
newsBloc: bloc,
),
NewsFoldersView(
bloc: widget.bloc,
bloc: bloc,
),
NewsFeedsView(
bloc: widget.bloc,
bloc: bloc,
),
];
final floatingActionButtons = [
null,
NewsFolderFloatingActionButton(bloc: widget.bloc),
NewsFeedFloatingActionButton(bloc: widget.bloc),
NewsFolderFloatingActionButton(bloc: bloc),
NewsFeedFloatingActionButton(bloc: bloc),
];
return Scaffold(

8
packages/neon/neon_notes/lib/neon_notes.dart

@ -58,13 +58,7 @@ class NotesApp extends AppImplementation<NotesBloc, NotesAppSpecificOptions> {
);
@override
Widget buildPage(final BuildContext context, final AppsBloc appsBloc) {
final bloc = Provider.of<NotesBloc>(context, listen: false);
return NotesMainPage(
bloc: bloc,
);
}
Widget buildPage(final BuildContext context, final AppsBloc appsBloc) => const NotesMainPage();
@override
BehaviorSubject<int>? getUnreadCounter(final AppsBloc appsBloc) => null;

16
packages/neon/neon_notes/lib/pages/main.dart

@ -2,24 +2,24 @@ part of '../neon_notes.dart';
class NotesMainPage extends StatefulWidget {
const NotesMainPage({
required this.bloc,
super.key,
});
final NotesBloc bloc;
@override
State<NotesMainPage> createState() => _NotesMainPageState();
}
class _NotesMainPageState extends State<NotesMainPage> {
late int _index = widget.bloc.options.defaultCategoryOption.value.index;
late NotesBloc bloc;
late int _index = bloc.options.defaultCategoryOption.value.index;
@override
void initState() {
super.initState();
widget.bloc.errors.listen((final error) {
bloc = Provider.of<NotesBloc>(context, listen: false);
bloc.errors.listen((final error) {
handleNotesException(context, error);
});
}
@ -28,15 +28,15 @@ class _NotesMainPageState extends State<NotesMainPage> {
Widget build(final BuildContext context) {
final views = [
NotesView(
bloc: widget.bloc,
bloc: bloc,
),
NotesCategoriesView(
bloc: widget.bloc,
bloc: bloc,
),
];
final floatingActionButtons = [
NotesFloatingActionButton(bloc: widget.bloc),
NotesFloatingActionButton(bloc: bloc),
null,
];

8
packages/neon/neon_notifications/lib/neon_notifications.dart

@ -37,13 +37,7 @@ class NotificationsApp extends NotificationsAppInterface {
);
@override
Widget buildPage(final BuildContext context, final AppsBloc appsBloc) {
final bloc = Provider.of<NotificationsBloc>(context, listen: false);
return NotificationsMainPage(
bloc: bloc,
);
}
Widget buildPage(final BuildContext context, final AppsBloc appsBloc) => const NotificationsMainPage();
@override
BehaviorSubject<int> getUnreadCounter(final AppsBloc appsBloc) =>

17
packages/neon/neon_notifications/lib/pages/main.dart

@ -2,34 +2,35 @@ part of '../neon_notifications.dart';
class NotificationsMainPage extends StatefulWidget {
const NotificationsMainPage({
required this.bloc,
super.key,
});
final NotificationsBloc bloc;
@override
State<NotificationsMainPage> createState() => _NotificationsMainPageState();
}
class _NotificationsMainPageState extends State<NotificationsMainPage> {
late NotificationsBloc bloc;
@override
void initState() {
super.initState();
widget.bloc.errors.listen((final error) {
bloc = Provider.of<NotificationsBloc>(context, listen: false);
bloc.errors.listen((final error) {
NeonException.showSnackbar(context, error);
});
}
@override
Widget build(final BuildContext context) => ResultBuilder<List<NextcloudNotificationsNotification>>(
stream: widget.bloc.notifications,
stream: bloc.notifications,
builder: (final context, final notifications) => Scaffold(
resizeToAvoidBottomInset: false,
floatingActionButton: FloatingActionButton(
onPressed: () async {
widget.bloc.deleteAllNotifications();
bloc.deleteAllNotifications();
},
tooltip: AppLocalizations.of(context).notificationsDismissAll,
child: const Icon(MdiIcons.checkAll),
@ -40,7 +41,7 @@ class _NotificationsMainPageState extends State<NotificationsMainPage> {
items: notifications.data,
isLoading: notifications.loading,
error: notifications.error,
onRefresh: widget.bloc.refresh,
onRefresh: bloc.refresh,
builder: _buildNotification,
),
),
@ -113,7 +114,7 @@ class _NotificationsMainPageState extends State<NotificationsMainPage> {
}
},
onLongPress: () {
widget.bloc.deleteNotification(notification.notificationId);
bloc.deleteNotification(notification.notificationId);
},
);
}

Loading…
Cancel
Save