-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeneral_lib_flutter_core.dart
executable file
·198 lines (165 loc) · 5.2 KB
/
general_lib_flutter_core.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// ignore_for_file: empty_catches
/* <!-- START LICENSE -->
This Software / Program / Source Code Created By Developer From Company GLOBAL CORPORATION
Social Media:
- Youtube: https://youtube.com/@Global_Corporation
- Github: https://github.com/globalcorporation
- TELEGRAM: https://t.me/GLOBAL_CORP_ORG_BOT
All code script in here created 100% original without copy / steal from other code if we copy we add description source at from top code
If you wan't edit you must add credit me (don't change)
If this Software / Program / Source Code has you
Jika Program ini milik anda dari hasil beli jasa developer di (Global Corporation / apapun itu dari turunan itu jika ada kesalahan / bug / ingin update segera lapor ke sub)
Misal anda beli Beli source code di Slebew CORPORATION anda lapor dahulu di slebew jangan lapor di GLOBAL CORPORATION!
Jika ada kendala program ini (Pastikan sebelum deal project tidak ada negosiasi harga)
Karena jika ada negosiasi harga kemungkinan
1. Software Ada yang di kurangin
2. Informasi tidak lengkap
3. Bantuan Tidak Bisa remote / full time (Ada jeda)
Sebelum program ini sampai ke pembeli developer kami sudah melakukan testing
jadi sebelum nego kami sudah melakukan berbagai konsekuensi jika nego tidak sesuai ?
Bukan maksud kami menipu itu karena harga yang sudah di kalkulasi + bantuan tiba tiba di potong akhirnya bantuan / software kadang tidak lengkap
<!-- END LICENSE --> */
import 'dart:async';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:general_lib_flutter/extension/build_context.dart';
/// GeneralLibraryFlutter
class MyScrollBehavior extends MaterialScrollBehavior {
/// GeneralLibraryFlutter
@override
Set<PointerDeviceKind> get dragDevices {
return {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
PointerDeviceKind.trackpad,
PointerDeviceKind.stylus,
PointerDeviceKind.invertedStylus,
};
}
}
/// GeneralLibraryFlutter
class GeneralLibFlutter {
/// GeneralLibraryFlutter
const GeneralLibFlutter();
/// GeneralLibraryFlutter
static void ensureInitialized() {
WidgetsFlutterBinding.ensureInitialized();
}
/// GeneralLibraryFlutter
static BorderRadius borderRadiusBubbleChatMessage({
required bool isOutGoing,
double borderMax = 15,
required int index,
required int totalCount,
}) {
bool isFirstIndex = index == 0;
bool isLastIndex = index == totalCount - 1;
// detek first
if (isFirstIndex) {
if (isOutGoing) {
return BorderRadius.only(
topLeft: Radius.circular(borderMax),
bottomLeft: Radius.circular(borderMax),
bottomRight: Radius.circular(borderMax),
);
} else {
return BorderRadius.only(
topRight: Radius.circular(borderMax),
bottomLeft: Radius.circular(borderMax),
bottomRight: Radius.circular(borderMax),
);
}
} else if (isLastIndex) {
if (isOutGoing) {
return BorderRadius.only(
topRight: Radius.circular(borderMax),
bottomLeft: Radius.circular(borderMax),
topLeft: Radius.circular(borderMax),
);
} else {
return BorderRadius.only(
topRight: Radius.circular(borderMax),
topLeft: Radius.circular(borderMax),
bottomRight: Radius.circular(borderMax),
);
}
}
return BorderRadius.circular(borderMax);
}
}
/// GeneralLibraryFlutter
void assertAsync({
required FutureOr<dynamic> Function() function,
}) {
assert(() {
Future(function);
return true;
}());
}
/// GeneralLibraryFlutter
void assertSync({
required dynamic Function() function,
}) {
assert(() {
function();
return true;
}());
}
/// GeneralLibraryFlutter
mixin GeneralLibFlutterStatefulWidget<T extends StatefulWidget> on State<T> {
/// GeneralLibraryFlutter
final GlobalKey appBarGlobalKey = GlobalKey();
/// GeneralLibraryFlutter
final GlobalKey bottomBarGlobalKey = GlobalKey();
/// GeneralLibraryFlutter
final GlobalKey floatingBarGlobalKey = GlobalKey();
/// GeneralLibraryFlutter
bool isCanPop = false;
/// GeneralLibraryFlutter
bool _isEnsureInitialized = false;
/// GeneralLibraryFlutter
void ensureInitialized() {
if (_isEnsureInitialized) {
return;
}
isCanPop = context.navigator().canPop();
_isEnsureInitialized = true;
}
/// GeneralLibraryFlutter
bool isLoading = false;
/// GeneralLibraryFlutter
Future<void> refresh();
/// GeneralLibraryFlutter
Future<void> refreshState({
required FutureOr<dynamic> Function() onRefresh,
FutureOr<dynamic> Function(Object e, StackTrace stackTrace)? onError,
bool isThrowOnError = true,
}) async {
if (isLoading) {
return;
}
setState(() {
isLoading = true;
});
await Future(() async {
try {
await onRefresh();
} catch (e, stack) {
if (isThrowOnError) {
rethrow;
}
// ignore: non_constant_identifier_names
final on_error = onError;
if (on_error != null) {
try {
await on_error(e, stack);
} catch (e) {}
return;
}
}
});
setState(() {
isLoading = false;
});
}
}