import 'dart:collection'; import 'package:flutter/material.dart'; const designWidth = 360; Size screenSize = const Size(360, 690); extension IterableExtension on Iterable { E? getOrNull(int index) { if (index >= 0 && index < length) { return elementAt(index); } return null; } Queue toQueue() { return Queue.from(this); } } extension ListExtention on List { E? get firstOrNull { Iterator it = iterator; if (!it.moveNext()) { return null; } return it.current; } E? getAllowOverflow(int index) { if (index >= length) { return null; } return this[index]; } E? firstOrNullWhere(bool test(E element)) { for (E element in this) { if (test(element)) return element; } return null; } } extension MapExtention on Map { dynamic get(dynamic key) { return this[key]; } } extension ScopeFunc on T { R let(R Function(T it) op) => op(this); T also(void Function(T it) op) { op(this); return this; } } extension DoubleGap on double { SizedBox get gapColumn => SizedBox(height: this); SizedBox get gapRow => SizedBox(width: this); double get dp => this * screenSize.width / designWidth; } extension IntGap on int { SizedBox get gapColumn => SizedBox(height: toDouble()); Widget gapColumnWithBg(Color color) => Container(color: color, height: toDouble()); SizedBox get gapRow => SizedBox(width: toDouble()); double get dp => this * screenSize.width / designWidth; } extension Localization on String { Text toText({ double? size, Color? color, FontWeight weight = FontWeight.w400, double? lineHeight, TextStyle? style, }) { size ??= 16.dp; style ??= TextStyle(fontWeight: weight, fontSize: size, color: color); if (lineHeight != null) { style = style.copyWith(height: lineHeight / size); } return Text(this, style: style); } }