Skip to content

Commit

Permalink
Merge pull request #23 from tomasweigenast/dev
Browse files Browse the repository at this point in the history
add italian locale
  • Loading branch information
tomasweigenast authored Jun 3, 2024
2 parents d0e2c97 + 59cffb2 commit b2ff55e
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.0

- Add Italian locale

## 2.0.1

- Fix a bug in controller that does not reload dataset when applying a sort filter
Expand Down
14 changes: 7 additions & 7 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.0.1"
version: "2.1.0"
path:
dependency: transitive
description:
Expand All @@ -227,10 +227,10 @@ packages:
dependency: transitive
description:
name: path_provider_android
sha256: a248d8146ee5983446bf03ed5ea8f6533129a12b11f12057ad1b4a67a2b3b41d
sha256: "9c96da072b421e98183f9ea7464898428e764bc0ce5567f27ec8693442e72514"
url: "https://pub.dev"
source: hosted
version: "2.2.4"
version: "2.2.5"
path_provider_foundation:
dependency: transitive
description:
Expand Down Expand Up @@ -368,10 +368,10 @@ packages:
dependency: transitive
description:
name: win32
sha256: "0eaf06e3446824099858367950a813472af675116bf63f008a4c2a75ae13e9cb"
sha256: a79dbe579cb51ecd6d30b17e0cae4e0ea15e2c0e66f69ad4198f22a6789e94f4
url: "https://pub.dev"
source: hosted
version: "5.5.0"
version: "5.5.1"
xdg_directories:
dependency: transitive
description:
Expand All @@ -381,5 +381,5 @@ packages:
source: hosted
version: "1.0.4"
sdks:
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.19.2"
dart: ">=3.4.0 <4.0.0"
flutter: ">=3.22.0"
4 changes: 4 additions & 0 deletions lib/l10n/generated/intl/messages_all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import 'package:intl/src/intl_helpers.dart';
import 'messages_de.dart' as messages_de;
import 'messages_en.dart' as messages_en;
import 'messages_es.dart' as messages_es;
import 'messages_it.dart' as messages_it;

typedef Future<dynamic> LibraryLoader();
Map<String, LibraryLoader> _deferredLibraries = {
'de': () => new SynchronousFuture(null),
'en': () => new SynchronousFuture(null),
'es': () => new SynchronousFuture(null),
'it': () => new SynchronousFuture(null),
};

MessageLookupByLibrary? _findExact(String localeName) {
Expand All @@ -35,6 +37,8 @@ MessageLookupByLibrary? _findExact(String localeName) {
return messages_en.messages;
case 'es':
return messages_es.messages;
case 'it':
return messages_it.messages;
default:
return null;
}
Expand Down
59 changes: 59 additions & 0 deletions lib/l10n/generated/intl/messages_it.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// DO NOT EDIT. This is code generated via package:intl/generate_localized.dart
// This is a library that provides messages for a it locale. All the
// messages from the main program should be duplicated here with the same
// function name.

// Ignore issues from commonly used lints in this file.
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';

final messages = new MessageLookup();

typedef String MessageIfAbsent(String messageStr, List<dynamic> args);

class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'it';

static String m0(currentPage) => "Pagina ${currentPage}";

static String m1(time) => "Ultimo aggiornamento alle ${time}";

static String m2(totalElements) =>
"Visualizzazione di ${totalElements} elementi";

final messages = _notInlinedMessages(_notInlinedMessages);
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"applyFilterButtonText":
MessageLookupByLibrary.simpleMessage("Applica"),
"cancelFilteringButtonText":
MessageLookupByLibrary.simpleMessage("Annulla"),
"editableColumnCancelButtonText":
MessageLookupByLibrary.simpleMessage("Annulla"),
"editableColumnSaveChangesButtonText":
MessageLookupByLibrary.simpleMessage("Salva"),
"filterByTitle": MessageLookupByLibrary.simpleMessage("Filtra per"),
"nextPageButtonText":
MessageLookupByLibrary.simpleMessage("Pagina successiva"),
"noItemsFoundText":
MessageLookupByLibrary.simpleMessage("Nessun elemento trovato"),
"pageIndicatorText": m0,
"previousPageButtonText":
MessageLookupByLibrary.simpleMessage("Pagina precedente"),
"refreshText": MessageLookupByLibrary.simpleMessage("Aggiorna"),
"refreshedAtText": m1,
"removeAllFiltersButtonText":
MessageLookupByLibrary.simpleMessage("Rimuovi"),
"removeFilterButtonText":
MessageLookupByLibrary.simpleMessage("Rimuovi filtro"),
"rowsPerPageText":
MessageLookupByLibrary.simpleMessage("Righe per pagina"),
"showFilterMenuTooltip": MessageLookupByLibrary.simpleMessage("Filtro"),
"totalElementsText": m2
};
}
1 change: 1 addition & 0 deletions lib/l10n/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions lib/l10n/intl_it.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"showFilterMenuTooltip": "Filtro",
"filterByTitle": "Filtra per",
"applyFilterButtonText": "Applica",
"cancelFilteringButtonText": "Annulla",
"removeAllFiltersButtonText": "Rimuovi",
"editableColumnSaveChangesButtonText": "Salva",
"editableColumnCancelButtonText": "Annulla",
"removeFilterButtonText": "Rimuovi filtro",
"refreshText": "Aggiorna",
"refreshedAtText": "Ultimo aggiornamento alle {time}",
"@refreshedAtText": {
"placeholders": {
"time": {}
}
},
"rowsPerPageText": "Righe per pagina",
"pageIndicatorText": "Pagina {currentPage}",
"@pageIndicatorText": {
"placeholders": {
"currentPage": {}
}
},
"totalElementsText": "Visualizzazione di {totalElements} elementi",
"@totalElementsText": {
"placeholders": {
"totalElements": {}
}
},
"nextPageButtonText": "Pagina successiva",
"previousPageButtonText": "Pagina precedente",
"noItemsFoundText": "Nessun elemento trovato"
}
70 changes: 47 additions & 23 deletions lib/src/controller.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
part of 'paged_datatable.dart';

typedef Fetcher<K extends Comparable<K>, T> = FutureOr<(List<T> resultset, K? nextPageToken)> Function(
int pageSize, SortModel? sortModel, FilterModel filterModel, K? pageToken);
typedef Fetcher<K extends Comparable<K>, T>
= FutureOr<(List<T> resultset, K? nextPageToken)> Function(int pageSize,
SortModel? sortModel, FilterModel filterModel, K? pageToken);

typedef RowChangeListener<K extends Comparable<K>, T> = void Function(int index, T item);
typedef RowChangeListener<K extends Comparable<K>, T> = void Function(
int index, T item);

/// [PagedDataTableController] represents the state of a [PagedDataTable] of type [T], using pagination keys of type [K].
///
/// Is recommended that [T] specifies a custom hashCode and equals method for comparison reasons.
final class PagedDataTableController<K extends Comparable<K>, T> extends ChangeNotifier {
final List<T> _currentDataset = []; // the current dataset that is being displayed
final Map<String, FilterState> _filtersState = {}; // The list of filters' states
final Map<int, K> _paginationKeys = {}; // it's a map because on not found map will return null, list will throw
final class PagedDataTableController<K extends Comparable<K>, T>
extends ChangeNotifier {
final List<T> _currentDataset =
[]; // the current dataset that is being displayed
final Map<String, FilterState> _filtersState =
{}; // The list of filters' states
final Map<int, K> _paginationKeys =
{}; // it's a map because on not found map will return null, list will throw
final Set<int> _selectedRows = {}; // The list of selected row indexes
final GlobalKey<FormState> _filtersFormKey = GlobalKey();
late final List<int>? _pageSizes;
Expand All @@ -24,11 +30,14 @@ final class PagedDataTableController<K extends Comparable<K>, T> extends ChangeN
};
PagedDataTableConfiguration? _configuration;

Object? _currentError; // If something went wrong when fetching items, this is the latest error
Object?
_currentError; // If something went wrong when fetching items, this is the latest error
int _totalItems = 0; // the total items in the current dataset
int _currentPageSize = 0;
int _currentPageIndex = 0; // The current index of the page, used to lookup token inside _paginationKeys
bool _hasNextPage = false; // a flag that indicates if there are more pages after the current one
int _currentPageIndex =
0; // The current index of the page, used to lookup token inside _paginationKeys
bool _hasNextPage =
false; // a flag that indicates if there are more pages after the current one
SortModel? _currentSortModel; // The current sort model of the table
_TableState _state = _TableState.idle;

Expand Down Expand Up @@ -58,7 +67,8 @@ final class PagedDataTableController<K extends Comparable<K>, T> extends ChangeN
List<int> get selectedRows => _selectedRows.toList(growable: false);

/// The list of selected items.
List<T> get selectedItems => UnmodifiableListView(_selectedRows.map((index) => _currentDataset[index]));
List<T> get selectedItems => UnmodifiableListView(
_selectedRows.map((index) => _currentDataset[index]));

/// Updates the sort model and refreshes the dataset
set sortModel(SortModel? sortModel) {
Expand All @@ -82,7 +92,8 @@ final class PagedDataTableController<K extends Comparable<K>, T> extends ChangeN
if (_currentSortModel!.descending) {
sortModel = null;
} else {
sortModel = SortModel._(fieldName: _currentSortModel!.fieldName, descending: true);
sortModel = SortModel._(
fieldName: _currentSortModel!.fieldName, descending: true);
}
}

Expand Down Expand Up @@ -136,7 +147,9 @@ final class PagedDataTableController<K extends Comparable<K>, T> extends ChangeN
/// Removes a row at the specified [index].
void removeRowAt(int index) {
if (index >= _totalItems) {
throw ArgumentError("index cannot be greater than or equals to the total list of items.", "index");
throw ArgumentError(
"index cannot be greater than or equals to the total list of items.",
"index");
}

if (index < 0) {
Expand Down Expand Up @@ -164,7 +177,9 @@ final class PagedDataTableController<K extends Comparable<K>, T> extends ChangeN
/// Replaces the element at [index] with [value]
void replace(int index, T value) {
if (index >= _totalItems) {
throw ArgumentError("Index cannot be greater than or equals to the total size of the current dataset.", "index");
throw ArgumentError(
"Index cannot be greater than or equals to the total size of the current dataset.",
"index");
}

_currentDataset[index] = value;
Expand Down Expand Up @@ -209,15 +224,18 @@ final class PagedDataTableController<K extends Comparable<K>, T> extends ChangeN

/// Registers a callback that gets called when the row at [index] is updated.
void addRowChangeListener(int index, RowChangeListener<K, T> onRowChange) {
final listeners = _listeners[_ListenerType.rowChange] as Map<int, List<RowChangeListener<K, T>>>;
final listeners = _listeners[_ListenerType.rowChange]
as Map<int, List<RowChangeListener<K, T>>>;
final listenersForIndex = listeners[index] ?? [];
listenersForIndex.add(onRowChange);
listeners[index] = listenersForIndex;
}

/// Unregisters a row change callback.
void removeRowChangeListener(int index, RowChangeListener<K, T> rowChangeListener) {
final listeners = _listeners[_ListenerType.rowChange] as Map<int, List<RowChangeListener<K, T>>>;
void removeRowChangeListener(
int index, RowChangeListener<K, T> rowChangeListener) {
final listeners = _listeners[_ListenerType.rowChange]
as Map<int, List<RowChangeListener<K, T>>>;
final listenersForIndex = listeners[index];
if (listenersForIndex == null) return;

Expand Down Expand Up @@ -265,7 +283,8 @@ final class PagedDataTableController<K extends Comparable<K>, T> extends ChangeN
void setFilter(String filterId, dynamic value) {
final filterState = _filtersState[filterId];
if (filterState == null) {
throw ArgumentError("Filter with id $filterId does not exist.", "filterId");
throw ArgumentError(
"Filter with id $filterId does not exist.", "filterId");
}

filterState.value = value;
Expand All @@ -274,7 +293,8 @@ final class PagedDataTableController<K extends Comparable<K>, T> extends ChangeN

/// This method automatically calls notifyListeners too.
void _notifyOnRowChanged(int rowIndex) {
final rowChangeListeners = (_listeners[_ListenerType.rowChange] as Map<int, List<RowChangeListener<K, T>>>);
final rowChangeListeners = (_listeners[_ListenerType.rowChange]
as Map<int, List<RowChangeListener<K, T>>>);
final listeners = rowChangeListeners[rowIndex];
try {
if (listeners != null) {
Expand All @@ -294,7 +314,8 @@ final class PagedDataTableController<K extends Comparable<K>, T> extends ChangeN

/// This method automatically calls notifyListeners too.
void _notifyRowChangedMany(Iterable<int> indexes) {
final listeners = (_listeners[_ListenerType.rowChange] as Map<int, List<RowChangeListener<K, T>>>);
final listeners = (_listeners[_ListenerType.rowChange]
as Map<int, List<RowChangeListener<K, T>>>);
for (final index in indexes) {
try {
final listenerGroup = listeners[index];
Expand Down Expand Up @@ -328,7 +349,8 @@ final class PagedDataTableController<K extends Comparable<K>, T> extends ChangeN
_pageSizes = pageSizes;
_configuration = config;
_fetcher = fetcher;
_filtersState.addEntries(filters.map((filter) => MapEntry(filter.id, filter.createState())));
_filtersState.addEntries(
filters.map((filter) => MapEntry(filter.id, filter.createState())));

// Schedule a fetch
Future.microtask(_fetch);
Expand All @@ -348,9 +370,11 @@ final class PagedDataTableController<K extends Comparable<K>, T> extends ChangeN

try {
final pageToken = _paginationKeys[page];
final filterModel = FilterModel._(_filtersState.map((key, value) => MapEntry(key, value.value)));
final filterModel = FilterModel._(
_filtersState.map((key, value) => MapEntry(key, value.value)));

var (items, nextPageToken) = await _fetcher(_currentPageSize, sortModel, filterModel, pageToken);
var (items, nextPageToken) =
await _fetcher(_currentPageSize, sortModel, filterModel, pageToken);
_hasNextPage = nextPageToken != null;
_currentPageIndex = page;
if (nextPageToken != null) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: paged_datatable
description: A brand new way of creating paginated DataTables in Flutter with sorting and filters
version: 2.0.1
version: 2.1.0
homepage: https://github.com/tomasweigenast/paged-datatable

environment:
Expand Down

0 comments on commit b2ff55e

Please sign in to comment.