Null safety

This commit is contained in:
Hillel Coren 2023-09-20 10:58:07 +03:00
parent 5e490c5d05
commit b328d56c23
10 changed files with 82 additions and 42 deletions

View File

@ -93,7 +93,8 @@ class ReportsScreenVM {
final GroupTotals groupTotals; final GroupTotals groupTotals;
final Function(BuildContext, List<String>) onReportColumnsChanged; final Function(BuildContext, List<String>) onReportColumnsChanged;
final Function(BuildContext) onExportPressed; final Function(BuildContext) onExportPressed;
final Function(BuildContext, BuiltMap<String?, String?>) onReportFiltersChanged; final Function(BuildContext, BuiltMap<String?, String?>)
onReportFiltersChanged;
final Function(String?, bool) onReportSorted; final Function(String?, bool) onReportSorted;
final Function(int, bool) onReportTotalsSorted; final Function(int, bool) onReportTotalsSorted;
final Function({ final Function({
@ -471,7 +472,8 @@ class ReportsScreenVM {
getReportColumnType(column, context) == getReportColumnType(column, context) ==
ReportColumnType.number) ReportColumnType.number)
.toList(); .toList();
columns.sort((String? str1, String? str2) => str1!.compareTo(str2!)); columns
.sort((String? str1, String? str2) => str1!.compareTo(str2!));
csvData += localization!.lookup(reportState.group)! + csvData += localization!.lookup(reportState.group)! +
',' + ',' +
@ -651,7 +653,7 @@ GroupTotals calculateReportTotals({
final column = columns[j]; final column = columns[j];
if (column == reportState.group) { if (column == reportState.group) {
totals[group]!['count'] += 1; totals[group]!['count'] = totals[group]!['count']! + 1;
} }
if (cell is ReportNumberValue || if (cell is ReportNumberValue ||
@ -676,9 +678,9 @@ GroupTotals calculateReportTotals({
fromCurrencyId: cell.currencyId, fromCurrencyId: cell.currencyId,
toCurrencyId: company.currencyId); toCurrencyId: company.currencyId);
cellValue = round(cellValue * rate, toCurrency.precision); cellValue = round(cellValue * rate, toCurrency.precision);
totals[group]![column] += cellValue; totals[group]![column] = totals[group]![column]! + cellValue;
} else { } else {
totals[group]![column] += cell.doubleValue!; totals[group]![column] = totals[group]![column]! + cell.doubleValue!;
} }
} }
} }

View File

@ -129,8 +129,9 @@ class _ScheduleEditState extends State<ScheduleEdit> {
''); '');
return EditScaffold( return EditScaffold(
title: title: schedule.isNew
schedule.isNew ? localization!.newSchedule : localization!.editSchedule, ? localization!.newSchedule
: localization!.editSchedule,
onCancelPressed: (context) => viewModel.onCancelPressed(context), onCancelPressed: (context) => viewModel.onCancelPressed(context),
onSavePressed: (context) => _onSavePressed(), onSavePressed: (context) => _onSavePressed(),
body: Form( body: Form(
@ -236,7 +237,8 @@ class _ScheduleEditState extends State<ScheduleEdit> {
labelText: localization.dateRange, labelText: localization.dateRange,
blankValue: null, blankValue: null,
value: parameters.dateRange!.isNotEmpty value: parameters.dateRange!.isNotEmpty
? DateRange.valueOf(toCamelCase(parameters.dateRange!)) ? DateRange.valueOf(
toCamelCase(parameters.dateRange!))
: null, : null,
onChanged: (dynamic value) { onChanged: (dynamic value) {
viewModel.onChanged(schedule.rebuild((b) => b viewModel.onChanged(schedule.rebuild((b) => b
@ -290,8 +292,8 @@ class _ScheduleEditState extends State<ScheduleEdit> {
label: localization.onlyClientsWithInvoices, label: localization.onlyClientsWithInvoices,
value: parameters.onlyClientsWithInvoices, value: parameters.onlyClientsWithInvoices,
onChanged: (value) { onChanged: (value) {
viewModel.onChanged(schedule.rebuild( viewModel.onChanged(schedule.rebuild((b) =>
(b) => b..parameters.onlyClientsWithInvoices = value)); b..parameters.onlyClientsWithInvoices = value));
}), }),
]), ]),
FormCard( FormCard(
@ -305,6 +307,9 @@ class _ScheduleEditState extends State<ScheduleEdit> {
clientState: state.clientState, clientState: state.clientState,
excludeIds: parameters.clients!.toList(), excludeIds: parameters.clients!.toList(),
onSelected: (value) { onSelected: (value) {
if (value == null) {
return;
}
if (!parameters.clients!.contains(value.id)) { if (!parameters.clients!.contains(value.id)) {
viewModel.onChanged(schedule.rebuild( viewModel.onChanged(schedule.rebuild(
(b) => b..parameters.clients.add(value.id))); (b) => b..parameters.clients.add(value.id)));
@ -319,8 +324,8 @@ class _ScheduleEditState extends State<ScheduleEdit> {
HelpText(localization.allClients), HelpText(localization.allClients),
for (var clientId in parameters.clients!) for (var clientId in parameters.clients!)
ListTile( ListTile(
title: title: Text(
Text(state.clientState.get(clientId)!.displayName), state.clientState.get(clientId)!.displayName),
trailing: IconButton( trailing: IconButton(
icon: Icon(Icons.clear), icon: Icon(Icons.clear),
onPressed: () { onPressed: () {

View File

@ -43,9 +43,9 @@ class ScheduleListItem extends StatelessWidget {
String subtitle = formatDate(schedule!.nextRun, context); String subtitle = formatDate(schedule!.nextRun, context);
String? title = localization.lookup(schedule!.template); String title = localization.lookup(schedule!.template) ?? '';
if (schedule!.template == ScheduleEntity.TEMPLATE_EMAIL_RECORD) { if (schedule!.template == ScheduleEntity.TEMPLATE_EMAIL_RECORD) {
final entityType = EntityType.valueOf(schedule!.parameters.entityType); final entityType = EntityType.valueOf(schedule!.parameters.entityType!);
final entity = final entity =
state.getEntityMap(entityType)![schedule!.parameters.entityId]; state.getEntityMap(entityType)![schedule!.parameters.entityId];
@ -87,7 +87,8 @@ class ScheduleListItem extends StatelessWidget {
child: Container( child: Container(
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
child: ListTile( child: ListTile(
onTap: () => onTap != null ? onTap!() : selectEntity(entity: schedule!), onTap: () =>
onTap != null ? onTap!() : selectEntity(entity: schedule!),
onLongPress: () => onLongPress != null onLongPress: () => onLongPress != null
? onLongPress!() ? onLongPress!()
: selectEntity(entity: schedule!, longPress: true), : selectEntity(entity: schedule!, longPress: true),

View File

@ -36,8 +36,9 @@ class _ScheduleViewState extends State<ScheduleView> {
BaseEntity? entity; BaseEntity? entity;
if (schedule.template == ScheduleEntity.TEMPLATE_EMAIL_RECORD) { if (schedule.template == ScheduleEntity.TEMPLATE_EMAIL_RECORD) {
final entityType = EntityType.valueOf(schedule.parameters.entityType); final entityType = EntityType.valueOf(schedule.parameters.entityType!);
entity = state.getEntityMap(entityType)![schedule.parameters.entityId] as BaseEntity?; entity = state.getEntityMap(entityType)![schedule.parameters.entityId]
as BaseEntity?;
} }
return ViewScaffold( return ViewScaffold(
@ -86,9 +87,11 @@ class _ScheduleViewState extends State<ScheduleView> {
localization.showPaymentsTable: parameters.showPaymentsTable! localization.showPaymentsTable: parameters.showPaymentsTable!
? localization.yes ? localization.yes
: localization.no, : localization.no,
localization.onlyClientsWithInvoices: (parameters.onlyClientsWithInvoices != null && parameters.onlyClientsWithInvoices!) localization.onlyClientsWithInvoices:
? localization.yes (parameters.onlyClientsWithInvoices != null &&
: localization.no, parameters.onlyClientsWithInvoices!)
? localization.yes
: localization.no,
localization.status: localization.lookup(parameters.status), localization.status: localization.lookup(parameters.status),
}) })
], ],

View File

@ -46,9 +46,11 @@ Completer<T> snackBarCompleter<T>(
Completer<Null> popCompleter(BuildContext context, dynamic result) { Completer<Null> popCompleter(BuildContext context, dynamic result) {
final Completer<Null> completer = Completer<Null>(); final Completer<Null> completer = Completer<Null>();
completer.future.then((_) { completer.future
.then<Null>(() {
Navigator.of(context).pop<dynamic>(result); Navigator.of(context).pop<dynamic>(result);
} as FutureOr<_> Function(Null)).catchError((Object error) { } as FutureOr<Null> Function(Null))
.catchError((Object error) {
showDialog<ErrorDialog>( showDialog<ErrorDialog>(
context: navigatorKey.currentContext!, context: navigatorKey.currentContext!,
builder: (BuildContext context) { builder: (BuildContext context) {

View File

@ -419,7 +419,7 @@ class _FieldConfirmationState extends State<FieldConfirmation> {
maxLengthEnforcement: widget.maxLength != null maxLengthEnforcement: widget.maxLength != null
? MaxLengthEnforcement.enforced ? MaxLengthEnforcement.enforced
: MaxLengthEnforcement.none, : MaxLengthEnforcement.none,
buildCounter: (_, {currentLength, maxLength, isFocused}) => null, //buildCounter: (_, {currentLength, maxLength, isFocused}) => null,
decoration: InputDecoration( decoration: InputDecoration(
labelText: widget.field, labelText: widget.field,
), ),

View File

@ -1,3 +1,4 @@
/*
// DELETE THIS FILE ONCE SUPER EDITOR IS UPDATED // DELETE THIS FILE ONCE SUPER EDITOR IS UPDATED
import 'dart:convert'; import 'dart:convert';
@ -587,3 +588,4 @@ class _EmptyParagraphSyntax extends md.BlockSyntax {
return md.Element('p', []); return md.Element('p', []);
} }
} }
*/

View File

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:invoiceninja_flutter/utils/markdown.dart'; import 'package:invoiceninja_flutter/utils/markdown.dart';
import 'package:invoiceninja_flutter/utils/super_editor/toolbar.dart'; import 'package:invoiceninja_flutter/utils/super_editor/toolbar.dart';
import 'package:super_editor/super_editor.dart'; import 'package:super_editor/super_editor.dart';
import 'package:super_editor_markdown/super_editor_markdown.dart';
/// Example of a rich text editor. /// Example of a rich text editor.
/// ///

View File

@ -45,10 +45,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: attributed_text name: attributed_text
sha256: "892b9517ba27f78ebee526424a91d1aba44d729e610f06a0dd9a3a43d3d81f6d" sha256: e43495051b63e6cdbe96aa62123974074cca109d9c56f74ce2ffaec8060e044e
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.2.1" version: "0.2.2"
barcode: barcode:
dependency: transitive dependency: transitive
description: description:
@ -466,6 +466,14 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
follow_the_leader:
dependency: transitive
description:
name: follow_the_leader
sha256: "44396bad4abbf0d43d5ca3ee98180772bb45a78f39a1960c62170843bd46753f"
url: "https://pub.dev"
source: hosted
version: "0.0.4+3"
frontend_server_client: frontend_server_client:
dependency: transitive dependency: transitive
description: description:
@ -808,13 +816,13 @@ packages:
source: hosted source: hosted
version: "1.0.2" version: "1.0.2"
markdown: markdown:
dependency: "direct main" dependency: transitive
description: description:
name: markdown name: markdown
sha256: "39caf989ccc72c63e87b961851a74257141938599ed2db45fbd9403fee0db423" sha256: "01512006c8429f604eb10f9848717baeaedf99e991d14a50d540d9beff08e5c6"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "5.0.0" version: "4.0.1"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
@ -911,6 +919,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.3.1" version: "0.3.1"
overlord:
dependency: transitive
description:
name: overlord
sha256: "7fa6a83455b7da5c66a16320c02783d110c574a6e6c511750c662dbadfe9399f"
url: "https://pub.dev"
source: hosted
version: "0.0.3+2"
package_config: package_config:
dependency: transitive dependency: transitive
description: description:
@ -1456,20 +1472,27 @@ packages:
super_editor: super_editor:
dependency: "direct main" dependency: "direct main"
description: description:
path: super_editor name: super_editor
ref: HEAD sha256: "2d5acf95449f53eec1c7d0788530b3a667758224a1e4aa4164bd5d6c0d159bab"
resolved-ref: e4eceea4a72706410a1e910ad0ce01b815c63a8e url: "https://pub.dev"
url: "https://github.com/superlistapp/super_editor.git" source: hosted
source: git version: "0.2.6"
version: "0.2.3-dev.1" super_editor_markdown:
dependency: "direct main"
description:
name: super_editor_markdown
sha256: "2515d0183ee21aa22d577e95e80b1e4bc1b9ce0f651127d40844be7cb58b5330"
url: "https://pub.dev"
source: hosted
version: "0.1.5"
super_text_layout: super_text_layout:
dependency: transitive dependency: transitive
description: description:
name: super_text_layout name: super_text_layout
sha256: "6cf41a07780d7e40cec56ed3dcde59b527968a4e282b78e2d7e9a0134b26685c" sha256: "8afed48db5e15c9c3488ca9f24b24cd24a4867a6d9d2dd2ba540ac363f50b60d"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.1.4" version: "0.1.6"
sync_http: sync_http:
dependency: transitive dependency: transitive
description: description:

View File

@ -69,12 +69,13 @@ dependencies:
contacts_service: ^0.6.3 contacts_service: ^0.6.3
diacritic: ^0.1.3 diacritic: ^0.1.3
states_rebuilder: ^6.2.0 states_rebuilder: ^6.2.0
# super_editor: ^0.2.2 super_editor: ^0.2.6
markdown: ^5.0.0 # REMOVE THIS super_editor_markdown: ^0.1.5
super_editor: #markdown: ^5.0.0 # REMOVE THIS
git: #super_editor:
url: https://github.com/superlistapp/super_editor.git # git:
path: super_editor # url: https://github.com/superlistapp/super_editor.git
# path: super_editor
html2md: ^1.2.6 html2md: ^1.2.6
printing: ^5.10.1 printing: ^5.10.1
image_cropper: ^3.0.1 image_cropper: ^3.0.1