Skip to content

Instantly share code, notes, and snippets.

@masterwok
Created December 15, 2021 05:09
Show Gist options
  • Save masterwok/ffdf25c1c5d5f9115ad89d2638929d50 to your computer and use it in GitHub Desktop.
Save masterwok/ffdf25c1c5d5f9115ad89d2638929d50 to your computer and use it in GitHub Desktop.
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