mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Upgrading samples to flutter_lints, part 1 of n (#804)
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
# Defines a default set of lint rules enforced for
|
||||
# projects at Google. For details and rationale,
|
||||
# see https://github.com/dart-lang/pedantic#enabled-lints.
|
||||
include: package:pedantic/analysis_options.yaml
|
||||
|
||||
# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
|
||||
# Uncomment to specify additional rules.
|
||||
# linter:
|
||||
# rules:
|
||||
# - camel_case_types
|
||||
include: package:flutter_lints/flutter.yaml
|
||||
|
||||
analyzer:
|
||||
# exclude:
|
||||
# - path/to/excluded/files/**
|
||||
exclude:
|
||||
- lib/src/data.g.dart
|
||||
strong-mode:
|
||||
implicit-casts: false
|
||||
implicit-dynamic: false
|
||||
|
||||
linter:
|
||||
rules:
|
||||
avoid_types_on_closure_parameters: true
|
||||
avoid_void_async: true
|
||||
cancel_subscriptions: true
|
||||
close_sinks: true
|
||||
directives_ordering: true
|
||||
package_api_docs: true
|
||||
package_prefixed_library_names: true
|
||||
test_types_in_equals: true
|
||||
throw_in_finally: true
|
||||
unnecessary_statements: true
|
||||
use_key_in_widget_constructors: false
|
||||
|
||||
@@ -15,7 +15,7 @@ class CookbookScraper {
|
||||
WebDriver _driver;
|
||||
|
||||
Future init() async {
|
||||
_driver = await createDriver(desired: {});
|
||||
_driver = await createDriver(desired: <String, dynamic>{});
|
||||
}
|
||||
|
||||
Future dispose() async {
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:checked_yaml/checked_yaml.dart';
|
||||
|
||||
import 'src/data.dart';
|
||||
import 'package:checked_yaml/checked_yaml.dart';
|
||||
|
||||
export 'src/data.dart';
|
||||
|
||||
@@ -17,6 +17,7 @@ Future<List<Sample>> getSamples() async {
|
||||
var cookbookContents = await cookbookFile.readAsString();
|
||||
var index = checkedYamlDecode(contents, (m) => Index.fromJson(m),
|
||||
sourceUrl: yamlFile.uri);
|
||||
var cookbookIndex = Index.fromJson(json.decode(cookbookContents));
|
||||
var cookbookIndex =
|
||||
Index.fromJson(json.decode(cookbookContents) as Map<dynamic, dynamic>);
|
||||
return index.samples..addAll(cookbookIndex.samples);
|
||||
}
|
||||
|
||||
@@ -45,13 +45,14 @@ class Carousel {
|
||||
|
||||
// Move to the first slide after init
|
||||
// This is responsible for creating a smooth animation
|
||||
Future.delayed(Duration(milliseconds: 500)).then((value) => _slideRight());
|
||||
Future<void>.delayed(const Duration(milliseconds: 500))
|
||||
.then((value) => _slideRight());
|
||||
}
|
||||
|
||||
void _hideSlides() {
|
||||
slides.forEach((s) {
|
||||
for (final s in slides) {
|
||||
s.classes.add('next-hidden');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _initBullets() {
|
||||
@@ -95,7 +96,7 @@ class Carousel {
|
||||
|
||||
void _touchEndListener(TouchEvent e) {
|
||||
if (touched) {
|
||||
int dx = e.changedTouches.first.client.x - x0;
|
||||
int dx = (e.changedTouches.first.client.x - x0) as int;
|
||||
|
||||
// dx==0 case is ignored
|
||||
if (dx > 0 && currentSlideIndex > 0) {
|
||||
@@ -167,11 +168,11 @@ class Carousel {
|
||||
nextSlide = slides[0];
|
||||
}
|
||||
|
||||
slides.forEach((e) {
|
||||
for (final e in slides) {
|
||||
_removeSlideClasses([e]);
|
||||
if (e.classes.contains('prev-hidden')) e.classes.add('next-hidden');
|
||||
if (e.classes.contains('prev')) e.classes.add('prev-hidden');
|
||||
});
|
||||
}
|
||||
|
||||
_removeSlideClasses([prevSlide, currentSlide, nextSlide]);
|
||||
|
||||
@@ -203,11 +204,11 @@ class Carousel {
|
||||
prevSlide = slides[lastSlideIndex];
|
||||
}
|
||||
|
||||
slides.forEach((e) {
|
||||
for (final e in slides) {
|
||||
_removeSlideClasses([e]);
|
||||
if (e.classes.contains('next')) e.classes.add('next-hidden');
|
||||
if (e.classes.contains('next-hidden')) e.classes.add('prev-hidden');
|
||||
});
|
||||
}
|
||||
|
||||
_removeSlideClasses([prevSlide, currentSlide, nextSlide]);
|
||||
|
||||
@@ -218,7 +219,7 @@ class Carousel {
|
||||
_updateBullets();
|
||||
}
|
||||
|
||||
void _goToIndexSlide(index) {
|
||||
void _goToIndexSlide(int index) {
|
||||
final sliding =
|
||||
(currentSlideIndex < index) ? () => _slideRight() : () => _slideLeft();
|
||||
while (currentSlideIndex != index) {
|
||||
@@ -227,10 +228,10 @@ class Carousel {
|
||||
}
|
||||
|
||||
void _removeSlideClasses(List<Element> slides) {
|
||||
slides.forEach((s) {
|
||||
for (final s in slides) {
|
||||
s.classes
|
||||
.removeAll(['prev-hidden', 'prev', 'active', 'next', 'next-hidden']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _initArrowKeyControl() {
|
||||
|
||||
@@ -7,9 +7,9 @@ import 'data.dart';
|
||||
import 'util.dart' as util;
|
||||
|
||||
String _escapeAttribute(String s) =>
|
||||
HtmlEscape(HtmlEscapeMode.attribute).convert(s);
|
||||
const HtmlEscape(HtmlEscapeMode.attribute).convert(s);
|
||||
String _escapeElement(String s) =>
|
||||
HtmlEscape(HtmlEscapeMode.element).convert(s);
|
||||
const HtmlEscape(HtmlEscapeMode.element).convert(s);
|
||||
|
||||
String description(Sample sample) => '''
|
||||
<!DOCTYPE html>
|
||||
|
||||
@@ -4,7 +4,7 @@ homepage: https://github.com/flutter/samples_index
|
||||
author: Flutter Team <flutter-dev@googlegroups.com>
|
||||
version: 0.0.1
|
||||
environment:
|
||||
sdk: '>=2.5.0 <3.0.0'
|
||||
sdk: ">=2.5.0 <3.0.0"
|
||||
dependencies:
|
||||
json_annotation: ^3.0.0
|
||||
path: ^1.6.0
|
||||
@@ -16,7 +16,7 @@ dependencies:
|
||||
html: ^0.14.0
|
||||
dev_dependencies:
|
||||
grinder: ^0.8.3
|
||||
pedantic: ^1.9.0
|
||||
flutter_lints: ^1.0.0
|
||||
test: ^1.6.0
|
||||
json_serializable: ^3.2.0
|
||||
build: ^1.2.0
|
||||
|
||||
@@ -54,7 +54,7 @@ void main() {
|
||||
var sample = index.samples.first;
|
||||
expect(
|
||||
sample.searchAttributes.split(' '),
|
||||
containsAll([
|
||||
containsAll(const <String>[
|
||||
'kittens',
|
||||
'tag:beginner',
|
||||
'tag:kittens',
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:grinder/grinder.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
@@ -12,10 +12,11 @@ import 'package:samples_index/src/templates.dart' as templates;
|
||||
import 'package:samples_index/cookbook.dart';
|
||||
import 'package:image/image.dart' as image;
|
||||
|
||||
void main(args) => grind(args);
|
||||
Future<void> main(List<String> args) => grind(args);
|
||||
|
||||
@Task('Run tests in the VM')
|
||||
void testCli() async => await TestRunner().testAsync(platformSelector: 'vm');
|
||||
Future<void> testCli() async =>
|
||||
await TestRunner().testAsync(platformSelector: 'vm');
|
||||
|
||||
@Task()
|
||||
void analyze() {
|
||||
@@ -25,13 +26,13 @@ void analyze() {
|
||||
@Task('deploy')
|
||||
@Depends(analyze, testCli, generate, buildRelease)
|
||||
void deploy() {
|
||||
print('All tasks completed. ');
|
||||
print('');
|
||||
log('All tasks completed. ');
|
||||
log('');
|
||||
}
|
||||
|
||||
@Task('Run build_runner to public/ directory')
|
||||
@Depends(createThumbnails)
|
||||
Future buildRelease() async {
|
||||
Future<void> buildRelease() async {
|
||||
var app = PubApp.local('build_runner');
|
||||
await app.runAsync(
|
||||
'build --release --output web:public --delete-conflicting-outputs'
|
||||
@@ -41,9 +42,9 @@ Future buildRelease() async {
|
||||
|
||||
@DefaultTask('Build the project.')
|
||||
@Depends(clean)
|
||||
Future generate() async {
|
||||
Future<void> generate() async {
|
||||
var samples = await getSamples();
|
||||
print('Generating index for ${samples.length} samples...');
|
||||
log('Generating index for ${samples.length} samples...');
|
||||
var outputFile = File('web/index.html');
|
||||
await outputFile.create(recursive: true);
|
||||
await outputFile.writeAsString(templates.index(samples));
|
||||
@@ -55,12 +56,12 @@ Future generate() async {
|
||||
});
|
||||
futures.add(future);
|
||||
}
|
||||
await Future.wait(futures);
|
||||
print('Generated index for ${samples.length} samples.');
|
||||
await Future.wait<void>(futures);
|
||||
log('Generated index for ${samples.length} samples.');
|
||||
}
|
||||
|
||||
@Task('Scrape the cookbook for images and descriptions')
|
||||
Future scrapeCookbook() async {
|
||||
Future<void> scrapeCookbook() async {
|
||||
var driver = await Process.start(
|
||||
'chromedriver', ['--port=4444', '--url-base=wd/hub', '--verbose']);
|
||||
await driver.stdout.pipe(stdout);
|
||||
@@ -68,7 +69,7 @@ Future scrapeCookbook() async {
|
||||
var scraper = CookbookScraper();
|
||||
await scraper.init();
|
||||
var links = await scraper.fetchCookbookLinks();
|
||||
print('Scraping ${links.length} cookbook articles');
|
||||
log('Scraping ${links.length} cookbook articles');
|
||||
var allSamples = <Sample>[];
|
||||
for (var link in links) {
|
||||
allSamples.add(await scraper.getMetadata(link));
|
||||
@@ -76,23 +77,23 @@ Future scrapeCookbook() async {
|
||||
}
|
||||
var file = File('lib/src/cookbook.json');
|
||||
await file.create();
|
||||
var encoder = JsonEncoder.withIndent('\t');
|
||||
var encoder = const JsonEncoder.withIndent('\t');
|
||||
await file.writeAsString(encoder.convert(Index(allSamples)));
|
||||
await scraper.dispose();
|
||||
var killed = driver.kill();
|
||||
if (!killed) {
|
||||
print('failed to kill chromedriver process');
|
||||
log('failed to kill chromedriver process');
|
||||
}
|
||||
}
|
||||
|
||||
@Task('creates thumbnail images in web/images')
|
||||
Future createThumbnails() async {
|
||||
Future<void> createThumbnails() async {
|
||||
await _createThumbnails(Directory('web/images'));
|
||||
await _createThumbnails(Directory('web/images/cookbook'));
|
||||
}
|
||||
|
||||
// Creates a thumbnail image for each png file
|
||||
Future _createThumbnails(Directory directory) async {
|
||||
Future<void> _createThumbnails(Directory directory) async {
|
||||
var files = await directory.list().toList();
|
||||
var filesToWrite = <Future>{};
|
||||
|
||||
@@ -112,16 +113,16 @@ Future _createThumbnails(Directory directory) async {
|
||||
filesToWrite.add(thumbnailFile.writeAsBytes(image.encodePng(resized)));
|
||||
}
|
||||
|
||||
await Future.wait(filesToWrite);
|
||||
await Future.wait<void>(filesToWrite);
|
||||
}
|
||||
|
||||
@Task('remove generated HTML files')
|
||||
Future clean() async {
|
||||
Future<void> clean() async {
|
||||
var tasks = <Future>[];
|
||||
await for (var file in Directory('web').list(recursive: true)) {
|
||||
if (path.extension(file.path) == '.html') {
|
||||
tasks.add(file.delete());
|
||||
}
|
||||
}
|
||||
await Future.wait(tasks);
|
||||
await Future.wait<void>(tasks);
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ void main() {
|
||||
}));
|
||||
|
||||
// Filter cards on each keypress
|
||||
searchBar.listen('keydown', (Event e) async {
|
||||
searchBar.listen('keydown', (e) async {
|
||||
await Future(() {});
|
||||
handleSearch();
|
||||
});
|
||||
|
||||
// Update the URL only when the user is done typing in the search bar
|
||||
searchBar.listen('change', (Event e) {
|
||||
searchBar.listen('change', (e) {
|
||||
queryParams[searchKey] = searchBar.value;
|
||||
updateHash();
|
||||
});
|
||||
@@ -58,7 +58,7 @@ void main() {
|
||||
|
||||
// Initialize chips
|
||||
chipSet = MDCChipSet(querySelector('.mdc-chip-set'));
|
||||
chipSet.listen('MDCChip:selection', (Event e) {
|
||||
chipSet.listen('MDCChip:selection', (e) {
|
||||
// Get the query parameters for this chip
|
||||
var selectedChipIndex = chipSet.chips.indexWhere((chip) => chip.selected);
|
||||
var chipParams = paramsForChip(selectedChipIndex);
|
||||
|
||||
Reference in New Issue
Block a user