mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
Add analysis_options, format and fix up (#104)
This commit is contained in:
32
jsonexample/analysis_options.yaml
Normal file
32
jsonexample/analysis_options.yaml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
include: package:pedantic/analysis_options.yaml
|
||||||
|
|
||||||
|
analyzer:
|
||||||
|
exclude:
|
||||||
|
- lib/json_serializable/*.g.dart
|
||||||
|
strong-mode:
|
||||||
|
implicit-casts: false
|
||||||
|
implicit-dynamic: false
|
||||||
|
|
||||||
|
linter:
|
||||||
|
rules:
|
||||||
|
- avoid_types_on_closure_parameters
|
||||||
|
- avoid_void_async
|
||||||
|
- await_only_futures
|
||||||
|
- camel_case_types
|
||||||
|
- cancel_subscriptions
|
||||||
|
- close_sinks
|
||||||
|
- constant_identifier_names
|
||||||
|
- control_flow_in_finally
|
||||||
|
- empty_statements
|
||||||
|
- hash_and_equals
|
||||||
|
- implementation_imports
|
||||||
|
- non_constant_identifier_names
|
||||||
|
- package_api_docs
|
||||||
|
- package_names
|
||||||
|
- package_prefixed_library_names
|
||||||
|
- test_types_in_equals
|
||||||
|
- throw_in_finally
|
||||||
|
- unnecessary_brace_in_string_interps
|
||||||
|
- unnecessary_getters_setters
|
||||||
|
- unnecessary_new
|
||||||
|
- unnecessary_statements
|
||||||
@@ -40,6 +40,7 @@ abstract class BuiltComplexObject
|
|||||||
|
|
||||||
BuiltComplexObject._();
|
BuiltComplexObject._();
|
||||||
|
|
||||||
factory BuiltComplexObject([updates(BuiltComplexObjectBuilder b)]) =
|
factory BuiltComplexObject(
|
||||||
|
[void Function(BuiltComplexObjectBuilder) updates]) =
|
||||||
_$BuiltComplexObject;
|
_$BuiltComplexObject;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,6 @@ abstract class BuiltSimpleObject
|
|||||||
|
|
||||||
BuiltSimpleObject._();
|
BuiltSimpleObject._();
|
||||||
|
|
||||||
factory BuiltSimpleObject([updates(BuiltSimpleObjectBuilder b)]) =
|
factory BuiltSimpleObject([void Function(BuiltSimpleObjectBuilder) updates]) =
|
||||||
_$BuiltSimpleObject;
|
_$BuiltSimpleObject;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,24 +29,27 @@ class ConvertedComplexObject {
|
|||||||
if (json == null) return null;
|
if (json == null) return null;
|
||||||
|
|
||||||
return ConvertedComplexObject(
|
return ConvertedComplexObject(
|
||||||
aString: json['aString'],
|
aString: json['aString'] as String,
|
||||||
anInt: json['anInt'],
|
anInt: json['anInt'] as int,
|
||||||
aDouble: json['aDouble'],
|
aDouble: json['aDouble'] as double,
|
||||||
anObject: json['anObject'] != null
|
anObject: json['anObject'] != null
|
||||||
? ConvertedSimpleObject.fromJson(json['anObject'])
|
? ConvertedSimpleObject.fromJson(
|
||||||
|
json['anObject'] as Map<String, dynamic>)
|
||||||
: null,
|
: null,
|
||||||
aListOfStrings: json['aListOfStrings'] != null
|
aListOfStrings: json['aListOfStrings'] != null
|
||||||
? List<String>.from(json['aListOfStrings'])
|
? List<String>.from(json['aListOfStrings'] as Iterable<dynamic>)
|
||||||
: null,
|
: null,
|
||||||
aListOfInts: json['aListOfInts'] != null
|
aListOfInts: json['aListOfInts'] != null
|
||||||
? List<int>.from(json['aListOfInts'])
|
? List<int>.from(json['aListOfInts'] as Iterable<dynamic>)
|
||||||
: null,
|
: null,
|
||||||
aListOfDoubles: json['aListOfDoubles'] != null
|
aListOfDoubles: json['aListOfDoubles'] != null
|
||||||
? List<double>.from(json['aListOfDoubles'])
|
? List<double>.from(json['aListOfDoubles'] as Iterable<dynamic>)
|
||||||
: null,
|
: null,
|
||||||
aListOfObjects: json['aListOfObjects'] != null
|
aListOfObjects: json['aListOfObjects'] != null
|
||||||
? List<ConvertedSimpleObject>.from(json['aListOfObjects']
|
? List<ConvertedSimpleObject>.from((json['aListOfObjects']
|
||||||
.map((o) => ConvertedSimpleObject.fromJson(o)))
|
as Iterable<dynamic>)
|
||||||
|
.map<dynamic>((dynamic o) =>
|
||||||
|
ConvertedSimpleObject.fromJson(o as Map<String, dynamic>)))
|
||||||
: null);
|
: null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,17 +23,17 @@ class ConvertedSimpleObject {
|
|||||||
if (json == null) return null;
|
if (json == null) return null;
|
||||||
|
|
||||||
return ConvertedSimpleObject(
|
return ConvertedSimpleObject(
|
||||||
aString: json['aString'],
|
aString: json['aString'] as String,
|
||||||
anInt: json['anInt'],
|
anInt: json['anInt'] as int,
|
||||||
aDouble: json['aDouble'],
|
aDouble: json['aDouble'] as double,
|
||||||
aListOfStrings: json['aListOfStrings'] != null
|
aListOfStrings: json['aListOfStrings'] != null
|
||||||
? List<String>.from(json['aListOfStrings'])
|
? List<String>.from(json['aListOfStrings'] as Iterable<dynamic>)
|
||||||
: null,
|
: null,
|
||||||
aListOfInts: json['aListOfInts'] != null
|
aListOfInts: json['aListOfInts'] != null
|
||||||
? List<int>.from(json['aListOfInts'])
|
? List<int>.from(json['aListOfInts'] as Iterable<dynamic>)
|
||||||
: null,
|
: null,
|
||||||
aListOfDoubles: json['aListOfDoubles'] != null
|
aListOfDoubles: json['aListOfDoubles'] != null
|
||||||
? List<double>.from(json['aListOfDoubles'])
|
? List<double>.from(json['aListOfDoubles'] as Iterable<dynamic>)
|
||||||
: null,
|
: null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
// ignore_for_file: argument_type_not_assignable, strong_mode_implicit_dynamic_parameter, strong_mode_implicit_dynamic_variable
|
||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ class SimpleObjectView extends StatelessWidget {
|
|||||||
Text('aListOfStrings:', style: boldStyle),
|
Text('aListOfStrings:', style: boldStyle),
|
||||||
Text(
|
Text(
|
||||||
prettyPrintList(
|
prettyPrintList(
|
||||||
simpleObject.aListOfStrings,
|
simpleObject.aListOfStrings as Iterable<dynamic>,
|
||||||
),
|
),
|
||||||
style: localTheme.body1,
|
style: localTheme.body1,
|
||||||
),
|
),
|
||||||
@@ -68,7 +68,7 @@ class SimpleObjectView extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Text('aListOfInts:', style: boldStyle),
|
Text('aListOfInts:', style: boldStyle),
|
||||||
Text(
|
Text(
|
||||||
prettyPrintList(simpleObject.aListOfInts),
|
prettyPrintList(simpleObject.aListOfInts as Iterable<dynamic>),
|
||||||
style: localTheme.body1,
|
style: localTheme.body1,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -80,7 +80,7 @@ class SimpleObjectView extends StatelessWidget {
|
|||||||
child: Text('aListOfDoubles:', style: boldStyle),
|
child: Text('aListOfDoubles:', style: boldStyle),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
prettyPrintList(simpleObject.aListOfDoubles),
|
prettyPrintList(simpleObject.aListOfDoubles as Iterable<dynamic>),
|
||||||
style: localTheme.body1,
|
style: localTheme.body1,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -135,7 +135,7 @@ class ComplexObjectView extends StatelessWidget {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (simpleObjects.length == 0) {
|
if (simpleObjects.isEmpty) {
|
||||||
return [
|
return [
|
||||||
const Padding(
|
const Padding(
|
||||||
padding: EdgeInsets.symmetric(vertical: 4.0),
|
padding: EdgeInsets.symmetric(vertical: 4.0),
|
||||||
@@ -145,7 +145,7 @@ class ComplexObjectView extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return simpleObjects
|
return simpleObjects
|
||||||
.expand((o) => [
|
.expand((dynamic o) => [
|
||||||
const SizedBox(height: 4.0),
|
const SizedBox(height: 4.0),
|
||||||
SimpleObjectView(o),
|
SimpleObjectView(o),
|
||||||
const SizedBox(height: 4.0),
|
const SizedBox(height: 4.0),
|
||||||
@@ -213,7 +213,8 @@ class ComplexObjectView extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Text('aListOfStrings:', style: boldStyle),
|
Text('aListOfStrings:', style: boldStyle),
|
||||||
Text(
|
Text(
|
||||||
prettyPrintList(complexObject.aListOfStrings),
|
prettyPrintList(
|
||||||
|
complexObject.aListOfStrings as Iterable<dynamic>),
|
||||||
style: localTheme.body1,
|
style: localTheme.body1,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -222,7 +223,8 @@ class ComplexObjectView extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Text('aListOfInts:', style: boldStyle),
|
Text('aListOfInts:', style: boldStyle),
|
||||||
Text(
|
Text(
|
||||||
prettyPrintList(complexObject.aListOfInts),
|
prettyPrintList(
|
||||||
|
complexObject.aListOfInts as Iterable<dynamic>),
|
||||||
style: localTheme.body1,
|
style: localTheme.body1,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -234,7 +236,8 @@ class ComplexObjectView extends StatelessWidget {
|
|||||||
child: Text('aListOfDoubles:', style: boldStyle),
|
child: Text('aListOfDoubles:', style: boldStyle),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
prettyPrintList(complexObject.aListOfDoubles),
|
prettyPrintList(
|
||||||
|
complexObject.aListOfDoubles as Iterable<dynamic>),
|
||||||
style: localTheme.body1,
|
style: localTheme.body1,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -251,8 +254,8 @@ class ComplexObjectView extends StatelessWidget {
|
|||||||
padding: const EdgeInsets.only(left: 24.0),
|
padding: const EdgeInsets.only(left: 24.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children:
|
children: _generateSimpleObjectWidgets(
|
||||||
_generateSimpleObjectWidgets(complexObject.aListOfObjects),
|
complexObject.aListOfObjects as Iterable<dynamic>),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ packages:
|
|||||||
name: async
|
name: async
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0"
|
version: "2.2.0"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -299,7 +299,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "1.6.2"
|
version: "1.6.2"
|
||||||
pedantic:
|
pedantic:
|
||||||
dependency: transitive
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
name: pedantic
|
name: pedantic
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
@@ -332,7 +332,7 @@ packages:
|
|||||||
name: quiver
|
name: quiver
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.2"
|
version: "2.0.3"
|
||||||
shelf:
|
shelf:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -407,7 +407,7 @@ packages:
|
|||||||
name: test_api
|
name: test_api
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.2.4"
|
version: "0.2.5"
|
||||||
timing:
|
timing:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ dev_dependencies:
|
|||||||
build_runner: ^1.0.0
|
build_runner: ^1.0.0
|
||||||
built_value_generator: ^6.1.5
|
built_value_generator: ^6.1.5
|
||||||
json_serializable: ^2.2.1
|
json_serializable: ^2.2.1
|
||||||
|
pedantic: ^1.5.0
|
||||||
|
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
// ignore_for_file: strong_mode_implicit_dynamic_list_literal
|
||||||
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:jsonexample/built_value/built_simple_object.dart';
|
import 'package:jsonexample/built_value/built_simple_object.dart';
|
||||||
import 'package:jsonexample/built_value/built_value_serializers.dart';
|
import 'package:jsonexample/built_value/built_value_serializers.dart';
|
||||||
|
|||||||
@@ -10,8 +10,7 @@ import 'package:jsonexample/widgets.dart';
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('SimpleObjectView widget test', () {
|
group('SimpleObjectView widget test', () {
|
||||||
testWidgets('Typical object is displayed correctly',
|
testWidgets('Typical object is displayed correctly', (tester) async {
|
||||||
(WidgetTester tester) async {
|
|
||||||
final simpleObject = ConvertedSimpleObject(
|
final simpleObject = ConvertedSimpleObject(
|
||||||
aString: 'Blah, blah, blah',
|
aString: 'Blah, blah, blah',
|
||||||
anInt: 1,
|
anInt: 1,
|
||||||
@@ -35,8 +34,7 @@ void main() {
|
|||||||
expect(find.text('[1.0, 2.0, 3.0]'), findsOneWidget);
|
expect(find.text('[1.0, 2.0, 3.0]'), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Empty lists are displayed as brackets',
|
testWidgets('Empty lists are displayed as brackets', (tester) async {
|
||||||
(WidgetTester tester) async {
|
|
||||||
final simpleObject = ConvertedSimpleObject(
|
final simpleObject = ConvertedSimpleObject(
|
||||||
aString: 'Blah, blah, blah',
|
aString: 'Blah, blah, blah',
|
||||||
anInt: 1,
|
anInt: 1,
|
||||||
@@ -55,8 +53,7 @@ void main() {
|
|||||||
expect(find.text('[]'), findsNWidgets(3));
|
expect(find.text('[]'), findsNWidgets(3));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Null values are displayed as NULL',
|
testWidgets('Null values are displayed as NULL', (tester) async {
|
||||||
(WidgetTester tester) async {
|
|
||||||
final simpleObject = ConvertedSimpleObject(
|
final simpleObject = ConvertedSimpleObject(
|
||||||
aString: null,
|
aString: null,
|
||||||
anInt: null,
|
anInt: null,
|
||||||
@@ -77,8 +74,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
group('ComplexObjectView widget test', () {
|
group('ComplexObjectView widget test', () {
|
||||||
testWidgets('Typical object is displayed correctly',
|
testWidgets('Typical object is displayed correctly', (tester) async {
|
||||||
(WidgetTester tester) async {
|
|
||||||
final complexObject = ConvertedComplexObject(
|
final complexObject = ConvertedComplexObject(
|
||||||
aString: 'Blah, blah, blah',
|
aString: 'Blah, blah, blah',
|
||||||
anInt: 1,
|
anInt: 1,
|
||||||
@@ -145,8 +141,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Empty lists are displayed as brackets',
|
testWidgets('Empty lists are displayed as brackets', (tester) async {
|
||||||
(WidgetTester tester) async {
|
|
||||||
final complexObject = ConvertedComplexObject(
|
final complexObject = ConvertedComplexObject(
|
||||||
aString: 'Blah, blah, blah',
|
aString: 'Blah, blah, blah',
|
||||||
anInt: 1,
|
anInt: 1,
|
||||||
@@ -174,8 +169,7 @@ void main() {
|
|||||||
expect(find.text('[]'), findsNWidgets(4));
|
expect(find.text('[]'), findsNWidgets(4));
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('Null values are displayed as NULL',
|
testWidgets('Null values are displayed as NULL', (tester) async {
|
||||||
(WidgetTester tester) async {
|
|
||||||
final complexObject = ConvertedComplexObject(
|
final complexObject = ConvertedComplexObject(
|
||||||
aString: null,
|
aString: null,
|
||||||
anInt: null,
|
anInt: null,
|
||||||
|
|||||||
Reference in New Issue
Block a user