1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 22:09:06 +00:00

Some linting_tool updates and cleanup (#1279)

This commit is contained in:
Parker Lougheed
2022-05-22 23:48:16 -05:00
committed by GitHub
parent 50863c5b63
commit d6296157f4
24 changed files with 187 additions and 196 deletions

View File

@@ -8,8 +8,10 @@ import 'package:linting_tool/model/rule.dart';
import 'package:yaml/yaml.dart';
class APIProvider {
final _baseURL = 'https://dart-lang.github.io/linter';
static const String _baseURL = 'https://dart-lang.github.io/linter';
final http.Client httpClient;
APIProvider(this.httpClient);
Future<List<Rule>> getRulesList() async {
@@ -17,11 +19,10 @@ class APIProvider {
await httpClient.get(Uri.parse('$_baseURL//lints/machine/rules.json'));
if (response.statusCode == 200) {
List<Rule> rulesList = [];
final data = json.decode(response.body) as List;
for (var item in data) {
rulesList.add(Rule.fromJson(item as Map<String, dynamic>));
}
final rulesList = [
for (final item in data) Rule.fromJson(item as Map<String, dynamic>)
];
return rulesList;
} else {
throw Exception('Failed to load rules');

View File

@@ -10,7 +10,7 @@ class HiveService {
boxName,
);
List<T> existingProducts = await getBoxes(boxName);
final List<T> existingProducts = await getBoxes(boxName);
if (!existingProducts.contains(item)) {
await openBox.add(item);
@@ -24,9 +24,9 @@ class HiveService {
boxName,
);
List<T> existingProducts = await getBoxes(boxName);
final Set<T> existingProducts = Set.unmodifiable(await getBoxes(boxName));
for (var item in items) {
for (final item in items) {
if (!existingProducts.contains(item)) {
await openBox.add(item);
}
@@ -38,9 +38,9 @@ class HiveService {
boxName,
);
List<T> boxes = await getBoxes(boxName);
final List<T> boxes = await getBoxes(boxName);
for (var box in boxes) {
for (final box in boxes) {
if (box == item) {
await openBox.deleteAt(boxes.indexOf(item));
}
@@ -52,9 +52,9 @@ class HiveService {
boxName,
);
List<T> boxes = await getBoxes(boxName);
final List<T> boxes = await getBoxes(boxName);
for (var box in boxes) {
for (final box in boxes) {
if (box == item) {
await openBox.putAt(boxes.indexOf(item), newItem);
}
@@ -62,15 +62,13 @@ class HiveService {
}
static Future<List<T>> getBoxes<T>(String boxName, [String? query]) async {
List<T> boxList = [];
final openBox = await Hive.openLazyBox<T>(boxName);
int length = openBox.length;
final length = openBox.length;
for (int i = 0; i < length; i++) {
boxList.add(await openBox.getAt(i) as T);
}
final boxList = <T>[
for (int i = 0; i < length; i++) await openBox.getAt(i) as T
];
return boxList;
}

View File

@@ -8,11 +8,9 @@ import 'package:linting_tool/repository/api_provider.dart';
import 'package:yaml/yaml.dart';
class Repository {
late final APIProvider _apiProvider;
final APIProvider _apiProvider;
Repository(http.Client httpClient) {
_apiProvider = APIProvider(httpClient);
}
Repository(http.Client httpClient) : _apiProvider = APIProvider(httpClient);
Future<List<Rule>> getRulesList() => _apiProvider.getRulesList();