LCOV - code coverage report
Current view: top level - src/util - enum_helpers.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 3 3 100.0 %
Date: 2021-10-15 15:56:51 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:analyzer/dart/constant/value.dart';
       2             : 
       3             : /// gets the value of an Enum from a Dart Object
       4           1 : T? getEnumFromDartObject<T>(
       5             :   DartObject? obj,
       6             :   List<T> values,
       7             : ) {
       8             :   if (obj == null) {
       9             :     return null;
      10             :   }
      11             : 
      12           4 :   String getName(T format) => '$format'.split('.').last;
      13             : 
      14             :   T? enumValue;
      15             :   try {
      16           3 :     enumValue = values.firstWhere((v) => obj.getField(getName(v!)) != null);
      17             :   } catch (_) {
      18             :     // there was no enum value found
      19             :     // continue
      20             :   }
      21             : 
      22             :   return enumValue;
      23             : }

Generated by: LCOV version 1.15