添加一些工具类

main
zhuce 2024-03-09 14:28:23 +08:00
parent f5817af759
commit 988052630a
9 changed files with 424 additions and 15 deletions

View File

@ -15,6 +15,6 @@ class LoginApi {
"wx_unionid": unionid
};
var post = await xHttp.post("/v2/auth/get-access-token", data);
print(post);
// print(post);
}
}

81
lib/config/constant.dart Normal file
View File

@ -0,0 +1,81 @@
class Constant{
//
static const String testHost = "http://api.test.jjsos.cn/";
//线
static const String host = "http://api.jjsos.cn/";
//host
static const String pictureHost = "http://pic.jjsos.cn/";
//
static const String testWorkOrderUrl = "http://backend.test.jjsos.cn/old/elc-work-new-app?order_id=";
static const String workOrderUrl = "http://backend.jjsos.cn/old/elc-work-new-app?order_id=";
//线
static bool isOrderStar = false;
//
static bool isOpen = false;
//
static bool weberror=false;
//
static int heartbeatTime = 0;
static int onlineTime = 0;
//
static bool isService = false;
static bool isMain = false;
//
static bool hasMessage = false;
static bool hasMessageInform = false;
static const String WX_ID = "wx3bd407849a19c609";
static const String WX_Secret = "efb0ca67e9b2a58fb5b460b8b4153563";
//
static double lat = 0.00;
static double lng = 0.00;
static String address = "";
//退
static const String OUT_LOGIN_TOKEN = "OUT_LOGIN_TOKEN";
//
static const String ORDER_EMPTY_SIGN_TOKEN = "ORDER_EMPTY_SIGN_TOKEN";
// token
static const String ORDER_NEW_TOKEN = "ORDER_NEW_TOKEN";
//
static const String ORDER_CANCEL_TOKEN = "ORDER_CANCEL_TOKEN";
//
static const String ORDER_EMPTY_TOKEN = "ORDER_EMPTY_TOKEN";
//
static const String ORDER_REFRESH_TOKEN = "ORDER_REFRESH_TOKEN";
//
static const String ORDER_PAY_TOKEN = "ORDER_PAY_TOKEN";
//
static const String ORDER_COMPLETE_TOKEN = "ORDER_COMPLETE_TOKEN";
//token
//
static const int NEW_ORDER_INSIDE = 1;
//
static const int NEW_ORDER_JIUJIU = 2;
//
static const int ORDER_BACKSTAGE_CLOSE = 3;
//
static const int ORDER_BACKSTAGE_MODIFY = 4;
//
static const int ORDER_BACKSTAGE_CLOSE_CHARGE = 5;
//
static const int WHETHER_ARRIVE_SCENE = 6;
//线
static const int ENTERED_OFFLINE_MODE = 7;
//
static const int ORDER_WHETHER_CLOSE = 8;
//
static const int ORDER_COMPLETE = 9;
//app-
static String newVersion="4.1.3.9";
// 0=1=2=3= 4=() 5=()
static int NECUPDATE =0;
static bool isDriverMessage = false;
static bool isServiceTrailer = true;
static String arriveTipsStr = "";
static String uploadStartStr = "";
}

View File

@ -1,6 +1,7 @@
import 'package:autosos_flutter/pages/home/home_page.dart';
import 'package:autosos_flutter/pages/login/login_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
void main() {
runApp(const MyApp());
@ -13,11 +14,13 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const LoginPage());
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const LoginPage(),
builder: EasyLoading.init(),
);
}
}

View File

@ -1,7 +1,10 @@
import 'package:autosos_flutter/api/login_api.dart';
import 'package:autosos_flutter/util/xhttp.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@ -10,6 +13,8 @@ class LoginPage extends StatefulWidget {
}
class _LoginPageState extends State<LoginPage> {
final TextEditingController _unameController = TextEditingController();
final TextEditingController _pwdController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
@ -49,20 +54,22 @@ class _LoginPageState extends State<LoginPage> {
color: Colors.grey,
),
),
const Expanded(
Expanded(
child: TextField(
decoration: InputDecoration(hintText: "请输入手机号"),
controller: _unameController,
decoration: const InputDecoration(hintText: "请输入手机号"),
)),
],
),
),
const Padding(
padding: EdgeInsets.all(20),
Padding(
padding: const EdgeInsets.all(20),
child: Row(
children: [
Expanded(
child: TextField(
decoration: InputDecoration(hintText: "请输入密码"),
controller: _pwdController,
decoration: const InputDecoration(hintText: "请输入密码"),
))
],
),
@ -93,6 +100,8 @@ class _LoginPageState extends State<LoginPage> {
}
void _login() async{
String username = _unameController.text;
String password = _pwdController.text;
LoginApi.login(1, username, password, "", "", "", "");
}
}

View File

@ -0,0 +1,15 @@
import 'package:autosos_flutter/util/sp_util.dart';
import 'package:basic_utils/basic_utils.dart';
import 'package:uuid/uuid.dart';
class DeviceIdUtils{
static String? getDeviceId(){
SPUtil spUtil = SPUtil();
var deviceId = spUtil.get<String>("JJdeviceId");
if(StringUtils.isNullOrEmpty(deviceId)){
var uuid = const Uuid();
return uuid.v1();
}
return deviceId;
}
}

85
lib/util/sp_util.dart Normal file
View File

@ -0,0 +1,85 @@
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
class SPUtil{
//
static SPUtil? _instance;
factory SPUtil() => _instance ??= SPUtil._initial();
SharedPreferences? _preferences;
//
SPUtil._initial() {
//init 使async/await
init();
}
//SharedPreferences
void init() async {
_preferences ??= await SharedPreferences.getInstance();
}
// 使 SharedPreferences ,static
static Future<SPUtil?> perInit() async {
if (_instance == null) {
//访
SharedPreferences preferences = await SharedPreferences.getInstance();
_instance = SPUtil._pre(preferences);
}
return _instance;
}
SPUtil._pre(SharedPreferences prefs) {
_preferences = prefs;
}
///String
void setString(key, value) {
_preferences?.setString(key, value);
}
///setStringList
void setStringList(key, value) {
_preferences?.setStringList(key, value);
}
///setBool
void setBool(key, value) {
_preferences?.setBool(key, value);
}
///setDouble
void setDouble(key, value) {
_preferences?.setDouble(key, value);
}
///setInt
void setInt(key, value) {
_preferences?.setInt(key, value);
}
///Json
void setJson(key, value) {
value = jsonEncode(value);
_preferences?.setString(key, value);
}
///
T? get<T>(key) {
var result = _preferences?.get(key);
if (result != null) {
return result as T;
}
return null;
}
///JSON
Map<String, dynamic>? getJson(key) {
String? result = _preferences?.getString(key);
if (result!=null && result!='') {
return jsonDecode(result);
}
return null;
}
///StringUtilisNotEmpty
/// static isNotEmpty(String? str) {
/// return str?.isNotEmpty ?? false;
/// }
///
void clean() {
_preferences?.clear();
}
///
void remove(key) {
_preferences?.remove(key);
}
}

View File

@ -41,7 +41,7 @@ class XHttp {
static Dio dio = Dio();
// static Dio dio;
String _getBaseUrl() => 'https:xxx/';
String _getBaseUrl() => 'http://api.test.jjsos.cn';
/// 使
XHttp._internal() {
if ('' == dio.options.baseUrl) {

View File

@ -33,6 +33,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.11.0"
basic_utils:
dependency: "direct main"
description:
name: basic_utils
sha256: "2064b21d3c41ed7654bc82cc476fd65542e04d60059b74d5eed490a4da08fc6c"
url: "https://pub.flutter-io.cn"
source: hosted
version: "5.7.0"
boolean_selector:
dependency: transitive
description:
@ -65,6 +73,22 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.18.0"
convert:
dependency: transitive
description:
name: convert
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.1.1"
crypto:
dependency: transitive
description:
name: crypto
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.3"
cupertino_icons:
dependency: "direct main"
description:
@ -89,6 +113,30 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.1"
ffi:
dependency: transitive
description:
name: ffi
sha256: "7bf0adc28a23d395f19f3f1eb21dd7cfd1dd9f8e1c50051c069122e6853bc878"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
file:
dependency: transitive
description:
name: file
sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
url: "https://pub.flutter-io.cn"
source: hosted
version: "7.0.0"
fixnum:
dependency: transitive
description:
name: fixnum
sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.0"
flutter:
dependency: "direct main"
description: flutter
@ -131,6 +179,19 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
http:
dependency: transitive
description:
name: http
sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
http_parser:
dependency: transitive
description:
@ -139,6 +200,22 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.2"
js:
dependency: transitive
description:
name: js
sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.7.1"
json_annotation:
dependency: transitive
description:
name: json_annotation
sha256: b10a7b2ff83d83c777edba3c6a0f97045ddadd56c944e1a23a3fdf43a1bf4467
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.8.1"
lints:
dependency: transitive
description:
@ -147,6 +224,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.1"
logging:
dependency: transitive
description:
name: logging
sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.0"
matcher:
dependency: transitive
description:
@ -179,6 +264,38 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.8.3"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.1"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.2"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.1"
platform:
dependency: transitive
description:
name: platform
sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.1.4"
plugin_platform_interface:
dependency: transitive
description:
@ -187,6 +304,70 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.8"
pointycastle:
dependency: transitive
description:
name: pointycastle
sha256: "43ac87de6e10afabc85c445745a7b799e04de84cebaa4fd7bf55a5e1e9604d29"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.7.4"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
sha256: "81429e4481e1ccfb51ede496e916348668fd0921627779233bd24cc3ff6abd02"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.2"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
sha256: "8568a389334b6e83415b6aae55378e158fbc2314e074983362d20c562780fb06"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.1"
shared_preferences_foundation:
dependency: transitive
description:
name: shared_preferences_foundation
sha256: "7708d83064f38060c7b39db12aefe449cb8cdc031d6062280087bc4cdb988f5c"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.3.5"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
sha256: "9f2cbcf46d4270ea8be39fa156d86379077c8a5228d9dfdb1164ae0bb93f1faa"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.3.2"
shared_preferences_platform_interface:
dependency: transitive
description:
name: shared_preferences_platform_interface
sha256: "22e2ecac9419b4246d7c22bfbbda589e3acf5c0351137d87dd2939d984d37c3b"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.3.2"
shared_preferences_web:
dependency: transitive
description:
name: shared_preferences_web
sha256: "7b15ffb9387ea3e237bb7a66b8a23d2147663d391cafc5c8f37b2e7b4bde5d21"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.2"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
sha256: "841ad54f3c8381c480d0c9b508b89a34036f512482c407e6df7a9c4aa2ef8f59"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.3.2"
sky_engine:
dependency: transitive
description: flutter
@ -200,6 +381,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.10.0"
sprintf:
dependency: transitive
description:
name: sprintf
sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23"
url: "https://pub.flutter-io.cn"
source: hosted
version: "7.0.0"
stack_trace:
dependency: transitive
description:
@ -256,6 +445,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.3.2"
uuid:
dependency: "direct main"
description:
name: uuid
sha256: cd210a09f7c18cbe5a02511718e0334de6559871052c90a90c0cca46a4aa81c8
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.3.3"
vector_math:
dependency: transitive
description:
@ -272,6 +469,22 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.3.0"
win32:
dependency: transitive
description:
name: win32
sha256: "464f5674532865248444b4c3daca12bd9bf2d7c47f759ce2617986e7229494a8"
url: "https://pub.flutter-io.cn"
source: hosted
version: "5.2.0"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.4"
sdks:
dart: ">=3.2.6 <4.0.0"
flutter: ">=3.7.0"
flutter: ">=3.16.0"

View File

@ -35,6 +35,9 @@ dependencies:
amap_flutter_map: ^3.0.0
dio: ^5.4.1
flutter_easyloading: ^3.0.5
shared_preferences: ^2.2.2
basic_utils: ^5.7.0
uuid: ^4.3.3
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.