1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import 'dart:convert';
- import 'package:fis_common/logger/logger.dart';
- import 'package:flutter/services.dart';
- /// 应用参数(随编译引入)
- class AppParameters {
- static const _path = "assets/app_params.json";
- static late final AppParameterDataModel _data;
- static bool _hasLoaded = false;
- /// 数据内容
- static AppParameterDataModel get data => _data;
- /// 加载预置参数数据
- static Future<void> load() async {
- if (_hasLoaded) return;
- try {
- final dynamic jsonMap;
- final json = await rootBundle.loadString(_path, cache: false);
- jsonMap = jsonDecode(json);
- _data = AppParameterDataModel.fromJson(jsonMap);
- } catch (e) {
- logger.e("Load AppConfig error.", e);
- _data = AppParameterDataModel();
- }
- _hasLoaded = true;
- }
- }
- class AppParameterDataModel {
- // ignore: constant_identifier_names
- static const C_DEFAULT_GATEWAY =
- "https://platform.xinglinghui.com:9400"; // TODO:
- static const C_HOME_PAGE_URL = "http://192.168.6.80:8408"; // TODO:
- AppParameterDataModel({
- this.serverGateway = C_DEFAULT_GATEWAY,
- this.homePageUrl = C_HOME_PAGE_URL,
- });
- factory AppParameterDataModel.fromJson(Map<String, dynamic> map) {
- return AppParameterDataModel(
- serverGateway: map['server_gateway'] ?? C_DEFAULT_GATEWAY,
- homePageUrl: map['home_page_url'] ?? C_HOME_PAGE_URL,
- );
- }
- String serverGateway;
- String homePageUrl;
- }
|