Add action to pull services json
This commit is contained in:
parent
56879f6c14
commit
c0eef32f56
3 changed files with 31 additions and 1 deletions
|
@ -1,6 +1,18 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:zontreck/Settings.dart';
|
||||
|
||||
class Constants {
|
||||
static const TITLEBAR_COLOR = Color.fromARGB(255, 97, 0, 0);
|
||||
static const DRAWER_COLOR = Color.fromARGB(148, 0, 97, 97);
|
||||
|
||||
static const SERVICES_JSON =
|
||||
"https://raw.githubusercontent.com/AriasCreations/AriasCreations/main/services.json";
|
||||
|
||||
static Future<Map<String, dynamic>> pullServicesJson() async {
|
||||
Settings settings = Settings();
|
||||
var reply = await settings.dio.get(SERVICES_JSON);
|
||||
return json.decode(reply.data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
import 'package:dio/dio.dart';
|
||||
import 'package:libac_flutter/nbt/impl/CompoundTag.dart';
|
||||
|
||||
class Settings {
|
||||
static Settings? _inst = null;
|
||||
Settings._() {}
|
||||
|
||||
Dio dio = Dio();
|
||||
|
||||
factory Settings() {
|
||||
if (Settings._inst != null)
|
||||
return Settings._inst!;
|
||||
|
@ -20,4 +23,14 @@ class Settings {
|
|||
|
||||
return tag;
|
||||
}
|
||||
|
||||
String API_SERVER = "";
|
||||
|
||||
void setServices(Map<String, dynamic> js) {
|
||||
var protocol = js['api']['protocol'] as String;
|
||||
var port = js['api']['port'] as int;
|
||||
var host = js['api']['host'] as String;
|
||||
|
||||
API_SERVER = "${protocol}://${host}:${port}/";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:zontreck/Constants.dart';
|
||||
import 'package:zontreck/Settings.dart';
|
||||
import 'package:zontreck/pages/Main.dart';
|
||||
|
||||
void main() {
|
||||
void main() async {
|
||||
Settings settings = Settings();
|
||||
var services = await Constants.pullServicesJson();
|
||||
settings.setServices(services);
|
||||
runApp(new MainPage());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue