forked from bosskmk/pluto_grid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
116 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,82 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:intl/intl.dart' as intl; | ||
|
||
class PlutoCell { | ||
/// Value of cell | ||
dynamic value; | ||
import 'pluto_column.dart'; | ||
import 'pluto_column_type.dart'; | ||
|
||
class PlutoCell { | ||
PlutoCell({ | ||
this.value, | ||
}) : _key = UniqueKey(); | ||
dynamic value, | ||
}) : _key = UniqueKey(), | ||
_value = value; | ||
|
||
/// cell key | ||
final Key _key; | ||
|
||
Key get key => _key; | ||
|
||
/// cell value | ||
dynamic _value; | ||
|
||
dynamic get value => _value; | ||
|
||
set value(dynamic changed) { | ||
if (_value == changed) { | ||
return; | ||
} | ||
|
||
_value = changed; | ||
|
||
_valueForSorting = null; | ||
} | ||
|
||
dynamic _valueForSorting; | ||
|
||
dynamic get valueForSorting { | ||
_valueForSorting ??= _getValueForSorting(); | ||
|
||
return _valueForSorting; | ||
} | ||
|
||
dynamic _getValueForSorting() { | ||
if (_valueForSorting != null) { | ||
return _valueForSorting; | ||
} | ||
|
||
assert(_column != null); | ||
|
||
if (_column.type.isText) { | ||
_valueForSorting = _value.toString(); | ||
} else if (_column.type.isNumber) { | ||
_valueForSorting = _value.runtimeType != num | ||
? num.tryParse(_value.toString()) ?? 0 | ||
: _value; | ||
} else if (_column.type.isDate) { | ||
PlutoColumnTypeDate dateColumn = _column.type; | ||
|
||
final dateFormat = intl.DateFormat(dateColumn.format); | ||
|
||
DateTime dateFormatValue; | ||
|
||
try { | ||
dateFormatValue = dateFormat.parse(_value); | ||
} catch (e) { | ||
dateFormatValue = _column.type.defaultValue; | ||
} | ||
|
||
_valueForSorting = dateFormatValue; | ||
} else { | ||
_valueForSorting = _value; | ||
} | ||
|
||
return _valueForSorting; | ||
} | ||
|
||
/// cell column | ||
PlutoColumn _column; | ||
|
||
void setColumn(PlutoColumn column) { | ||
_column = column; | ||
_valueForSorting = _getValueForSorting(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters