Skip to content

Commit

Permalink
refactor: enable and fix some lint rules (#452)
Browse files Browse the repository at this point in the history
I enabled a bunch of simple lint rules. All those lints in one pull
request because it would have been a lot of really small pull requests
otherwise. But I created for every lint one commit in case thats better
to review.

~~This pull request introduces the following breaking changes:~~
* ~~Remove the parameter `hash` from `MapOptions` because it was not
used.~~
* ~~The parameter type of `annotationOrder` and
`annotationConsumeTapEvents` from
  `MapLibreMap` has changed to a Set.~~
  • Loading branch information
josxha committed Jun 25, 2024
1 parent 887ee1c commit a47b279
Show file tree
Hide file tree
Showing 79 changed files with 407 additions and 608 deletions.
30 changes: 0 additions & 30 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,60 +10,30 @@ analyzer:
linter:
rules:
# temporary rules
avoid_escaping_inner_quotes: false
prefer_interpolation_to_compose_strings: false
prefer_if_elements_to_conditional_expressions: false
constant_identifier_names: false
flutter_style_todos: false
one_member_abstracts: false
lines_longer_than_80_chars: false
prefer_int_literals: false
unnecessary_lambdas: false
avoid_print: false
noop_primitive_operations: false
avoid_bool_literals_in_conditional_expressions: false
avoid_unused_constructor_parameters: false
no_default_cases: false
sort_pub_dependencies: false
unnecessary_breaks: false
avoid_redundant_argument_values: false
unawaited_futures: false
overridden_fields: false
avoid_setters_without_getters: false
cast_nullable_to_non_nullable: false
only_throw_errors: false
no_runtimeType_toString: false
always_put_required_named_parameters_first: false
leading_newlines_in_multiline_strings: false
prefer_constructors_over_static_methods: false
prefer_null_aware_method_calls: false
directives_ordering: false
unnecessary_await_in_return: false
avoid_multiple_declarations_per_line: false
unnecessary_string_escapes: false
parameter_assignments: false
combinators_ordering: false
use_setters_to_change_properties: false
avoid_equals_and_hash_code_on_mutable_classes: false
type_annotate_public_apis: false
unnecessary_library_directive: false
prefer_asserts_with_message: false
public_member_api_docs: false
require_trailing_commas: false
avoid_dynamic_calls: false
avoid_void_async: false
always_use_package_imports: false
prefer_single_quotes: false
always_declare_return_types: false
sort_constructors_first: false
avoid_relative_lib_imports: false
avoid_positional_boolean_parameters: false
prefer_final_fields: false
prefer_final_locals: false
prefer_final_in_for_each: false
implicit_call_tearoffs: false
comment_references: false
cascade_invocations: false
avoid_type_to_string: false
omit_local_variable_types: false
use_named_constants: false
1 change: 1 addition & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ include: ../analysis_options.yaml
linter:
rules:
public_member_api_docs: false
avoid_redundant_argument_values: false
108 changes: 51 additions & 57 deletions example/lib/annotation_order_maps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,71 +31,65 @@ class _AnnotationOrderBodyState extends State<AnnotationOrderBody> {
return Column(
children: <Widget>[
Card(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 0.0),
child: Column(
children: <Widget>[
const Padding(
padding: EdgeInsets.only(bottom: 5.0),
child: Text(
'This map has polygones (fill) above all other anotations (default behavior)'),
),
Center(
child: SizedBox(
width: 250.0,
height: 250.0,
child: MapLibreMap(
onMapCreated: onMapCreatedOne,
onStyleLoadedCallback: () => onStyleLoaded(controllerOne),
initialCameraPosition: CameraPosition(
target: center,
zoom: 5.0,
),
annotationOrder: const [
AnnotationType.line,
AnnotationType.symbol,
AnnotationType.circle,
AnnotationType.fill,
],
child: Column(
children: <Widget>[
const Padding(
padding: EdgeInsets.only(bottom: 5.0),
child: Text(
'This map has polygones (fill) above all other anotations (default behavior)'),
),
Center(
child: SizedBox(
width: 250.0,
height: 250.0,
child: MapLibreMap(
onMapCreated: onMapCreatedOne,
onStyleLoadedCallback: () => onStyleLoaded(controllerOne),
initialCameraPosition: CameraPosition(
target: center,
zoom: 5.0,
),
annotationOrder: const [
AnnotationType.line,
AnnotationType.symbol,
AnnotationType.circle,
AnnotationType.fill,
],
),
),
],
),
),
],
),
),
Card(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 0.0),
child: Column(
children: <Widget>[
const Padding(
padding: EdgeInsets.only(bottom: 5.0, top: 5.0),
child: Text(
'This map has polygones (fill) under all other anotations'),
),
Center(
child: SizedBox(
width: 250.0,
height: 250.0,
child: MapLibreMap(
onMapCreated: onMapCreatedTwo,
onStyleLoadedCallback: () => onStyleLoaded(controllerTwo),
initialCameraPosition: CameraPosition(
target: center,
zoom: 5.0,
),
annotationOrder: const [
AnnotationType.fill,
AnnotationType.line,
AnnotationType.symbol,
AnnotationType.circle,
],
child: Column(
children: <Widget>[
const Padding(
padding: EdgeInsets.only(bottom: 5.0, top: 5.0),
child: Text(
'This map has polygones (fill) under all other anotations'),
),
Center(
child: SizedBox(
width: 250.0,
height: 250.0,
child: MapLibreMap(
onMapCreated: onMapCreatedTwo,
onStyleLoadedCallback: () => onStyleLoaded(controllerTwo),
initialCameraPosition: CameraPosition(
target: center,
zoom: 5.0,
),
annotationOrder: const [
AnnotationType.fill,
AnnotationType.line,
AnnotationType.symbol,
AnnotationType.circle,
],
),
),
],
),
),
],
),
),
],
Expand All @@ -110,7 +104,7 @@ class _AnnotationOrderBodyState extends State<AnnotationOrderBody> {
controllerTwo = controller;
}

void onStyleLoaded(MapLibreMapController controller) async {
Future<void> onStyleLoaded(MapLibreMapController controller) async {
await addImageFromAsset(
controller, "custom-marker", "assets/symbols/custom-marker.png");
controller.addSymbol(
Expand Down
2 changes: 1 addition & 1 deletion example/lib/click_annotations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ClickAnnotationBodyState extends State<ClickAnnotationBody> {
_showSnackBar('symbol', symbol.id);
}

void _onStyleLoaded() async {
Future<void> _onStyleLoaded() async {
await addImageFromAsset(
controller!, "custom-marker", "assets/symbols/custom-marker.png");
controller!.addCircle(
Expand Down
12 changes: 6 additions & 6 deletions example/lib/custom_marker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class CustomMarkerState extends State<CustomMarker> {
//_measurePerformance();

// Generate random markers
var param = <LatLng>[];
final param = <LatLng>[];
for (var i = 0; i < randomMarkerNum; i++) {
final lat = _rnd.nextDouble() * 20 + 30;
final lng = _rnd.nextDouble() * 20 + 125;
Expand All @@ -120,7 +120,7 @@ class CustomMarkerState extends State<CustomMarker> {

_mapController.toScreenLocationBatch(param).then((value) {
for (var i = 0; i < randomMarkerNum; i++) {
var point =
final point =
Point<double>(value[i].x as double, value[i].y as double);
_addMarker(point, param[i]);
}
Expand All @@ -141,17 +141,17 @@ class CustomMarkerState extends State<CustomMarker> {
}

_mapController.toScreenLocation(const LatLng(0, 0));
Stopwatch sw = Stopwatch();
final sw = Stopwatch();

for (final batch in batches) {
//
// primitive
//
for (var i = 0; i < trial; i++) {
sw.start();
var list = <Future<Point<num>>>[];
final list = <Future<Point<num>>>[];
for (var j = 0; j < batch; j++) {
var p = _mapController
final p = _mapController
.toScreenLocation(LatLng(j.toDouble() % 80, j.toDouble() % 300));
list.add(p);
}
Expand All @@ -166,7 +166,7 @@ class CustomMarkerState extends State<CustomMarker> {
//
for (var i = 0; i < trial; i++) {
sw.start();
var param = <LatLng>[];
final param = <LatLng>[];
for (var j = 0; j < batch; j++) {
param.add(LatLng(j.toDouble() % 80, j.toDouble() % 300));
}
Expand Down
8 changes: 4 additions & 4 deletions example/lib/get_map_informations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ class _GetMapInfoBodyState extends State<GetMapInfoBody> {
});
}

void displaySources() async {
Future<void> displaySources() async {
if (controller == null) {
return;
}
List<String> sources = await controller!.getSourceIds();
final sources = await controller!.getSourceIds();
setState(() {
data = 'Sources: ${sources.map((e) => '"$e"').join(', ')}';
});
}

void displayLayers() async {
Future<void> displayLayers() async {
if (controller == null) {
return;
}
List<String> layers = (await controller!.getLayerIds()).cast<String>();
final layers = (await controller!.getLayerIds()).cast<String>();
setState(() {
data = 'Layers: ${layers.map((e) => '"$e"').join(', ')}';
});
Expand Down
2 changes: 1 addition & 1 deletion example/lib/layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class LayerState extends State {
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}

void _onStyleLoadedCallback() async {
Future<void> _onStyleLoadedCallback() async {
await addImageFromAsset(
controller, "custom-marker", "assets/symbols/custom-marker.png");
await controller.addGeoJsonSource("points", _points);
Expand Down
14 changes: 7 additions & 7 deletions example/lib/line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class LineBodyState extends State<LineBody> {

/// Adds an asset image to the currently displayed style
Future<void> addImageFromAsset(String name, String assetName) async {
final ByteData bytes = await rootBundle.load(assetName);
final Uint8List list = bytes.buffer.asUint8List();
final bytes = await rootBundle.load(assetName);
final list = bytes.buffer.asUint8List();
return controller!.addImage(name, list);
}

Expand Down Expand Up @@ -109,15 +109,15 @@ class LineBodyState extends State<LineBody> {
}

Future<void> _changeLinePattern() async {
String? current =
final current =
_selectedLine!.options.linePattern == null ? "assetImage" : null;
await _updateSelectedLine(
LineOptions(linePattern: current),
);
}

Future<void> _changeAlpha() async {
double? current = _selectedLine!.options.lineOpacity;
var current = _selectedLine!.options.lineOpacity;
current ??= 1.0;

await _updateSelectedLine(
Expand All @@ -126,7 +126,7 @@ class LineBodyState extends State<LineBody> {
}

Future<void> _toggleVisible() async {
double? current = _selectedLine!.options.lineOpacity;
var current = _selectedLine!.options.lineOpacity;
current ??= 1.0;
await _updateSelectedLine(
LineOptions(lineOpacity: current == 0.0 ? 1.0 : 0.0),
Expand Down Expand Up @@ -213,9 +213,9 @@ class LineBodyState extends State<LineBody> {
onPressed: (_selectedLine == null)
? null
: () async {
var latLngs = await controller!
final latLngs = await controller!
.getLineLatLngs(_selectedLine!);
for (var latLng in latLngs) {
for (final latLng in latLngs) {
debugPrint(latLng.toString());
}
},
Expand Down
8 changes: 4 additions & 4 deletions example/lib/local_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ class LocalStyleState extends State<LocalStyle> {
super.initState();

getApplicationDocumentsDirectory().then((dir) async {
String documentDir = dir.path;
String stylesDir = '$documentDir/styles';
String styleJSON =
final documentDir = dir.path;
final stylesDir = '$documentDir/styles';
const styleJSON =
'{"version":8,"name":"Demo style","center":[50,10],"zoom":4,"sources":{"demotiles":{"type":"vector","url":"https://demotiles.maplibre.org/tiles/tiles.json"}},"sprite":"","glyphs":"https://orangemug.github.io/font-glyphs/glyphs/{fontstack}/{range}.pbf","layers":[{"id":"background","type":"background","paint":{"background-color":"rgba(255, 255, 255, 1)"}},{"id":"countries","type":"line","source":"demotiles","source-layer":"countries","paint":{"line-color":"rgba(0, 0, 0, 1)","line-width":1,"line-opacity":1}}]}';

await Directory(stylesDir).create(recursive: true);

File styleFile = File('$stylesDir/style.json');
final styleFile = File('$stylesDir/style.json');

await styleFile.writeAsString(styleJSON);

Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class _MapsDemoState extends State<MapsDemo> {
}
}

void _pushPage(BuildContext context, ExamplePage page) async {
Future<void> _pushPage(BuildContext context, ExamplePage page) async {
if (!kIsWeb && page.needsLocationPermission) {
final location = Location();
final hasPermissions = await location.hasPermission();
Expand Down
Loading

0 comments on commit a47b279

Please sign in to comment.