Created
December 15, 2021 05:09
-
-
Save masterwok/ffdf25c1c5d5f9115ad89d2638929d50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:json_annotation/json_annotation.dart'; | |
import 'proxy_config.dart'; | |
import 'package:flutter/services.dart' show rootBundle; | |
import "package:yaml/yaml.dart"; | |
import 'dart:convert'; | |
part 'config.g.dart'; | |
@JsonSerializable() | |
class Config { | |
final ProxyConfig proxy; | |
Config(this.proxy); | |
factory Config.fromJson(Map<String, dynamic> json) => _$ConfigFromJson(json); | |
Map<String, dynamic> toJson() => _$ConfigToJson(this); | |
/// Create a new [Config] instance using a file located at [path]. | |
static Future<Config> from(String path) async { | |
final yamlString = await rootBundle.loadString(path); | |
final yaml = loadYaml(yamlString); | |
final decoded = json.decode(json.encode(yaml)); | |
return Config.fromJson(decoded); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment