Flutter upgrade

This commit is contained in:
Hillel Coren 2021-11-19 12:23:54 +02:00
parent 7a7ba913be
commit 6cfb0bd066
23 changed files with 21 additions and 47 deletions

View File

@ -11,19 +11,20 @@ import 'package:flutter_redux/flutter_redux.dart';
// Project imports: // Project imports:
import 'package:invoiceninja_flutter/.env.dart'; import 'package:invoiceninja_flutter/.env.dart';
import 'package:invoiceninja_flutter/constants.dart';
import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/data/models/models.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/app/app_state.dart';
import 'package:invoiceninja_flutter/ui/app/app_border.dart'; import 'package:invoiceninja_flutter/ui/app/app_border.dart';
import 'package:invoiceninja_flutter/ui/app/forms/decorated_form_field.dart'; import 'package:invoiceninja_flutter/ui/app/forms/decorated_form_field.dart';
import 'package:invoiceninja_flutter/ui/app/responsive_padding.dart'; import 'package:invoiceninja_flutter/ui/app/responsive_padding.dart';
import 'package:invoiceninja_flutter/ui/app/scrollable_listview.dart'; import 'package:invoiceninja_flutter/ui/app/scrollable_listview.dart';
import 'package:invoiceninja_flutter/utils/colors.dart';
import 'package:invoiceninja_flutter/utils/formatting.dart'; import 'package:invoiceninja_flutter/utils/formatting.dart';
import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:invoiceninja_flutter/utils/localization.dart';
import 'package:invoiceninja_flutter/utils/platforms.dart'; import 'package:invoiceninja_flutter/utils/platforms.dart';
class EntityDropdown extends StatefulWidget { class EntityDropdown extends StatefulWidget {
const EntityDropdown({ const EntityDropdown({
@required Key key,
@required this.entityType, @required this.entityType,
@required this.labelText, @required this.labelText,
@required this.onSelected, @required this.onSelected,
@ -38,7 +39,7 @@ class EntityDropdown extends StatefulWidget {
this.onFieldSubmitted, this.onFieldSubmitted,
this.overrideSuggestedAmount, this.overrideSuggestedAmount,
this.overrideSuggestedLabel, this.overrideSuggestedLabel,
}) : super(key: key); });
final EntityType entityType; final EntityType entityType;
final List<String> entityList; final List<String> entityList;
@ -81,6 +82,15 @@ class _EntityDropdownState extends State<EntityDropdown> {
} }
} }
@override
void didUpdateWidget(oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.entityId != oldWidget.entityId) {
_textController.text = _entityMap[widget.entityId]?.listDisplayName ?? '';
}
}
@override @override
void didChangeDependencies() { void didChangeDependencies() {
final state = StoreProvider.of<AppState>(context).state; final state = StoreProvider.of<AppState>(context).state;
@ -262,6 +272,8 @@ class _EntityDropdownState extends State<EntityDropdown> {
optionsViewBuilder: (BuildContext context, optionsViewBuilder: (BuildContext context,
AutocompleteOnSelected<SelectableEntity> onSelected, AutocompleteOnSelected<SelectableEntity> onSelected,
Iterable<SelectableEntity> options) { Iterable<SelectableEntity> options) {
final highlightedIndex = AutocompleteHighlightedOption.of(context);
return Theme( return Theme(
data: theme, data: theme,
child: Align( child: Align(
@ -277,7 +289,12 @@ class _EntityDropdownState extends State<EntityDropdown> {
itemCount: options.length, itemCount: options.length,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return Container( return Container(
color: Theme.of(context).cardColor, color: highlightedIndex == index
? convertHexStringToColor(
state.prefState.enableDarkMode
? kDefaultDarkSelectedColor
: kDefaultLightSelectedColor)
: Theme.of(context).cardColor,
child: _EntityListTile( child: _EntityListTile(
onTap: (entity) => onSelected(entity), onTap: (entity) => onSelected(entity),
entity: options.elementAt(index), entity: options.elementAt(index),

View File

@ -37,7 +37,6 @@ class ClientPicker extends StatelessWidget {
final state = store.state; final state = store.state;
return EntityDropdown( return EntityDropdown(
key: ValueKey('__client_${clientId}__'),
entityType: EntityType.client, entityType: EntityType.client,
labelText: localization.client, labelText: localization.client,
entityId: clientId, entityId: clientId,

View File

@ -65,7 +65,6 @@ class DynamicSelector extends StatelessWidget {
); );
} else { } else {
return EntityDropdown( return EntityDropdown(
key: ValueKey('__entity_id_${entityId}__'),
labelText: labelText ?? localization.lookup('$entityType'), labelText: labelText ?? localization.lookup('$entityType'),
entityType: entityType, entityType: entityType,
onSelected: (entity) => onChanged(entity?.id), onSelected: (entity) => onChanged(entity?.id),

View File

@ -138,7 +138,6 @@ class ClientEditBillingAddressState extends State<ClientEditBillingAddress> {
onSavePressed: viewModel.onSavePressed, onSavePressed: viewModel.onSavePressed,
), ),
EntityDropdown( EntityDropdown(
key: ValueKey('__country_${client.countryId}__'),
entityType: EntityType.country, entityType: EntityType.country,
entityList: memoizedCountryList(viewModel.staticState.countryMap), entityList: memoizedCountryList(viewModel.staticState.countryMap),
labelText: localization.country, labelText: localization.country,

View File

@ -120,7 +120,6 @@ class ClientEditNotesState extends State<ClientEditNotes> {
showBlank: true, showBlank: true,
), ),
EntityDropdown( EntityDropdown(
key: ValueKey('__industry_${client.industryId}__'),
entityType: EntityType.industry, entityType: EntityType.industry,
entityList: memoizedIndustryList(viewModel.staticState.industryMap), entityList: memoizedIndustryList(viewModel.staticState.industryMap),
labelText: localization.industry, labelText: localization.industry,

View File

@ -95,7 +95,6 @@ class ClientEditSettingsState extends State<ClientEditSettings> {
: null, : null,
children: <Widget>[ children: <Widget>[
EntityDropdown( EntityDropdown(
key: ValueKey('__currency_${client.currencyId}__'),
entityType: EntityType.currency, entityType: EntityType.currency,
entityList: memoizedCurrencyList(viewModel.staticState.currencyMap), entityList: memoizedCurrencyList(viewModel.staticState.currencyMap),
labelText: localization.currency, labelText: localization.currency,
@ -104,7 +103,6 @@ class ClientEditSettingsState extends State<ClientEditSettings> {
.rebuild((b) => b..settings.currencyId = currency?.id ?? '')), .rebuild((b) => b..settings.currencyId = currency?.id ?? '')),
), ),
EntityDropdown( EntityDropdown(
key: ValueKey('__language_${client.languageId}__'),
entityType: EntityType.language, entityType: EntityType.language,
entityList: memoizedLanguageList(viewModel.staticState.languageMap), entityList: memoizedLanguageList(viewModel.staticState.languageMap),
labelText: localization.language, labelText: localization.language,

View File

@ -134,7 +134,6 @@ class ClientEditShippingAddressState extends State<ClientEditShippingAddress> {
onSavePressed: viewModel.onSavePressed, onSavePressed: viewModel.onSavePressed,
), ),
EntityDropdown( EntityDropdown(
key: ValueKey('__country_${client.shippingCountryId}__'),
entityType: EntityType.country, entityType: EntityType.country,
entityList: memoizedCountryList(viewModel.staticState.countryMap), entityList: memoizedCountryList(viewModel.staticState.countryMap),
labelText: localization.country, labelText: localization.country,

View File

@ -146,7 +146,6 @@ class _CompanyGatewayEditState extends State<CompanyGatewayEdit>
children: <Widget>[ children: <Widget>[
if (companyGateway.isNew) if (companyGateway.isNew)
EntityDropdown( EntityDropdown(
key: ValueKey('__gateway_${companyGateway.gatewayId}__'),
entityType: EntityType.gateway, entityType: EntityType.gateway,
entityList: entityList:
memoizedGatewayList(state.staticState.gatewayMap), memoizedGatewayList(state.staticState.gatewayMap),

View File

@ -147,7 +147,6 @@ class ExpenseEditDetailsState extends State<ExpenseEditDetails> {
autocorrect: false, autocorrect: false,
), ),
EntityDropdown( EntityDropdown(
key: ValueKey('__vendor_${expense.vendorId}__'),
//autofocus: true, //autofocus: true,
entityType: EntityType.vendor, entityType: EntityType.vendor,
labelText: localization.vendor, labelText: localization.vendor,
@ -164,7 +163,6 @@ class ExpenseEditDetailsState extends State<ExpenseEditDetails> {
), ),
if (!expense.isInvoiced) ...[ if (!expense.isInvoiced) ...[
EntityDropdown( EntityDropdown(
key: ValueKey('__client_${expense.clientId}__'),
entityType: EntityType.client, entityType: EntityType.client,
labelText: localization.client, labelText: localization.client,
entityId: expense.clientId, entityId: expense.clientId,
@ -284,7 +282,6 @@ class ExpenseEditDetailsState extends State<ExpenseEditDetails> {
), ),
if (expense.usesInclusiveTaxes) amountField, if (expense.usesInclusiveTaxes) amountField,
EntityDropdown( EntityDropdown(
key: ValueKey('__currency_${expense.currencyId}__'),
entityType: EntityType.currency, entityType: EntityType.currency,
entityList: memoizedCurrencyList(staticState.currencyMap), entityList: memoizedCurrencyList(staticState.currencyMap),
labelText: localization.currency, labelText: localization.currency,

View File

@ -189,8 +189,6 @@ class ExpenseEditSettingsState extends State<ExpenseEditSettings> {
children: <Widget>[ children: <Widget>[
SizedBox(height: 8), SizedBox(height: 8),
EntityDropdown( EntityDropdown(
key: ValueKey(
'__payment_type_${expense.paymentTypeId}__'),
entityType: EntityType.paymentType, entityType: EntityType.paymentType,
entityList: entityList:
memoizedPaymentTypeList(staticState.paymentTypeMap), memoizedPaymentTypeList(staticState.paymentTypeMap),
@ -242,8 +240,6 @@ class ExpenseEditSettingsState extends State<ExpenseEditSettings> {
children: <Widget>[ children: <Widget>[
SizedBox(height: 8), SizedBox(height: 8),
EntityDropdown( EntityDropdown(
key: ValueKey(
'__invoice_currency_${expense.invoiceCurrencyId}__'),
entityType: EntityType.currency, entityType: EntityType.currency,
entityList: entityList:
memoizedCurrencyList(staticState.currencyMap), memoizedCurrencyList(staticState.currencyMap),

View File

@ -251,7 +251,7 @@ class InvoiceEditDesktopState extends State<InvoiceEditDesktop>
children: <Widget>[ children: <Widget>[
if (invoice.isNew) if (invoice.isNew)
ClientPicker( ClientPicker(
//autofocus: true, autofocus: true,
clientId: invoice.clientId, clientId: invoice.clientId,
clientState: state.clientState, clientState: state.clientState,
onSelected: (client) { onSelected: (client) {

View File

@ -201,7 +201,6 @@ class _PaymentEditState extends State<PaymentEdit> {
children: <Widget>[ children: <Widget>[
if (payment.isNew) ...[ if (payment.isNew) ...[
EntityDropdown( EntityDropdown(
key: ValueKey('__client_${payment.clientId}__'),
entityType: EntityType.client, entityType: EntityType.client,
labelText: AppLocalization.of(context).client, labelText: AppLocalization.of(context).client,
entityId: payment.clientId, entityId: payment.clientId,
@ -269,7 +268,6 @@ class _PaymentEditState extends State<PaymentEdit> {
), ),
if (payment.isApplying != true) if (payment.isApplying != true)
EntityDropdown( EntityDropdown(
key: ValueKey('__type_${payment.typeId}__'),
entityType: EntityType.paymentType, entityType: EntityType.paymentType,
entityList: memoizedPaymentTypeList( entityList: memoizedPaymentTypeList(
viewModel.staticState.paymentTypeMap), viewModel.staticState.paymentTypeMap),
@ -369,8 +367,6 @@ class _PaymentEditState extends State<PaymentEdit> {
), ),
if (_showConvertCurrency) ...[ if (_showConvertCurrency) ...[
EntityDropdown( EntityDropdown(
key: ValueKey(
'__currency_${payment.exchangeCurrencyId}_${_showConvertCurrency}__'),
entityType: EntityType.currency, entityType: EntityType.currency,
entityList: entityList:
memoizedCurrencyList(viewModel.staticState.currencyMap), memoizedCurrencyList(viewModel.staticState.currencyMap),
@ -644,7 +640,6 @@ class _PaymentableEditorState extends State<PaymentableEditor> {
if (widget.entityType == EntityType.invoice) if (widget.entityType == EntityType.invoice)
Expanded( Expanded(
child: EntityDropdown( child: EntityDropdown(
key: ValueKey('__invoice_${paymentable.invoiceId}__'),
allowClearing: false, allowClearing: false,
entityType: EntityType.invoice, entityType: EntityType.invoice,
labelText: AppLocalization.of(context).invoice, labelText: AppLocalization.of(context).invoice,
@ -675,7 +670,6 @@ class _PaymentableEditorState extends State<PaymentableEditor> {
if (widget.entityType == EntityType.credit) if (widget.entityType == EntityType.credit)
Expanded( Expanded(
child: EntityDropdown( child: EntityDropdown(
key: ValueKey('__credit_${paymentable.creditId}__'),
allowClearing: false, allowClearing: false,
entityType: EntityType.credit, entityType: EntityType.credit,
labelText: AppLocalization.of(context).credit, labelText: AppLocalization.of(context).credit,

View File

@ -319,7 +319,6 @@ class _PaymentableEditorState extends State<PaymentableEditor> {
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: EntityDropdown( child: EntityDropdown(
key: ValueKey('__invoice_${paymentable.invoiceId}__'),
allowClearing: false, allowClearing: false,
entityType: EntityType.invoice, entityType: EntityType.invoice,
labelText: AppLocalization.of(context).invoice, labelText: AppLocalization.of(context).invoice,

View File

@ -164,7 +164,6 @@ class _ProjectEditState extends State<ProjectEdit> {
), ),
project.isNew project.isNew
? EntityDropdown( ? EntityDropdown(
key: ValueKey('__client_${project.clientId}__'),
entityType: EntityType.client, entityType: EntityType.client,
labelText: localization.client, labelText: localization.client,
entityId: project.clientId, entityId: project.clientId,

View File

@ -330,7 +330,6 @@ class _CompanyDetailsState extends State<CompanyDetails>
showBlank: true, showBlank: true,
), ),
EntityDropdown( EntityDropdown(
key: ValueKey('__industry_${company.industryId}__'),
entityType: EntityType.industry, entityType: EntityType.industry,
entityList: entityList:
memoizedIndustryList(state.staticState.industryMap), memoizedIndustryList(state.staticState.industryMap),
@ -383,7 +382,6 @@ class _CompanyDetailsState extends State<CompanyDetails>
autofillHints: [AutofillHints.postalCode], autofillHints: [AutofillHints.postalCode],
), ),
EntityDropdown( EntityDropdown(
key: ValueKey('__country_${settings.countryId}__'),
entityType: EntityType.country, entityType: EntityType.country,
entityList: entityList:
memoizedCountryList(state.staticState.countryMap), memoizedCountryList(state.staticState.countryMap),
@ -475,8 +473,6 @@ class _CompanyDetailsState extends State<CompanyDetails>
)) ))
.toList()), .toList()),
EntityDropdown( EntityDropdown(
key: ValueKey(
'__default_payment_type_${settings.defaultPaymentTypeId}__'),
entityType: EntityType.paymentType, entityType: EntityType.paymentType,
entityList: memoizedPaymentTypeList( entityList: memoizedPaymentTypeList(
state.staticState.paymentTypeMap), state.staticState.paymentTypeMap),

View File

@ -277,7 +277,6 @@ class _InvoiceDesignState extends State<InvoiceDesign>
LearnMoreUrl( LearnMoreUrl(
url: 'https://fonts.google.com', url: 'https://fonts.google.com',
child: EntityDropdown( child: EntityDropdown(
key: ValueKey('__primary_font_${settings.primaryFont}__'),
entityType: EntityType.font, entityType: EntityType.font,
labelText: localization.primaryFont, labelText: localization.primaryFont,
entityId: settings.primaryFont, entityId: settings.primaryFont,
@ -287,8 +286,6 @@ class _InvoiceDesignState extends State<InvoiceDesign>
), ),
), ),
EntityDropdown( EntityDropdown(
key: ValueKey(
'__secondary_fond_${settings.secondaryFont}__'),
entityType: EntityType.font, entityType: EntityType.font,
labelText: localization.secondaryFont, labelText: localization.secondaryFont,
entityId: settings.secondaryFont, entityId: settings.secondaryFont,

View File

@ -142,7 +142,6 @@ class _LocalizationSettingsState extends State<LocalizationSettings>
FormCard( FormCard(
children: <Widget>[ children: <Widget>[
EntityDropdown( EntityDropdown(
key: ValueKey('__currency_${settings.currencyId}__'),
entityType: EntityType.currency, entityType: EntityType.currency,
entityList: entityList:
memoizedCurrencyList(state.staticState.currencyMap), memoizedCurrencyList(state.staticState.currencyMap),
@ -171,7 +170,6 @@ class _LocalizationSettingsState extends State<LocalizationSettings>
url: kTransifexURL, url: kTransifexURL,
label: localization.helpTranslate, label: localization.helpTranslate,
child: EntityDropdown( child: EntityDropdown(
key: ValueKey('__language_${settings.languageId}__'),
entityType: EntityType.language, entityType: EntityType.language,
entityList: entityList:
memoizedLanguageList(state.staticState.languageMap), memoizedLanguageList(state.staticState.languageMap),
@ -183,7 +181,6 @@ class _LocalizationSettingsState extends State<LocalizationSettings>
), ),
), ),
EntityDropdown( EntityDropdown(
key: ValueKey('__timezone_${settings.timezoneId}__'),
entityType: EntityType.timezone, entityType: EntityType.timezone,
entityList: entityList:
memoizedTimezoneList(state.staticState.timezoneMap), memoizedTimezoneList(state.staticState.timezoneMap),
@ -194,7 +191,6 @@ class _LocalizationSettingsState extends State<LocalizationSettings>
.rebuild((b) => b..timezoneId = timezone?.id)), .rebuild((b) => b..timezoneId = timezone?.id)),
), ),
EntityDropdown( EntityDropdown(
key: ValueKey('__date_format_${settings.dateFormatId}__'),
entityType: EntityType.dateFormat, entityType: EntityType.dateFormat,
entityList: entityList:
memoizedDateFormatList(state.staticState.dateFormatMap), memoizedDateFormatList(state.staticState.dateFormatMap),

View File

@ -248,7 +248,6 @@ class _SettingsWizardState extends State<SettingsWizard> {
); );
final currency = EntityDropdown( final currency = EntityDropdown(
key: ValueKey('__currency_${_currencyId}__'),
entityType: EntityType.currency, entityType: EntityType.currency,
entityList: memoizedCurrencyList(state.staticState.currencyMap), entityList: memoizedCurrencyList(state.staticState.currencyMap),
labelText: localization.currency, labelText: localization.currency,
@ -260,7 +259,6 @@ class _SettingsWizardState extends State<SettingsWizard> {
); );
final language = EntityDropdown( final language = EntityDropdown(
key: ValueKey('__language_${_languageId}__'),
entityType: EntityType.language, entityType: EntityType.language,
entityList: memoizedLanguageList(state.staticState.languageMap), entityList: memoizedLanguageList(state.staticState.languageMap),
labelText: localization.language, labelText: localization.language,

View File

@ -252,7 +252,6 @@ class _SubscriptionEditState extends State<SubscriptionEdit>
isLast: true, isLast: true,
children: <Widget>[ children: <Widget>[
EntityDropdown( EntityDropdown(
key: ValueKey('__products_${subscription.productIds}__'),
entityType: EntityType.product, entityType: EntityType.product,
entityList: dropdownProductsSelector(state.productState.map, entityList: dropdownProductsSelector(state.productState.map,
state.productState.list, state.userState.map), state.productState.list, state.userState.map),
@ -291,8 +290,6 @@ class _SubscriptionEditState extends State<SubscriptionEdit>
height: 16, height: 16,
), ),
EntityDropdown( EntityDropdown(
key: ValueKey(
'__recuring_products_${subscription.recurringProductIds}__'),
entityType: EntityType.product, entityType: EntityType.product,
entityList: dropdownProductsSelector(state.productState.map, entityList: dropdownProductsSelector(state.productState.map,
state.productState.list, state.userState.map), state.productState.list, state.userState.map),

View File

@ -164,7 +164,6 @@ class _TaskEditDesktopState extends State<TaskEditDesktop> {
children: [ children: [
if (!task.isInvoiced) ...[ if (!task.isInvoiced) ...[
EntityDropdown( EntityDropdown(
key: ValueKey('__client_${task.clientId}__'),
entityType: EntityType.client, entityType: EntityType.client,
labelText: localization.client, labelText: localization.client,
entityId: task.clientId, entityId: task.clientId,

View File

@ -130,7 +130,6 @@ class _TaskEditDetailsState extends State<TaskEditDetails> {
children: <Widget>[ children: <Widget>[
if (!task.isInvoiced) ...[ if (!task.isInvoiced) ...[
EntityDropdown( EntityDropdown(
key: ValueKey('__client_${task.clientId}__'),
entityType: EntityType.client, entityType: EntityType.client,
labelText: localization.client, labelText: localization.client,
entityId: task.clientId, entityId: task.clientId,

View File

@ -128,7 +128,6 @@ class VendorEditAddressState extends State<VendorEditAddress> {
onSavePressed: viewModel.onSavePressed, onSavePressed: viewModel.onSavePressed,
), ),
EntityDropdown( EntityDropdown(
key: ValueKey('__country_${vendor.countryId}__'),
entityType: EntityType.country, entityType: EntityType.country,
entityList: entityList:
memoizedCountryList(viewModel.state.staticState.countryMap), memoizedCountryList(viewModel.state.staticState.countryMap),

View File

@ -94,7 +94,6 @@ class VendorEditNotesState extends State<VendorEditNotes> {
: null, : null,
children: <Widget>[ children: <Widget>[
EntityDropdown( EntityDropdown(
key: ValueKey('__currency_${vendor.currencyId}__'),
entityType: EntityType.currency, entityType: EntityType.currency,
entityList: memoizedCurrencyList(staticState.currencyMap), entityList: memoizedCurrencyList(staticState.currencyMap),
labelText: localization.currency, labelText: localization.currency,