205 lines
8.5 KiB
Dart
205 lines
8.5 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_redux/flutter_redux.dart';
|
|
import 'package:invoiceninja_flutter/constants.dart';
|
|
import 'package:invoiceninja_flutter/data/models/models.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/actions_menu_button.dart';
|
|
import 'package:invoiceninja_flutter/ui/app/dismissible_entity.dart';
|
|
import 'package:invoiceninja_flutter/ui/app/entity_state_label.dart';
|
|
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
|
import 'package:invoiceninja_flutter/utils/platforms.dart';
|
|
import 'package:invoiceninja_flutter/utils/app_context.dart';
|
|
|
|
class ClientListItem extends StatelessWidget {
|
|
const ClientListItem({
|
|
@required this.user,
|
|
@required this.client,
|
|
@required this.filter,
|
|
this.onTap,
|
|
this.onLongPress,
|
|
this.onCheckboxChanged,
|
|
this.isChecked = false,
|
|
});
|
|
|
|
final UserEntity user;
|
|
final GestureTapCallback onTap;
|
|
final GestureTapCallback onLongPress;
|
|
final ClientEntity client;
|
|
final String filter;
|
|
final Function(bool) onCheckboxChanged;
|
|
final bool isChecked;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final store = StoreProvider.of<AppState>(context);
|
|
final state = store.state;
|
|
final uiState = state.uiState;
|
|
final clientUIState = uiState.clientUIState;
|
|
final filterMatch = filter != null && filter.isNotEmpty
|
|
? client.matchesFilterValue(filter)
|
|
: null;
|
|
final listUIState = clientUIState.listUIState;
|
|
final isInMultiselect = listUIState.isInMultiselect();
|
|
final showCheckbox = onCheckboxChanged != null || isInMultiselect;
|
|
final textStyle = TextStyle(fontSize: 16);
|
|
|
|
return DismissibleEntity(
|
|
isSelected: isDesktop(context) &&
|
|
client.id ==
|
|
(uiState.isEditing
|
|
? clientUIState.editing.id
|
|
: clientUIState.selectedId),
|
|
userCompany: store.state.userCompany,
|
|
entity: client,
|
|
child: LayoutBuilder(
|
|
builder: (BuildContext context, BoxConstraints constraints) {
|
|
return constraints.maxWidth > kTableListWidthCutoff
|
|
? InkWell(
|
|
onTap: () => onTap != null
|
|
? onTap()
|
|
: selectEntity(entity: client, context: context),
|
|
onLongPress: () => onLongPress != null
|
|
? onLongPress()
|
|
: selectEntity(
|
|
entity: client, context: context, longPress: true),
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: 10,
|
|
right: 28,
|
|
top: 4,
|
|
bottom: 4,
|
|
),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: 16),
|
|
child: showCheckbox
|
|
? Padding(
|
|
padding: const EdgeInsets.only(right: 20),
|
|
child: IgnorePointer(
|
|
ignoring: listUIState.isInMultiselect(),
|
|
child: Checkbox(
|
|
value: isChecked,
|
|
materialTapTargetSize:
|
|
MaterialTapTargetSize.shrinkWrap,
|
|
onChanged: (value) =>
|
|
onCheckboxChanged(value),
|
|
activeColor: Theme.of(context).accentColor,
|
|
),
|
|
),
|
|
)
|
|
: ActionMenuButton(
|
|
entityActions: client.getActions(
|
|
userCompany: state.userCompany),
|
|
isSaving: false,
|
|
entity: client,
|
|
onSelected: (context, action) =>
|
|
handleEntityAction(context.getAppContext(),
|
|
client, action),
|
|
),
|
|
),
|
|
SizedBox(
|
|
width: kListNumberWidth,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
client.number,
|
|
style: textStyle,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
if (!client.isActive) EntityStateLabel(client)
|
|
],
|
|
),
|
|
),
|
|
SizedBox(width: 10),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
Text(
|
|
client.displayName +
|
|
(client.documents.isNotEmpty ? ' 📎' : ''),
|
|
style: textStyle),
|
|
if (filterMatch != null)
|
|
Text(
|
|
filterMatch,
|
|
maxLines: 3,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context).textTheme.subtitle2,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(width: 10),
|
|
Text(
|
|
formatNumber(client.balance, context,
|
|
clientId: client.id),
|
|
style: textStyle,
|
|
textAlign: TextAlign.end,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
: ListTile(
|
|
onTap: () => onTap != null
|
|
? onTap()
|
|
: selectEntity(entity: client, context: context),
|
|
onLongPress: () => onLongPress != null
|
|
? onLongPress()
|
|
: selectEntity(
|
|
entity: client, context: context, longPress: true),
|
|
leading: showCheckbox
|
|
? IgnorePointer(
|
|
ignoring: listUIState.isInMultiselect(),
|
|
child: Checkbox(
|
|
value: isChecked,
|
|
materialTapTargetSize:
|
|
MaterialTapTargetSize.shrinkWrap,
|
|
onChanged: (value) => onCheckboxChanged(value),
|
|
activeColor: Theme.of(context).accentColor,
|
|
),
|
|
)
|
|
: null,
|
|
title: Container(
|
|
width: MediaQuery.of(context).size.width,
|
|
child: Row(
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: Text(
|
|
client.displayName +
|
|
(client.documents.isNotEmpty ? ' 📎' : ''),
|
|
style: Theme.of(context).textTheme.headline6,
|
|
),
|
|
),
|
|
Text(
|
|
formatNumber(client.balance, context,
|
|
clientId: client.id),
|
|
style: Theme.of(context).textTheme.headline6),
|
|
],
|
|
),
|
|
),
|
|
subtitle: (filterMatch == null && client.isActive)
|
|
? null
|
|
: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
filterMatch != null
|
|
? Text(
|
|
filterMatch,
|
|
maxLines: 3,
|
|
overflow: TextOverflow.ellipsis,
|
|
)
|
|
: SizedBox(),
|
|
EntityStateLabel(client),
|
|
],
|
|
),
|
|
);
|
|
}),
|
|
);
|
|
}
|
|
}
|