mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
Implements default lints page (#871)
This commit is contained in:
committed by
GitHub
parent
a68f3f57d6
commit
bd4fa28584
@@ -6,6 +6,7 @@ import 'dart:developer';
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:linting_tool/model/profile.dart';
|
||||||
import 'package:linting_tool/model/rule.dart';
|
import 'package:linting_tool/model/rule.dart';
|
||||||
import 'package:linting_tool/repository/repository.dart';
|
import 'package:linting_tool/repository/repository.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
@@ -29,6 +30,27 @@ class RuleStore extends ChangeNotifier {
|
|||||||
|
|
||||||
String? get error => _error;
|
String? get error => _error;
|
||||||
|
|
||||||
|
List<RulesProfile> get defaultProfiles {
|
||||||
|
List<RulesProfile> _defaultProfiles = [];
|
||||||
|
|
||||||
|
var rulesWithDefaultSets =
|
||||||
|
rules.where((rule) => rule.sets.isNotEmpty).toList();
|
||||||
|
|
||||||
|
for (final rule in rulesWithDefaultSets) {
|
||||||
|
for (final setName in rule.sets) {
|
||||||
|
var profileIndex =
|
||||||
|
_defaultProfiles.indexWhere((profile) => profile.name == setName);
|
||||||
|
if (profileIndex >= 0) {
|
||||||
|
_defaultProfiles[profileIndex].rules.add(rule);
|
||||||
|
} else {
|
||||||
|
_defaultProfiles.add(RulesProfile(name: setName, rules: [rule]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _defaultProfiles;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> fetchRules() async {
|
Future<void> fetchRules() async {
|
||||||
if (!_isLoading) _isLoading = true;
|
if (!_isLoading) _isLoading = true;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|||||||
@@ -3,13 +3,82 @@
|
|||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:linting_tool/layout/adaptive.dart';
|
||||||
|
import 'package:linting_tool/model/rules_store.dart';
|
||||||
|
import 'package:linting_tool/pages/rules_page.dart';
|
||||||
|
import 'package:linting_tool/theme/colors.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class DefaultLintsPage extends StatelessWidget {
|
class DefaultLintsPage extends StatelessWidget {
|
||||||
const DefaultLintsPage({Key? key}) : super(key: key);
|
const DefaultLintsPage({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// TODO(abd99): Implement DefaultLintsPage, showing a list of default lint rules.
|
return Consumer<RuleStore>(
|
||||||
return const Text('Default Profiles');
|
builder: (context, rulesStore, child) {
|
||||||
|
if (rulesStore.isLoading) {
|
||||||
|
return const CircularProgressIndicator.adaptive();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rulesStore.defaultProfiles.isNotEmpty) {
|
||||||
|
var defaultSets = rulesStore.defaultProfiles;
|
||||||
|
final isDesktop = isDisplayLarge(context);
|
||||||
|
final isTablet = isDisplayMedium(context);
|
||||||
|
final startPadding = isTablet
|
||||||
|
? 60.0
|
||||||
|
: isDesktop
|
||||||
|
? 120.0
|
||||||
|
: 4.0;
|
||||||
|
final endPadding = isTablet
|
||||||
|
? 60.0
|
||||||
|
: isDesktop
|
||||||
|
? 120.0
|
||||||
|
: 4.0;
|
||||||
|
|
||||||
|
return ListView.separated(
|
||||||
|
padding: EdgeInsetsDirectional.only(
|
||||||
|
start: startPadding,
|
||||||
|
end: endPadding,
|
||||||
|
top: isDesktop ? 28 : 0,
|
||||||
|
bottom: isDesktop ? kToolbarHeight : 0,
|
||||||
|
),
|
||||||
|
cacheExtent: 5,
|
||||||
|
itemCount: defaultSets.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
var profile = rulesStore.defaultProfiles[index];
|
||||||
|
return ListTile(
|
||||||
|
title: Text(
|
||||||
|
profile.name,
|
||||||
|
),
|
||||||
|
tileColor: AppColors.white50,
|
||||||
|
onTap: () {
|
||||||
|
Navigator.push<void>(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => RulesPage(profile: profile),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
separatorBuilder: (context, index) => const SizedBox(height: 4),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(rulesStore.error ?? 'Failed to load rules.'),
|
||||||
|
const SizedBox(
|
||||||
|
height: 16.0,
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () => rulesStore.fetchRules(),
|
||||||
|
icon: const Icon(Icons.refresh),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user