import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; /// /// Compare two lists by their content ignoring their elements order. /// bool equalContent(List list1, List list2) { return const DeepCollectionEquality.unordered().equals(list1, list2); } /// /// Creates a composite ID from the passed [ids]. /// In the format id(1)_id(n) /// String getCompoundId(List ids){ ids.sort(); // sort to ensure the result is the same for any order of ids return ids.join('_'); } /// /// Convert decimal coordinate to degrees minutes seconds (DMS). /// String convertDecimalToDMS(double decimalValue) { bool isNegative = decimalValue < 0; double absoluteValue = decimalValue.abs(); int degrees = absoluteValue.toInt(); double minutesDecimal = (absoluteValue - degrees) * 60; int minutes = minutesDecimal.toInt(); double secondsDecimal = (minutesDecimal - minutes) * 60; double seconds = double.parse(secondsDecimal.toStringAsFixed(2)); String direction = isNegative ? (decimalValue < 0 ? 'W' : 'S') : (decimalValue >= 0 ? (degrees != 0 ? 'N' : 'E') : ''); // return formatted string return '${degrees.abs()}° ${minutes.abs()}\' ${seconds.abs()}" $direction'; } /// /// Get the [displayName] of our own Enumerations. /// String getDisplayText(dynamic option) { // Check if the option is an enum and has a displayName property if (option is Enum) { final dynamicEnum = option as dynamic; if (dynamicEnum.displayName != null) { return dynamicEnum.displayName; } } // Fallback to default toString if not an enum return option.toString().split('.').last; } /// /// Show a simple message dialog /// void showMsg(BuildContext context, String title, String content) { showDialog( context: context, builder: (context) => AlertDialog( title: Text(title), content: Text(content), actions: [ TextButton( onPressed: () { Navigator.of(context).pop(); }, child: const Text('OK'), ), ], ), ); }