cofounderella/lib/utils/helper.dart

55 lines
1.3 KiB
Dart
Raw Normal View History

2024-05-15 13:35:01 +02:00
import 'package:collection/collection.dart';
2024-05-18 00:24:10 +02:00
import 'package:flutter/material.dart';
2024-05-15 13:35:01 +02:00
///
/// Compare two lists by their content ignoring their elements order.
///
bool equalContent(List<dynamic> list1, List<dynamic> list2) {
return const DeepCollectionEquality.unordered().equals(list1, list2);
}
2024-05-25 13:56:45 +02:00
///
/// Creates a composite ID from the passed [ids].
/// In the format id(1)_id(n)
///
String getCompoundId(List<String> ids) {
2024-05-25 13:56:45 +02:00
ids.sort(); // sort to ensure the result is the same for any order of ids
return ids.join('_');
}
2024-05-21 14:01:44 +02:00
///
2024-05-25 13:56:45 +02:00
/// Get the [displayName] of our own Enumerations.
2024-05-21 14:01:44 +02:00
///
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;
}
2024-05-18 00:24:10 +02:00
///
/// 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'),
),
],
),
);
}