Further migrations to route based navigation, improved saved view logic

This commit is contained in:
Anton Stubenbord
2023-09-12 01:03:01 +02:00
parent 8e5eb5a6c6
commit 2e8144700f
28 changed files with 878 additions and 550 deletions

View File

@@ -5,7 +5,6 @@ import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/features/app_drawer/view/app_drawer.dart';
import 'package:paperless_mobile/features/inbox/cubit/inbox_cubit.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
import 'package:paperless_mobile/helpers/message_helpers.dart';
const _landingPage = 0;
const _documentsIndex = 1;
@@ -30,134 +29,123 @@ class ScaffoldWithNavigationBar extends StatefulWidget {
class ScaffoldWithNavigationBarState extends State<ScaffoldWithNavigationBar> {
@override
Widget build(BuildContext context) {
final disabledColor = Theme.of(context).disabledColor;
final primaryColor = Theme.of(context).colorScheme.primary;
return Scaffold(
drawer: const AppDrawer(),
bottomNavigationBar: NavigationBar(
selectedIndex: widget.navigationShell.currentIndex,
onDestinationSelected: (index) {
switch (index) {
case _landingPage:
widget.navigationShell.goBranch(index);
break;
case _documentsIndex:
if (widget.authenticatedUser.canViewDocuments) {
widget.navigationShell.goBranch(index);
} else {
showSnackBar(context, S.of(context)!.missingPermissions);
}
break;
case _scannerIndex:
if (widget.authenticatedUser.canCreateDocuments) {
widget.navigationShell.goBranch(index);
} else {
showSnackBar(context, S.of(context)!.missingPermissions);
}
break;
case _labelsIndex:
if (widget.authenticatedUser.canViewAnyLabel) {
widget.navigationShell.goBranch(index);
} else {
showSnackBar(context, S.of(context)!.missingPermissions);
}
break;
case _inboxIndex:
if (widget.authenticatedUser.canViewDocuments &&
widget.authenticatedUser.canViewTags) {
widget.navigationShell.goBranch(index);
} else {
showSnackBar(context, S.of(context)!.missingPermissions);
}
break;
default:
break;
}
widget.navigationShell.goBranch(
index,
initialLocation: index == widget.navigationShell.currentIndex,
);
},
destinations: [
NavigationDestination(
icon: Icon(Icons.home_outlined),
icon: const Icon(Icons.home_outlined),
selectedIcon: Icon(
Icons.home,
color: primaryColor,
),
label: "Home", //TODO: INTL
),
NavigationDestination(
icon: Icon(
Icons.description_outlined,
color: !widget.authenticatedUser.canViewDocuments
? disabledColor
: null,
_toggleDestination(
NavigationDestination(
icon: const Icon(Icons.description_outlined),
selectedIcon: Icon(
Icons.description,
color: primaryColor,
),
label: S.of(context)!.documents,
),
selectedIcon: Icon(
Icons.description,
color: primaryColor,
),
label: S.of(context)!.documents,
disableWhen: !widget.authenticatedUser.canViewDocuments,
),
NavigationDestination(
icon: Icon(
Icons.document_scanner_outlined,
color: !widget.authenticatedUser.canCreateDocuments
? disabledColor
: null,
_toggleDestination(
NavigationDestination(
icon: const Icon(Icons.document_scanner_outlined),
selectedIcon: Icon(
Icons.document_scanner,
color: primaryColor,
),
label: S.of(context)!.scanner,
),
selectedIcon: Icon(
Icons.document_scanner,
color: primaryColor,
),
label: S.of(context)!.scanner,
disableWhen: !widget.authenticatedUser.canCreateDocuments,
),
NavigationDestination(
icon: Icon(
Icons.sell_outlined,
color: !widget.authenticatedUser.canViewAnyLabel
? disabledColor
: null,
_toggleDestination(
NavigationDestination(
icon: const Icon(Icons.sell_outlined),
selectedIcon: Icon(
Icons.sell,
color: primaryColor,
),
label: S.of(context)!.labels,
),
selectedIcon: Icon(
Icons.sell,
color: primaryColor,
),
label: S.of(context)!.labels,
disableWhen: !widget.authenticatedUser.canViewAnyLabel,
),
NavigationDestination(
icon: Builder(builder: (context) {
if (!(widget.authenticatedUser.canViewDocuments &&
widget.authenticatedUser.canViewTags)) {
return Icon(
Icons.inbox_outlined,
color: disabledColor,
);
}
return BlocBuilder<InboxCubit, InboxState>(
builder: (context, state) {
return Badge.count(
isLabelVisible: state.itemsInInboxCount > 0,
count: state.itemsInInboxCount,
child: const Icon(Icons.inbox_outlined),
_toggleDestination(
NavigationDestination(
icon: Builder(
builder: (context) {
return BlocBuilder<InboxCubit, InboxState>(
builder: (context, state) {
return Badge.count(
isLabelVisible: state.itemsInInboxCount > 0,
count: state.itemsInInboxCount,
child: const Icon(Icons.inbox_outlined),
);
},
);
},
);
}),
selectedIcon: BlocBuilder<InboxCubit, InboxState>(
builder: (context, state) {
return Badge.count(
isLabelVisible: state.itemsInInboxCount > 0,
count: state.itemsInInboxCount,
child: Icon(
Icons.inbox,
color: primaryColor,
),
);
},
),
selectedIcon: BlocBuilder<InboxCubit, InboxState>(
builder: (context, state) {
return Badge.count(
isLabelVisible: state.itemsInInboxCount > 0 &&
widget.authenticatedUser.canViewInbox,
count: state.itemsInInboxCount,
child: Icon(
Icons.inbox,
color: primaryColor,
),
);
},
),
label: S.of(context)!.inbox,
),
label: S.of(context)!.inbox,
disableWhen: !widget.authenticatedUser.canViewInbox,
),
],
),
body: widget.navigationShell,
);
}
Widget _toggleDestination(
Widget destination, {
required bool disableWhen,
}) {
final disabledColor = Theme.of(context).disabledColor;
final disabledTheme = Theme.of(context).navigationBarTheme.copyWith(
labelTextStyle: MaterialStatePropertyAll(
Theme.of(context)
.textTheme
.labelSmall
?.copyWith(color: disabledColor),
),
iconTheme: MaterialStatePropertyAll(
Theme.of(context).iconTheme.copyWith(color: disabledColor),
),
);
if (disableWhen) {
return AbsorbPointer(
child: Theme(
data: Theme.of(context).copyWith(navigationBarTheme: disabledTheme),
child: destination,
),
);
}
return destination;
}
}