mirror of
https://github.com/flutter/samples.git
synced 2026-04-30 11:36:35 +00:00
[linting_tool] Add lint rules list (#856)
This commit is contained in:
committed by
GitHub
parent
3b65403631
commit
6bac1b9694
36
experimental/linting_tool/lib/model/rule.dart
Normal file
36
experimental/linting_tool/lib/model/rule.dart
Normal file
@@ -0,0 +1,36 @@
|
||||
// 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 'package:equatable/equatable.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'rule.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class Rule extends Equatable {
|
||||
final String name;
|
||||
final String description;
|
||||
final String group;
|
||||
final String maturity;
|
||||
final List<String> incompatible;
|
||||
final List<String> sets;
|
||||
final String details;
|
||||
|
||||
const Rule({
|
||||
required this.name,
|
||||
required this.description,
|
||||
required this.group,
|
||||
required this.maturity,
|
||||
required this.incompatible,
|
||||
required this.sets,
|
||||
required this.details,
|
||||
});
|
||||
|
||||
factory Rule.fromJson(Map<String, dynamic> json) => _$RuleFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$RuleToJson(this);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [name];
|
||||
}
|
||||
31
experimental/linting_tool/lib/model/rule.g.dart
Normal file
31
experimental/linting_tool/lib/model/rule.g.dart
Normal file
@@ -0,0 +1,31 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'rule.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Rule _$RuleFromJson(Map<String, dynamic> json) {
|
||||
return Rule(
|
||||
name: json['name'] as String,
|
||||
description: json['description'] as String,
|
||||
group: json['group'] as String,
|
||||
maturity: json['maturity'] as String,
|
||||
incompatible: (json['incompatible'] as List<dynamic>)
|
||||
.map((e) => e as String)
|
||||
.toList(),
|
||||
sets: (json['sets'] as List<dynamic>).map((e) => e as String).toList(),
|
||||
details: json['details'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$RuleToJson(Rule instance) => <String, dynamic>{
|
||||
'name': instance.name,
|
||||
'description': instance.description,
|
||||
'group': instance.group,
|
||||
'maturity': instance.maturity,
|
||||
'incompatible': instance.incompatible,
|
||||
'sets': instance.sets,
|
||||
'details': instance.details,
|
||||
};
|
||||
44
experimental/linting_tool/lib/model/rules_store.dart
Normal file
44
experimental/linting_tool/lib/model/rules_store.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:linting_tool/model/rule.dart';
|
||||
import 'package:linting_tool/repository/repository.dart';
|
||||
|
||||
class RuleStore extends ChangeNotifier {
|
||||
RuleStore() {
|
||||
fetchRules();
|
||||
}
|
||||
bool _isLoading = true;
|
||||
|
||||
bool get isLoading => _isLoading;
|
||||
|
||||
List<Rule> _rules = [];
|
||||
|
||||
List<Rule> get rules => _rules;
|
||||
|
||||
String? _error;
|
||||
|
||||
String? get error => _error;
|
||||
|
||||
Future<void> fetchRules() async {
|
||||
if (!_isLoading) _isLoading = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
var rules = await Repository().getRulesList();
|
||||
_rules = rules;
|
||||
} on SocketException catch (e) {
|
||||
log(e.toString());
|
||||
_error = 'Check internet connection.';
|
||||
} on Exception catch (e) {
|
||||
log(e.toString());
|
||||
}
|
||||
_isLoading = false;
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user