1. Import
This commit is contained in:
commit
cb4525a774
165 files changed
+14763
No files matched your search
@@ -0,0 +1,178 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../Tools/colored_safe_area.dart';
|
||||
|
||||
class Util {
|
||||
static Future<bool> preferencesContainsKey(String key) async {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
return prefs.containsKey(key);
|
||||
}
|
||||
|
||||
static void preferencesSaveString(String key, String value) async {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString(key, value);
|
||||
}
|
||||
|
||||
static Future<String?> preferencesGetString(
|
||||
String key, String? defaultValue) async {
|
||||
if (await preferencesContainsKey(key)) {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getString(key);
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
static void preferencesSaveInt(String key, int value) async {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt(key, value);
|
||||
}
|
||||
|
||||
static Future<int?> preferencesGetInt(String key, int? defaultValue) async {
|
||||
if (await preferencesContainsKey(key)) {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getInt(key);
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
static void preferencesSaveBool(String key, bool value) async {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(key, value);
|
||||
}
|
||||
|
||||
static Future<bool> preferencesGetBool(String key, bool defaultValue) async {
|
||||
if (await preferencesContainsKey(key)) {
|
||||
var prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getBool(key) as bool;
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
static Future<String> getAppUuid() async {
|
||||
var currentUuid = await preferencesGetString('uuid', null);
|
||||
|
||||
if (currentUuid == null) {
|
||||
currentUuid ??= const Uuid().v4();
|
||||
|
||||
preferencesSaveString("uuid", currentUuid);
|
||||
}
|
||||
|
||||
return currentUuid;
|
||||
}
|
||||
|
||||
static logInfo(String message) {
|
||||
if (kDebugMode) {
|
||||
print('Message: $message');
|
||||
}
|
||||
}
|
||||
|
||||
static logException(String message) {
|
||||
if (kDebugMode) {
|
||||
print('Exception: $message');
|
||||
}
|
||||
}
|
||||
|
||||
static int fastHash(String string) {
|
||||
var hash = 0xcbf29ce484222325;
|
||||
|
||||
var i = 0;
|
||||
while (i < string.length) {
|
||||
final codeUnit = string.codeUnitAt(i++);
|
||||
hash ^= codeUnit >> 8;
|
||||
hash *= 0x100000001b3;
|
||||
hash ^= codeUnit & 0xFF;
|
||||
hash *= 0x100000001b3;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
static Widget getWaitWidget(context) {
|
||||
return ColoredSafeArea(
|
||||
key: const Key('value'),
|
||||
child: Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
color: Colors.white,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static Future<Widget> fetchFutureIcon(icon) {
|
||||
return Future.delayed(const Duration(seconds: 0), () async {
|
||||
return icon;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Widget getDefaultButton(String text, Function() onPressed, {Image? image}) {
|
||||
return SizedBox(
|
||||
height: 60,
|
||||
child: Stack(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: SizedBox(
|
||||
height: 60,
|
||||
child: ElevatedButton(
|
||||
style: ButtonStyle(
|
||||
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
side: const BorderSide(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
backgroundColor: MaterialStateProperty.all<Color>(const Color.fromARGB(255, 220, 220, 220)),
|
||||
foregroundColor: MaterialStateProperty.all<Color>(Colors.black),
|
||||
),
|
||||
onPressed: () {
|
||||
onPressed();
|
||||
},
|
||||
child: Text(text)
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
left: 20,
|
||||
top: 15,
|
||||
child: Center(
|
||||
child: image
|
||||
)
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String mapTourMode(String mode)
|
||||
{
|
||||
var text = "";
|
||||
switch (mode)
|
||||
{
|
||||
case "pu":
|
||||
text += "/ Abholung";
|
||||
break;
|
||||
|
||||
case "del":
|
||||
text += "/ Auslieferung";
|
||||
break;
|
||||
|
||||
case "pudel":
|
||||
text += "/ Abholung/Auslieferung";
|
||||
break;
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
Reference in new issue
Block a user