-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextensions.dart
More file actions
97 lines (92 loc) · 3.39 KB
/
extensions.dart
File metadata and controls
97 lines (92 loc) · 3.39 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2022 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
// Add Google Fonts Package import
import 'package:google_fonts/google_fonts.dart';
extension TypographyUtils on BuildContext {
ThemeData get theme => Theme.of(this);
// TextTheme get textTheme => theme.textTheme; // Modify this line
TextTheme get textTheme =>
GoogleFonts.montserratTextTheme(theme.textTheme); // Modify this line
ColorScheme get colors => theme.colorScheme;
TextStyle? get displayLarge => textTheme.displayLarge?.copyWith(
color: colors.onSurface,
);
TextStyle? get displayMedium => textTheme.displayMedium?.copyWith(
color: colors.onSurface,
);
TextStyle? get displaySmall => textTheme.displaySmall?.copyWith(
color: colors.onSurface,
);
TextStyle? get headlineLarge => textTheme.headlineLarge?.copyWith(
color: colors.onSurface,
);
TextStyle? get headlineMedium => textTheme.headlineMedium?.copyWith(
color: colors.onSurface,
);
TextStyle? get headlineSmall => textTheme.headlineSmall?.copyWith(
color: colors.onSurface,
);
TextStyle? get titleLarge => textTheme.titleLarge?.copyWith(
color: colors.onSurface,
);
TextStyle? get titleMedium => textTheme.titleMedium?.copyWith(
color: colors.onSurface,
);
TextStyle? get titleSmall => textTheme.titleSmall?.copyWith(
color: colors.onSurface,
);
TextStyle? get labelLarge => textTheme.labelLarge?.copyWith(
color: colors.onSurface,
);
TextStyle? get labelMedium => textTheme.labelMedium?.copyWith(
color: colors.onSurface,
);
TextStyle? get labelSmall => textTheme.labelSmall?.copyWith(
color: colors.onSurface,
);
TextStyle? get bodyLarge => textTheme.bodyLarge?.copyWith(
color: colors.onSurface,
);
TextStyle? get bodyMedium => textTheme.bodyMedium?.copyWith(
color: colors.onSurface,
);
TextStyle? get bodySmall => textTheme.bodySmall?.copyWith(
color: colors.onSurface,
);
}
extension BreakpointUtils on BoxConstraints {
bool get isTablet => maxWidth > 730;
bool get isDesktop => maxWidth > 1200;
bool get isMobile => !isTablet && !isDesktop;
}
extension DurationString on String {
/// Assumes a string (roughly) of the format '\d{1,2}:\d{2}'
Duration toDuration() => switch (split(':')) {
[var minutes, var seconds] => Duration(
minutes: int.parse(minutes.trim()),
seconds: int.parse(seconds.trim()),
),
[var hours, var minutes, var seconds] => Duration(
hours: int.parse(hours.trim()),
minutes: int.parse(minutes.trim()),
seconds: int.parse(seconds.trim()),
),
_ => throw Exception('Invalid duration string: $this'),
};
}
extension HumanizedDuration on Duration {
String toHumanizedString() {
final seconds = '${inSeconds % 60}'.padLeft(2, '0');
String minutes = '${inMinutes % 60}';
if (inHours > 0 || inMinutes == 0) {
minutes = minutes.padLeft(2, '0');
}
String value = '$minutes:$seconds';
if (inHours > 0) {
value = '$inHours:$minutes:$seconds';
}
return value;
}
}