-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.dart
43 lines (36 loc) · 1.27 KB
/
extension.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import 'package:flutter/material.dart';
import 'router.dart';
import 'size_config.dart';
extension SizeExtension on num {
SizedBox get hBox => SizedBox(height: toDouble());
SizedBox get wBox => SizedBox(width: toDouble());
///
double get h => SizeConfig.getHeight(toDouble());
double get w => SizeConfig.getWidth(toDouble());
double get sp => SizeConfig.getTextSize(toDouble());
}
extension MediaQueryExtension on BuildContext {
double get height => MediaQuery.of(this).size.height;
double get width => MediaQuery.of(this).size.width;
}
extension StringExtension on String {
String get capitalize => isNotEmpty ? this[0].toUpperCase() + substring(1) : this;
}
extension HexString on String {
int toHex() => int.parse(replaceAll('#', '0xff'));
}
extension DurationExtensions on Duration {
String toHoursMinutes() {
String twoDigitMinutes = _toTwoDigits(inMinutes.remainder(60));
return "${_toTwoDigits(inHours)}:$twoDigitMinutes";
}
String toHoursMinutesSeconds() {
String twoDigitMinutes = _toTwoDigits(inMinutes.remainder(60));
String twoDigitSeconds = _toTwoDigits(inSeconds.remainder(60));
return "${_toTwoDigits(inHours)}:$twoDigitMinutes:$twoDigitSeconds";
}
String _toTwoDigits(int n) {
if (n >= 10) return "$n";
return "0$n";
}
}