Null safety

This commit is contained in:
Hillel Coren 2023-10-01 14:19:01 +03:00
parent f885b64013
commit 5377657beb
29 changed files with 87 additions and 86 deletions

View File

@ -94,8 +94,7 @@ class TransactionRepository {
.map((transactionId) => {
'id': transactionId,
if (vendorId.isNotEmpty) 'vendor_id': vendorId,
if (categoryId.isNotEmpty)
'ninja_category_id': categoryId,
if (categoryId.isNotEmpty) 'ninja_category_id': categoryId,
})
.toList()
},

View File

@ -368,8 +368,7 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
data: data.copyWith(
textScaleFactor: state.prefState.textScaleFactor,
alwaysUse24HourFormat:
state.company?.settings.enableMilitaryTime ??
false,
state.company?.settings.enableMilitaryTime ?? false,
),
child: child!,
);

View File

@ -108,8 +108,7 @@ abstract class DashboardUISettings
String get groupBy;
bool matchesCurrency(String? match) {
if (currencyId.isEmpty ||
currencyId == kCurrencyAll) {
if (currencyId.isEmpty || currencyId == kCurrencyAll) {
return true;
}

View File

@ -491,24 +491,24 @@ void handleDocumentAction(
.dispatch(LoadCredit(creditId: document.parentId)));
break;
case EntityType.expense:
completer.future.then<Null>((_) => store.dispatch(
LoadExpense(expenseId: document.parentId)));
completer.future.then<Null>((_) => store
.dispatch(LoadExpense(expenseId: document.parentId)));
break;
case EntityType.group:
completer.future.then<Null>((_) => store
.dispatch(LoadGroup(groupId: document.parentId)));
break;
case EntityType.invoice:
completer.future.then<Null>((_) => store.dispatch(
LoadInvoice(invoiceId: document.parentId)));
completer.future.then<Null>((_) => store
.dispatch(LoadInvoice(invoiceId: document.parentId)));
break;
case EntityType.product:
completer.future.then<Null>((_) => store.dispatch(
LoadProduct(productId: document.parentId)));
completer.future.then<Null>((_) => store
.dispatch(LoadProduct(productId: document.parentId)));
break;
case EntityType.project:
completer.future.then<Null>((_) => store.dispatch(
LoadProject(projectId: document.parentId)));
completer.future.then<Null>((_) => store
.dispatch(LoadProject(projectId: document.parentId)));
break;
case EntityType.purchaseOrder:
completer.future.then<Null>((_) => store.dispatch(

View File

@ -728,8 +728,7 @@ void handlePurchaseOrderAction(BuildContext? context,
onPressed: () {
Navigator.of(context).pop();
editEntity(
entity:
state.vendorState.get(purchaseOrder!.vendorId));
entity: state.vendorState.get(purchaseOrder!.vendorId));
},
child: Text(localization.editVendor.toUpperCase()))
]);

View File

@ -378,7 +378,8 @@ class _AppBottomBarState extends State<AppBottomBar> {
final settings = state.userCompany.settings.rebuild((b) => b
..tableColumns['${widget.entityType}'] =
BuiltList<String>(selected));
final userCompany = state.userCompany.rebuild((b) => b..settings.replace(settings));
final userCompany =
state.userCompany.rebuild((b) => b..settings.replace(settings));
final user =
state.user.rebuild((b) => b..userCompany.replace(userCompany));
final completer = snackBarCompleter<Null>(

View File

@ -98,7 +98,7 @@ class DataRow {
this.selected = false,
this.onSelectChanged,
required this.cells,
}) : key = ValueKey<int?>(index);
}) : key = ValueKey<int?>(index);
/// A [Key] that uniquely identifies this row. This is used to
/// ensure that if a row is added or removed, any stateful widgets

View File

@ -248,8 +248,7 @@ class LoginVM {
provider: UserEntity.OAUTH_PROVIDER_MICROSOFT,
oneTimePassword: oneTimePassword,
));
completer.future
.then<Null>((_) => _handleLogin(context: context));
completer.future.then<Null>((_) => _handleLogin(context: context));
}, (dynamic error) {
completer.completeError(error);
});
@ -359,8 +358,8 @@ class LoginVM {
email: email.trim(),
password: password.trim(),
));
completer.future.then<Null>(
(_) => _handleLogin(context: context, isSignUp: true));
completer.future
.then<Null>((_) => _handleLogin(context: context, isSignUp: true));
},
onRecoverPressed: (
BuildContext context,

View File

@ -46,8 +46,8 @@ class _ClientEditContactsState extends State<ClientEditContacts> {
key: Key(contact!.entityKey),
contact: contact,
isDialog: client.contacts.length > 1,
index: client.contacts.indexOf(
client.contacts.firstWhere((c) => c.id == contact.id)),
index: client.contacts
.indexOf(client.contacts.firstWhere((c) => c.id == contact.id)),
);
});
}

View File

@ -137,8 +137,7 @@ class CreditPresenter extends EntityPresenter {
case CreditFields.clientPostalCode:
return Text(client.postalCode);
case CreditFields.clientCountry:
return Text(
state.staticState.countryMap[client.countryId]?.name ?? '');
return Text(state.staticState.countryMap[client.countryId]?.name ?? '');
case CreditFields.contactName:
case CreditFields.contactEmail:
final contact = creditContactSelector(

View File

@ -607,7 +607,8 @@ class DashboardPanels extends StatelessWidget {
child: StaggeredGrid.count(
crossAxisCount: isMobile(context)
? userCompanySettings.dashboardFieldsPerRowMobile
: userCompanySettings.dashboardFieldsPerRowDesktop,
: userCompanySettings
.dashboardFieldsPerRowDesktop,
crossAxisSpacing: 8,
mainAxisSpacing: 12,
children: state.userCompany.settings.dashboardFields
@ -1121,7 +1122,8 @@ class __DashboardSettingsState extends State<_DashboardSettings> {
onPressed: () {
final completer = snackBarCompleter<Null>(
context, AppLocalization.of(context)!.savedSettings);
final user = state.user.rebuild((b) => b..userCompany.replace(state.userCompany));
final user = state.user
.rebuild((b) => b..userCompany.replace(state.userCompany));
store.dispatch(
SaveUserSettingsRequest(
completer: completer,

View File

@ -315,10 +315,12 @@ class InvoiceEditDesktopState extends State<InvoiceEditDesktop>
InkWell(
onLongPress: () => editEntity(
entity: invoice.isPurchaseOrder
? vendor: client),
? vendor
: client),
onTap: () => viewEntity(
entity: invoice.isPurchaseOrder
? vendor: client),
? vendor
: client),
child: ConstrainedBox(
constraints: BoxConstraints(
minWidth: double.infinity, minHeight: 40),
@ -328,7 +330,8 @@ class InvoiceEditDesktopState extends State<InvoiceEditDesktop>
EntityPresenter()
.initialize(
invoice.isPurchaseOrder
? vendor: client,
? vendor
: client,
context)
.title()!,
style:

View File

@ -206,7 +206,8 @@ class InvoiceEditVM extends AbstractInvoiceEditVM {
store.dispatch(UpdateInvoice(invoice.rebuild((b) => b
..clientId = clientId ?? ''
..projectId = projectId ?? ''
..invitations.replace(BuiltList<InvitationEntity>(client.emailContacts
..invitations.replace(BuiltList<InvitationEntity>(client
.emailContacts
.map(
(contact) => InvitationEntity(clientContactId: contact!.id))
.toList())))));

View File

@ -190,8 +190,7 @@ class InvoiceListItem extends StatelessWidget {
: ListTile(
onTap: () => onTap != null
? onTap!()
: selectEntity(
entity: invoice, forceView: !showCheckbox),
: selectEntity(entity: invoice, forceView: !showCheckbox),
onLongPress: () => onTap != null
? null
: selectEntity(entity: invoice, longPress: true),

View File

@ -164,8 +164,7 @@ class InvoicePresenter extends EntityPresenter {
case InvoiceFields.clientPostalCode:
return Text(client.postalCode);
case InvoiceFields.clientCountry:
return Text(
state.staticState.countryMap[client.countryId]?.name ?? '');
return Text(state.staticState.countryMap[client.countryId]?.name ?? '');
case InvoiceFields.contactName:
case InvoiceFields.contactEmail:
final contact = invoiceContactSelector(

View File

@ -343,7 +343,7 @@ class InvoiceOverview extends StatelessWidget {
EntityListTile(
isFilter: isFilter,
entity: payment,
subtitle: amount+ '' + formatDate(payment.date, context),
subtitle: amount + '' + formatDate(payment.date, context),
),
);
});
@ -373,7 +373,7 @@ class InvoiceOverview extends StatelessWidget {
EntityListTile(
isFilter: isFilter,
entity: credit,
subtitle: amount+ '' + formatDate(credit.date, context),
subtitle: amount + '' + formatDate(credit.date, context),
),
);
});

View File

@ -104,9 +104,8 @@ class _PaymentTermEditState extends State<PaymentTermEdit> {
keyboardType: TextInputType.number,
controller: _numDaysController,
label: localization.numberOfDays,
validator: (value) => value.isEmpty
? localization.pleaseEnterAValue
: null,
validator: (value) =>
value.isEmpty ? localization.pleaseEnterAValue : null,
onSavePressed: (context) => _onSavePressed(),
),
],

View File

@ -135,8 +135,7 @@ class PurchaseOrderPresenter extends EntityPresenter {
case PurchaseOrderFields.vendorPostalCode:
return Text(vendor.postalCode);
case PurchaseOrderFields.vendorCountry:
return Text(
state.staticState.countryMap[client.countryId]?.name ?? '');
return Text(state.staticState.countryMap[client.countryId]?.name ?? '');
case PurchaseOrderFields.contactName:
case PurchaseOrderFields.contactEmail:
final contact = purchaseOrderContactSelector(

View File

@ -131,8 +131,7 @@ class QuotePresenter extends EntityPresenter {
case QuoteFields.clientPostalCode:
return Text(client.postalCode);
case QuoteFields.clientCountry:
return Text(
state.staticState.countryMap[client.countryId]?.name ?? '');
return Text(state.staticState.countryMap[client.countryId]?.name ?? '');
case QuoteFields.contactName:
case QuoteFields.contactEmail:
final contact =

View File

@ -222,8 +222,8 @@ class RecurringInvoiceListItem extends StatelessWidget {
(invoice.nextSendDate.isNotEmpty
? ''
: '') +
formatDate(invoice.nextSendDate,
context) +
formatDate(
invoice.nextSendDate, context) +
(invoice.documents.isNotEmpty
? ' 📎'
: ''))

View File

@ -646,9 +646,10 @@ class _ReportDataTableState extends State<ReportDataTable> {
final reportResult = viewModel.reportResult!;
final reportState = viewModel.reportState;
final settings = state.userCompany.settings;
final reportSettings = settings.reportSettings.containsKey(reportState.report)
? settings.reportSettings[reportState.report]!
: ReportSettingsEntity();
final reportSettings =
settings.reportSettings.containsKey(reportState.report)
? settings.reportSettings[reportState.report]!
: ReportSettingsEntity();
final sortedColumns = reportResult.sortedColumns(reportState);
return Column(
@ -714,9 +715,10 @@ class TotalsDataTable extends StatelessWidget {
@override
Widget build(BuildContext context) {
return mt.DataTable(
sortColumnIndex: reportResult!.columns.length > reportSettings!.sortTotalsIndex
? reportSettings!.sortTotalsIndex
: null,
sortColumnIndex:
reportResult!.columns.length > reportSettings!.sortTotalsIndex
? reportSettings!.sortTotalsIndex
: null,
sortAscending: reportSettings!.sortTotalsAscending ?? true,
columns: reportResult!.totalColumns(
context,
@ -1481,9 +1483,10 @@ class ReportResult {
final state = store.state;
final reportState = state.uiState.reportsUIState;
final settings = state.userCompany.settings;
final reportSettings = settings.reportSettings.containsKey(reportState.report)
? settings.reportSettings[reportState.report]!
: ReportSettingsEntity();
final reportSettings =
settings.reportSettings.containsKey(reportState.report)
? settings.reportSettings[reportState.report]!
: ReportSettingsEntity();
final Map<String, Map<String?, double>> totals = {};

View File

@ -324,8 +324,8 @@ class _ScheduleEditState extends State<ScheduleEdit> {
HelpText(localization.allClients),
for (var clientId in parameters.clients!)
ListTile(
title: Text(
state.clientState.get(clientId).displayName),
title:
Text(state.clientState.get(clientId).displayName),
trailing: IconButton(
icon: Icon(Icons.clear),
onPressed: () {

View File

@ -77,7 +77,8 @@ class _ScheduleViewState extends State<ScheduleView> {
? localization.allClients
: parameters.clients!.length == 1
? state.clientState
.get(parameters.clients!.first).displayName
.get(parameters.clients!.first)
.displayName
: '${parameters.clients!.length} ${localization.clients}',
localization.dateRange: localization.lookup(parameters.dateRange),
localization.showAgingTable: parameters.showAgingTable!

View File

@ -277,23 +277,23 @@ class _UserDetailsState extends State<UserDetails>
.toUpperCase(),
textAlign: TextAlign.center,
),
onPressed: state.user.isConnectedToGoogle ||
state.user.isConnectedToMicrosoft
? null
: () {
if (state.settingsUIState.isChanged) {
showMessageDialog(
context: context,
message: localization.errorUnsavedChanges);
return;
}
onPressed:
state.user.isConnectedToGoogle || state.user.isConnectedToMicrosoft
? null
: () {
if (state.settingsUIState.isChanged) {
showMessageDialog(
context: context,
message: localization.errorUnsavedChanges);
return;
}
if (state.user.isConnectedToApple) {
viewModel.onDisconnectApplePressed(context);
} else {
// do nothing
}
},
if (state.user.isConnectedToApple) {
viewModel.onDisconnectApplePressed(context);
} else {
// do nothing
}
},
),
);

View File

@ -106,9 +106,9 @@ class SubscriptionListVM {
EntityAction action) =>
handleSubscriptionAction(context, subscriptions, action),
onRefreshed: (context) => _handleRefresh(context),
tableColumns: state.userCompany.settings
.getTableColumns(EntityType.subscription) ??
SubscriptionPresenter.getDefaultTableFields(state.userCompany),
tableColumns:
state.userCompany.settings.getTableColumns(EntityType.subscription) ??
SubscriptionPresenter.getDefaultTableFields(state.userCompany),
onSortColumn: (field) => store.dispatch(SortSubscriptions(field)),
onClearMultielsect: () => store.dispatch(ClearSubscriptionMultiselect()),
);

View File

@ -229,8 +229,7 @@ class _BottomBar extends StatelessWidget {
)!,
),
context,
clientId:
state.clientState.get(task.clientId).id,
clientId: state.clientState.get(task.clientId).id,
)!;
}

View File

@ -120,7 +120,8 @@ class TransactionListItem extends StatelessWidget {
style: textStyle),
Text(
state.bankAccountState
.get(transaction!.bankAccountId).name,
.get(transaction!.bankAccountId)
.name,
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: Theme.of(context)
@ -212,7 +213,8 @@ class TransactionListItem extends StatelessWidget {
Expanded(
child: filterMatch == null
? Text(state.bankAccountState
.get(transaction!.bankAccountId).name +
.get(transaction!.bankAccountId)
.name +
'' +
(transaction!.isDeposit
? localization!.deposit!

View File

@ -65,8 +65,8 @@ class _TransactionRuleViewState extends State<TransactionRuleView> {
: localization.disabled,
localization.vendor:
state.vendorState.get(transactionRule.vendorId).name,
localization.category: state.expenseCategoryState
.get(transactionRule.categoryId).name,
localization.category:
state.expenseCategoryState.get(transactionRule.categoryId).name,
}),
if (transactionRule.rules.isNotEmpty) ...[
Padding(

View File

@ -45,8 +45,8 @@ class _VendorEditContactsState extends State<VendorEditContacts> {
key: Key(contact!.entityKey),
contact: contact,
isDialog: vendor.contacts.length > 1,
index: vendor.contacts.indexOf(
vendor.contacts.firstWhere((c) => c.id == contact.id)),
index: vendor.contacts
.indexOf(vendor.contacts.firstWhere((c) => c.id == contact.id)),
);
});
}