From cc6dc878955f3c75c4d78fe6dc1d6c20c4fa6cd4 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 3 Aug 2021 07:48:21 +0300 Subject: [PATCH] Full width vendor editor --- lib/data/models/vendor_model.dart | 20 ++++++ lib/ui/vendor/edit/vendor_edit_desktop.dart | 57 ++++++++++++++++ lib/ui/vendor/edit/vendor_edit_footer.dart | 73 +++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 lib/ui/vendor/edit/vendor_edit_desktop.dart create mode 100644 lib/ui/vendor/edit/vendor_edit_footer.dart diff --git a/lib/data/models/vendor_model.dart b/lib/data/models/vendor_model.dart index ba51405ae..5a99806d7 100644 --- a/lib/data/models/vendor_model.dart +++ b/lib/data/models/vendor_model.dart @@ -393,6 +393,18 @@ abstract class VendorEntity extends Object @override FormatNumberType get listDisplayAmountType => FormatNumberType.money; + String get calculateDisplayName { + if (name.isNotEmpty) { + return name; + } else { + return primaryContact.fullNameOrEmail; + } + } + + VendorContactEntity get primaryContact => + contacts.firstWhere((contact) => contact.isPrimary, + orElse: () => VendorContactEntity()); + bool get hasCurrency => currencyId != null && currencyId.isNotEmpty; bool get hasUser => assignedUserId != null && assignedUserId.isNotEmpty; @@ -456,6 +468,14 @@ abstract class VendorContactEntity extends Object return (firstName + ' ' + lastName).trim(); } + String get fullNameOrEmail { + if (fullName.isNotEmpty) { + return fullName; + } else { + return email; + } + } + @override bool matchesFilter(String filter) { if (filter == null || filter.isEmpty) { diff --git a/lib/ui/vendor/edit/vendor_edit_desktop.dart b/lib/ui/vendor/edit/vendor_edit_desktop.dart new file mode 100644 index 000000000..c4e60160e --- /dev/null +++ b/lib/ui/vendor/edit/vendor_edit_desktop.dart @@ -0,0 +1,57 @@ +import 'package:flutter/material.dart'; +import 'package:invoiceninja_flutter/ui/app/scrollable_listview.dart'; +import 'package:invoiceninja_flutter/ui/vendor/edit/vendor_edit_address.dart'; +import 'package:invoiceninja_flutter/ui/vendor/edit/vendor_edit_contacts_vm.dart'; +import 'package:invoiceninja_flutter/ui/vendor/edit/vendor_edit_details.dart'; +import 'package:invoiceninja_flutter/ui/vendor/edit/vendor_edit_notes.dart'; +import 'package:invoiceninja_flutter/ui/vendor/edit/vendor_edit_vm.dart'; + +class VendorEditDesktop extends StatelessWidget { + const VendorEditDesktop({ + Key key, + @required this.viewModel, + }) : super(key: key); + + final VendorEditVM viewModel; + + @override + Widget build(BuildContext context) { + return ScrollableListView( + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Column( + children: [ + VendorEditDetails( + viewModel: viewModel, + ), + VendorEditNotes( + viewModel: viewModel, + ), + ], + ), + ), + Expanded( + child: Column( + children: [ + VendorEditContactsScreen(), + ], + ), + ), + Expanded( + child: Column( + children: [ + VendorEditAddress( + viewModel: viewModel, + ), + ], + ), + ), + ], + ), + ], + ); + } +} diff --git a/lib/ui/vendor/edit/vendor_edit_footer.dart b/lib/ui/vendor/edit/vendor_edit_footer.dart new file mode 100644 index 000000000..707af8844 --- /dev/null +++ b/lib/ui/vendor/edit/vendor_edit_footer.dart @@ -0,0 +1,73 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_redux/flutter_redux.dart'; +import 'package:invoiceninja_flutter/constants.dart'; +import 'package:invoiceninja_flutter/data/models/vendor_model.dart'; +import 'package:invoiceninja_flutter/data/models/entities.dart'; +import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; +import 'package:invoiceninja_flutter/redux/app/app_state.dart'; +import 'package:invoiceninja_flutter/ui/app/app_border.dart'; +import 'package:invoiceninja_flutter/utils/localization.dart'; +import 'package:invoiceninja_flutter/utils/platforms.dart'; + +class VendorEditFooter extends StatelessWidget { + const VendorEditFooter({@required this.vendor}); + + final VendorEntity vendor; + + @override + Widget build(BuildContext context) { + final localization = AppLocalization.of(context); + final store = StoreProvider.of(context); + final state = store.state; + final useSidebarEditor = + state.prefState.useSidebarEditor[EntityType.vendor] ?? false; + + return BottomAppBar( + elevation: 0, + color: Theme.of(context).cardColor, + shape: CircularNotchedRectangle(), + child: SizedBox( + height: kTopBottomBarHeight, + child: AppBorder( + isTop: true, + child: Row( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + if (isDesktop(context)) + Tooltip( + message: useSidebarEditor + ? localization.fullscreenEditor + : localization.sidebarEditor, + child: InkWell( + onTap: () => + store.dispatch(ToggleEditorLayout(EntityType.vendor)), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 8), + child: Icon(useSidebarEditor + ? Icons.chevron_left + : Icons.chevron_right), + ), + ), + ), + AppBorder( + isLeft: isDesktop(context), + child: Padding( + padding: const EdgeInsets.only(left: 16, top: 8), + child: Text( + vendor.calculateDisplayName, + style: TextStyle( + color: state.prefState.enableDarkMode + ? Colors.white + : Colors.black, + fontSize: 20.0, + ), + ), + ), + ), + ], + ), + ), + ), + ); + } +}