Skip to content
This repository was archived by the owner on Nov 28, 2024. It is now read-only.

Commit fabf745

Browse files
Add rows lint
1 parent b23fcb8 commit fabf745

12 files changed

+130
-142
lines changed

analysis_options.yaml

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
include: package:flutter_lints/flutter.yaml
2-
3-
# Additional information about this file can be found at
4-
# https://dart.dev/guides/language/analysis-options
1+
include: package:rows_lint/analysis_options.yaml

example/analysis_options.yaml

+1-29
Original file line numberDiff line numberDiff line change
@@ -1,29 +1 @@
1-
# This file configures the analyzer, which statically analyzes Dart code to
2-
# check for errors, warnings, and lints.
3-
#
4-
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5-
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6-
# invoked from the command line by running `flutter analyze`.
7-
8-
# The following line activates a set of recommended lints for Flutter apps,
9-
# packages, and plugins designed to encourage good coding practices.
10-
include: package:flutter_lints/flutter.yaml
11-
12-
linter:
13-
# The lint rules applied to this project can be customized in the
14-
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
15-
# included above or to enable additional rules. A list of all available lints
16-
# and their documentation is published at
17-
# https://dart-lang.github.io/linter/lints/index.html.
18-
#
19-
# Instead of disabling a lint rule for the entire project in the
20-
# section below, it can also be suppressed for a single line of code
21-
# or a specific dart file by using the `// ignore: name_of_lint` and
22-
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
23-
# producing the lint.
24-
rules:
25-
# avoid_print: false # Uncomment to disable the `avoid_print` rule
26-
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
27-
28-
# Additional information about this file can be found at
29-
# https://dart.dev/guides/language/analysis-options
1+
include: package:rows_lint/analysis_options.yaml

example/lib/main.dart

+14-13
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MyHomePage extends StatelessWidget {
3131
Widget build(BuildContext context) {
3232
return Scaffold(
3333
appBar: AppBar(
34-
title: const Text("Test Data Explorer"),
34+
title: const Text('Test Data Explorer'),
3535
),
3636
body: ListView(
3737
padding: const EdgeInsets.all(16),
@@ -117,7 +117,7 @@ class _DataExplorerPageState extends State<DataExplorerPage> {
117117

118118
@override
119119
void initState() {
120-
loadJsonDataFrom(widget.jsonUrl);
120+
_loadJsonDataFrom(widget.jsonUrl);
121121
super.initState();
122122
}
123123

@@ -141,7 +141,6 @@ class _DataExplorerPageState extends State<DataExplorerPage> {
141141
child: TextField(
142142
controller: searchController,
143143
onChanged: (term) => state.search(term),
144-
maxLines: 1,
145144
decoration: const InputDecoration(
146145
hintText: 'Search',
147146
),
@@ -151,21 +150,20 @@ class _DataExplorerPageState extends State<DataExplorerPage> {
151150
width: 8,
152151
),
153152
if (state.searchResults.isNotEmpty)
154-
Text(
155-
'${state.focusedSearchResultIndex + 1} of ${state.searchResults.length}'),
153+
Text(_searchFocusText()),
156154
if (state.searchResults.isNotEmpty)
157155
IconButton(
158156
onPressed: () {
159157
store.focusPreviousSearchResult();
160-
scrollToSearchMatch();
158+
_scrollToSearchMatch();
161159
},
162160
icon: const Icon(Icons.arrow_drop_up),
163161
),
164162
if (state.searchResults.isNotEmpty)
165163
IconButton(
166164
onPressed: () {
167165
store.focusNextSearchResult();
168-
scrollToSearchMatch();
166+
_scrollToSearchMatch();
169167
},
170168
icon: const Icon(Icons.arrow_drop_down),
171169
),
@@ -215,7 +213,7 @@ class _DataExplorerPageState extends State<DataExplorerPage> {
215213
),
216214
child: Text(
217215
node.isClass
218-
? '{${(node.childrenCount)}}'
216+
? '{${node.childrenCount}}'
219217
: '[${node.childrenCount}]',
220218
style: GoogleFonts.inconsolata(
221219
fontSize: 12,
@@ -252,7 +250,7 @@ class _DataExplorerPageState extends State<DataExplorerPage> {
252250
: const SizedBox(),
253251

254252
/// Creates a custom format for classes and array names.
255-
rootNameFormatter: (name) => '$name',
253+
rootNameFormatter: (dynamic name) => '$name',
256254

257255
/// Theme definitions of the json data explorer
258256
theme: DataExplorerTheme(
@@ -309,11 +307,14 @@ class _DataExplorerPageState extends State<DataExplorerPage> {
309307
);
310308
}
311309

312-
Future loadJsonDataFrom(String url) async {
310+
String _searchFocusText() =>
311+
'${store.focusedSearchResultIndex + 1} of ${store.searchResults.length}';
312+
313+
Future _loadJsonDataFrom(String url) async {
313314
debugPrint('Calling Json API');
314315
final data = await http.read(Uri.parse(url));
315316
debugPrint('Done!');
316-
var decoded = json.decode(data);
317+
final dynamic decoded = json.decode(data);
317318
store.buildNodes(decoded, areAllCollapsed: true);
318319
}
319320

@@ -326,7 +327,7 @@ class _DataExplorerPageState extends State<DataExplorerPage> {
326327
debugPrint('${node.key}: ${node.value}');
327328
}
328329

329-
void scrollToSearchMatch() {
330+
void _scrollToSearchMatch() {
330331
final index = store.displayNodes.indexOf(store.focusedSearchResult.node);
331332
if (index != -1) {
332333
itemScrollController.scrollTo(
@@ -362,7 +363,7 @@ class _OpenJsonButton extends StatelessWidget {
362363
padding: padding,
363364
child: ElevatedButton(
364365
child: Text(title),
365-
onPressed: () => Navigator.of(context).push(
366+
onPressed: () => Navigator.of(context).push<MaterialPageRoute>(
366367
MaterialPageRoute(
367368
builder: (ctx) => DataExplorerPage(
368369
jsonUrl: url,

example/pubspec.lock

+14-14
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ packages:
5050
url: "https://pub.dartlang.org"
5151
source: hosted
5252
version: "3.0.1"
53+
effective_dart:
54+
dependency: transitive
55+
description:
56+
name: effective_dart
57+
url: "https://pub.dartlang.org"
58+
source: hosted
59+
version: "1.3.2"
5360
fake_async:
5461
dependency: transitive
5562
description:
@@ -76,13 +83,6 @@ packages:
7683
description: flutter
7784
source: sdk
7885
version: "0.0.0"
79-
flutter_lints:
80-
dependency: "direct dev"
81-
description:
82-
name: flutter_lints
83-
url: "https://pub.dartlang.org"
84-
source: hosted
85-
version: "1.0.4"
8686
flutter_test:
8787
dependency: "direct dev"
8888
description: flutter
@@ -128,13 +128,6 @@ packages:
128128
relative: true
129129
source: path
130130
version: "0.0.1"
131-
lints:
132-
dependency: transitive
133-
description:
134-
name: lints
135-
url: "https://pub.dartlang.org"
136-
source: hosted
137-
version: "1.0.1"
138131
matcher:
139132
dependency: transitive
140133
description:
@@ -247,6 +240,13 @@ packages:
247240
url: "https://pub.dartlang.org"
248241
source: hosted
249242
version: "6.0.2"
243+
rows_lint:
244+
dependency: "direct dev"
245+
description:
246+
name: rows_lint
247+
url: "https://pub.dartlang.org"
248+
source: hosted
249+
version: "0.1.0"
250250
scrollable_positioned_list:
251251
dependency: transitive
252252
description:

example/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies:
1818
dev_dependencies:
1919
flutter_test:
2020
sdk: flutter
21-
flutter_lints: ^1.0.0
21+
rows_lint: 0.1.0
2222

2323
flutter:
2424
uses-material-design: true

lib/src/data_explorer_store.dart

+18-14
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,19 @@ class NodeViewModelState extends ChangeNotifier {
161161
/// Sets the highlight property of this node and all of its children.
162162
///
163163
/// [notifyListeners] is called to notify all registered listeners.
164-
void highlight(bool highlight) {
165-
_isHighlighted = highlight;
166-
for (var children in children) {
167-
children.highlight(highlight);
164+
void highlight({bool isHighlighted = true}) {
165+
_isHighlighted = isHighlighted;
166+
for (final children in children) {
167+
children.highlight(isHighlighted: isHighlighted);
168168
}
169169
notifyListeners();
170170
}
171171

172172
/// Sets the focus property of this node.
173173
///
174174
/// [notifyListeners] is called to notify all registered listeners.
175-
void focus(bool focus) {
176-
_isFocused = focus;
175+
void focus({bool isFocused = true}) {
176+
_isFocused = isFocused;
177177
notifyListeners();
178178
}
179179

@@ -204,15 +204,15 @@ Map<String, NodeViewModelState> buildViewModelNodes(dynamic object) {
204204
if (object is Map<String, dynamic>) {
205205
return _buildClassNodes(object: object);
206206
}
207-
return _buildClassNodes(object: {'data': object});
207+
return _buildClassNodes(object: <String, dynamic>{'data': object});
208208
}
209209

210210
Map<String, NodeViewModelState> _buildClassNodes({
211211
required Map<String, dynamic> object,
212212
int treeDepth = 0,
213213
}) {
214214
final map = <String, NodeViewModelState>{};
215-
object.forEach((key, value) {
215+
object.forEach((key, dynamic value) {
216216
if (value is Map<String, dynamic>) {
217217
final subClass = _buildClassNodes(
218218
object: value,
@@ -249,8 +249,8 @@ List<NodeViewModelState> _buildArrayNodes({
249249
int treeDepth = 0,
250250
}) {
251251
final array = <NodeViewModelState>[];
252-
for (int i = 0; i < object.length; i++) {
253-
final arrayValue = object[i];
252+
for (var i = 0; i < object.length; i++) {
253+
final dynamic arrayValue = object[i];
254254

255255
if (arrayValue is Map<String, dynamic>) {
256256
final classNode = _buildClassNodes(
@@ -292,9 +292,11 @@ List<NodeViewModelState> _flattenClass(Map<String, NodeViewModelState> object) {
292292

293293
if (!value.isCollapsed) {
294294
if (value.value is Map) {
295-
flatList.addAll(_flattenClass(value.value));
295+
flatList.addAll(
296+
_flattenClass(value.value as Map<String, NodeViewModelState>),
297+
);
296298
} else if (value.value is List) {
297-
flatList.addAll(_flattenArray(value.value));
299+
flatList.addAll(_flattenArray(value.value as List<NodeViewModelState>));
298300
}
299301
}
300302
});
@@ -307,7 +309,9 @@ List<NodeViewModelState> _flattenArray(List<NodeViewModelState> objects) {
307309
flatList.add(object);
308310
if (!object.isCollapsed &&
309311
object.value is Map<String, NodeViewModelState>) {
310-
flatList.addAll(_flattenClass(object.value));
312+
flatList.addAll(
313+
_flattenClass(object.value as Map<String, NodeViewModelState>),
314+
);
311315
}
312316
}
313317
return flatList;
@@ -574,7 +578,7 @@ class DataExplorerStore extends ChangeNotifier {
574578

575579
int _visibleChildrenCount(NodeViewModelState node) {
576580
final children = node.children;
577-
int count = 1;
581+
var count = 1;
578582
for (final child in children) {
579583
count =
580584
child.isCollapsed ? count + 1 : count + _visibleChildrenCount(child);

lib/src/data_explorer_theme.dart

+6-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,12 @@ class DataExplorerTheme {
176176

177177
@override
178178
bool operator ==(Object other) {
179-
if (identical(this, other)) return true;
180-
if (other.runtimeType != runtimeType) return false;
179+
if (identical(this, other)) {
180+
return true;
181+
}
182+
if (other.runtimeType != runtimeType) {
183+
return false;
184+
}
181185
return other is DataExplorerTheme &&
182186
rootKeyTextStyle == other.rootKeyTextStyle &&
183187
propertyKeyTextStyle == other.propertyKeyTextStyle &&

0 commit comments

Comments
 (0)