LCOV - code coverage report
Current view: top level - lib/model/form - form_data.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 35 35 100.0 %
Date: 2021-09-29 11:41:23 Functions: 0 0 -

          Line data    Source code
       1             : part of apptive_grid_model;
       2             : 
       3             : /// Model for FormData
       4             : class FormData {
       5             :   /// Creates a FormData Object
       6           3 :   FormData({
       7             :     this.name,
       8             :     required this.title,
       9             :     required this.components,
      10             :     this.actions = const [],
      11             :     required this.schema,
      12             :   });
      13             : 
      14             :   /// Deserializes [json] into a FormData Object
      15           4 :   FormData.fromJson(Map<String, dynamic> json)
      16           4 :       : name = json['name'],
      17           4 :         title = json['title'],
      18           4 :         components = (json['components'] as List)
      19           4 :             .map<FormComponent>(
      20          12 :               (e) => FormComponent.fromJson(e, json['schema']),
      21             :             )
      22           4 :             .toList(),
      23           4 :         actions = json['actions'] != null
      24           2 :             ? (json['actions'] as List)
      25           6 :                 .map((e) => FormAction.fromJson(e))
      26           2 :                 .toList()
      27           3 :             : [],
      28           4 :         schema = json['schema'];
      29             : 
      30             :   /// Name of the Form
      31             :   final String? name;
      32             : 
      33             :   /// Title of the Form
      34             :   final String title;
      35             : 
      36             :   /// List of [FormComponent] represented in the Form
      37             :   final List<FormComponent> components;
      38             : 
      39             :   /// List of [FormActions] available for this Form
      40             :   final List<FormAction> actions;
      41             : 
      42             :   /// Schema used to deserialize [components] and verify data send back to the server
      43             :   final dynamic schema;
      44             : 
      45             :   /// Serializes [FormData] to json
      46           6 :   Map<String, dynamic> toJson() => {
      47           3 :         'name': name,
      48           3 :         'title': title,
      49          11 :         'components': components.map((e) => e.toJson()).toList(),
      50          11 :         'actions': actions.map((e) => e.toJson()).toList(),
      51           3 :         'schema': schema,
      52             :       };
      53             : 
      54           3 :   @override
      55             :   String toString() {
      56           6 :     return 'FormData(${toJson()})';
      57             :   }
      58             : 
      59             :   /// Creates a [Map] used to send this data back to a server
      60           2 :   Map<String, dynamic> toRequestObject() {
      61           2 :     return Map.fromEntries(
      62           6 :       components.map((component) {
      63           8 :         return MapEntry(component.fieldId, component.data.schemaValue);
      64             :       }),
      65             :     );
      66             :   }
      67             : 
      68           3 :   @override
      69             :   bool operator ==(Object other) {
      70           3 :     return other is FormData &&
      71           9 :         name == other.name &&
      72           9 :         title == other.title &&
      73           9 :         schema == other.schema &&
      74           9 :         f.listEquals(actions, other.actions) &&
      75           9 :         f.listEquals(components, other.components);
      76             :   }
      77             : 
      78           1 :   @override
      79           2 :   int get hashCode => toString().hashCode;
      80             : }

Generated by: LCOV version 1.15