LCOV - code coverage report
Current view: top level - lib/model/grid - grid_row.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 21 21 100.0 %
Date: 2021-10-19 14:11:19 Functions: 0 0 -

          Line data    Source code
       1             : part of apptive_grid_model;
       2             : 
       3             : /// Model for a Row in a Grid
       4             : class GridRow {
       5             :   /// Creates a GridRow
       6           5 :   GridRow(this.id, this.entries);
       7             : 
       8             :   /// Creates a GridRow from [json]
       9             :   ///
      10             :   /// [fields] is used to map the correct type of [entries]
      11           5 :   factory GridRow.fromJson(
      12             :     dynamic json,
      13             :     List<GridField> fields,
      14             :     dynamic schema,
      15             :   ) {
      16           5 :     final data = json['fields'] as List;
      17           5 :     final entries = List<GridEntry>.generate(
      18           5 :       data.length,
      19          10 :       (i) => GridEntry.fromJson(
      20           5 :         data[i],
      21           5 :         fields[i],
      22          20 :         schema['properties']['fields']['items'][i],
      23             :       ),
      24             :     );
      25          10 :     return GridRow(json['_id'], entries);
      26             :   }
      27             : 
      28             :   /// id of the row
      29             :   final String id;
      30             : 
      31             :   /// List of entries
      32             :   final List<GridEntry> entries;
      33             : 
      34             :   /// Serializes a row to a Map
      35             :   ///
      36             :   /// in the format used by the Server for [GridData.fromJson] and [GridData.toJson]
      37           6 :   Map<String, dynamic> toJson() => {
      38           3 :         '_id': id,
      39          18 :         'fields': entries.map((e) => e.data.schemaValue).toList(),
      40             :       };
      41             : 
      42           2 :   @override
      43             :   String toString() {
      44           6 :     return 'GridRow(id: $id, entries: $entries)';
      45             :   }
      46             : 
      47           2 :   @override
      48             :   bool operator ==(Object other) {
      49           2 :     return other is GridRow &&
      50           6 :         id == other.id &&
      51           6 :         f.listEquals(entries, other.entries);
      52             :   }
      53             : 
      54           1 :   @override
      55           2 :   int get hashCode => toString().hashCode;
      56             : }

Generated by: LCOV version 1.15