Skip to content

Commit

Permalink
docs(utils): document missing methods
Browse files Browse the repository at this point in the history
  • Loading branch information
albertms10 committed Nov 21, 2022
1 parent 57d7385 commit 376aa49
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/utils/color_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,29 @@ import 'dart:collection' show SplayTreeMap;
import 'package:cabin_booking/utils/num_extension.dart';
import 'package:flutter/material.dart';

/// Color extension.
extension ColorExtension on Color {
/// Returns a new threshold to color Map based on the number of [samples]
/// and up to the [highestValue] for the threshold.
///
/// An optional [minOpacity] value can be provided for the first opacity
/// value in the Map.
///
/// Throws an [ArgumentError] if [samples] is not greater than zero.
///
/// Example:
/// ```dart
/// const color = Colors.blue;
/// const thresholds = {
/// 1: Color(0x332196f3),
/// 4: Color(0x552196f3),
/// 8: Color(0xaa2196f3),
/// 12: Color(0xff2196f3),
/// };
/// assert(
/// color.opacityThresholds(highestValue: 12, samples: 3) == thresholds,
/// );
/// ```
Map<int, Color> opacityThresholds({
required int highestValue,
required int samples,
Expand Down
15 changes: 15 additions & 0 deletions lib/utils/map_extension.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
/// Map extension.
extension MapExtension<K, V> on Map<K, V> {
/// Returns a new [Map] filled with the result of [ifAbsent] for [keys] that
/// are not present in this [Map].
///
/// Unlike [Map.update], this method does not mutate this [Map].
///
/// Example:
/// ```dart
/// const map = <int, bool?>{1: true, 2: false};
/// final filled = map.fillEmptyKeyValues(
/// keys: const [0, 1, 2, 5],
/// ifAbsent: () => null,
/// );
/// assert(filled == const {0: null, 1: true, 2: false, 5: null});
/// ```
Map<K, V> fillEmptyKeyValues({
Iterable<K> keys = const [],
required V Function() ifAbsent,
Expand Down

0 comments on commit 376aa49

Please sign in to comment.