1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00
Files
samples/experimental/linting_tool/lib/repository/api_provider.dart
Parker Lougheed 908e1cce83 Account for new generated rules.json location in linter tool (#1956)
In preparation for the linter moving to the SDK, the `rules.json` file
is no longer generated to its own location. The site-www version is
better guaranteed to be up to date and match the `stable` release of
Dart.
2023-07-21 19:49:25 -05:00

41 lines
1.3 KiB
Dart

// Copyright 2021 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:linting_tool/model/rule.dart';
import 'package:yaml/yaml.dart';
class APIProvider {
final http.Client httpClient;
APIProvider(this.httpClient);
Future<List<Rule>> getRulesList() async {
final response = await httpClient.get(Uri.parse(
'https://raw.githubusercontent.com/dart-lang/site-www/main/src/_data/linter_rules.json',
));
if (response.statusCode == 200) {
final data = json.decode(response.body) as List;
final rulesList = [
for (final item in data) Rule.fromJson(item as Map<String, dynamic>)
];
return rulesList;
} else {
throw Exception('Failed to load rules');
}
}
Future<YamlMap> getTemplateFile() async {
final response = await httpClient.get(Uri.parse(
'https://raw.githubusercontent.com/flutter/flutter/main/packages/flutter_tools/templates/app_shared/analysis_options.yaml.tmpl'));
if (response.statusCode == 200) {
return loadYaml(response.body) as YamlMap;
} else {
throw Exception('Failed to load template file');
}
}
}