Skip to content

Commit

Permalink
chore: Support to Flutter 3.24.0 (#440)
Browse files Browse the repository at this point in the history
* chore: Support to Flutter 3.24.0

* Update action.yml

* Update widget_tester.dart

* ignore undefined_hidden_name

* box

* box

* box

* fix todoList

* fix golden tests

* fix generation

* add withNullability

* update custom_lint

* Update action.yml

* retaking golden tests

* fix pipeline

* Update todo_list_page.dart
  • Loading branch information
tilucasoli authored Aug 9, 2024
1 parent 0f81f15 commit 0d9bc96
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ inputs:
flutter-version:
description: 'Flutter version'
required: false
default: ""
default: "stable"
run-dcm:
description: 'Should run DCM'
required: false
Expand Down
2 changes: 1 addition & 1 deletion examples/themed_button/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
sdk: flutter
mix:
path: ../../packages/mix
custom_lint:
custom_lint: ^0.6.4
google_fonts: ^6.0.0
cupertino_icons: ^1.0.6
widgetbook: ^3.7.1
Expand Down
5 changes: 3 additions & 2 deletions examples/todo_list/lib/pages/todo_list_page.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:flutter/material.dart';
import 'package:mix/mix.dart';
import 'package:todo_list/pages/add_task_page.dart';
import 'package:todo_list/pages/controller/task_controller.dart';
import 'package:todo_list/style/components/icon_button.dart';
import 'package:todo_list/style/components/list_tile.dart';
import 'package:todo_list/style/design_tokens.dart';

import '../style/components/icon_button.dart';
import 'add_task_page.dart';

const _colors = ColorTokens();
const _textStyles = TextStyleTokens();

Expand Down
2 changes: 1 addition & 1 deletion examples/todo_list/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
sdk: flutter
mix:
path: ../../packages/mix
custom_lint:
custom_lint: ^0.6.4
google_fonts: ^6.0.0

cupertino_icons: ^1.0.6
Expand Down
4 changes: 2 additions & 2 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ scripts:
failFast: true

analyze:dart:
run: melos exec -c 10 -- dart analyze --fatal-infos
run: melos exec -c 10 -- dart analyze .
description: Run Dart static analysis checks.

analyze:dcm:
Expand Down Expand Up @@ -91,7 +91,7 @@ scripts:
fix:
run: melos run lint:fix:all
custom_lint_analyze:
run: dart pub global activate custom_lint && melos exec --depends-on="mix_lint" custom_lint
run: melos exec --depends-on="mix_lint" dart pub run custom_lint

mix_exports:
run: melos exec --scope="packages/mix" dart run ./scripts/exports.dart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ void main() {
final result = dto.resolve(EmptyMixData);

expect(result.image, equals(imageProvider));
expect(result.alignment, equals(Alignment.center));
expect(result.repeat, equals(ImageRepeat.noRepeat));
expect(result.filterQuality, equals(FilterQuality.low));
expect(result.invertColors, equals(false));
expect(result.isAntiAlias, equals(false));
expect(result.alignment, equals(dto.defaultValue.alignment));
expect(result.repeat, equals(dto.defaultValue.repeat));
expect(result.filterQuality, equals(dto.defaultValue.filterQuality));
expect(result.invertColors, equals(dto.defaultValue.invertColors));
expect(result.isAntiAlias, equals(dto.defaultValue.isAntiAlias));
});

test('resolve with custom values', () {
Expand Down
3 changes: 2 additions & 1 deletion packages/mix_lint/lib/src/lints/attributes_ordering.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/error/error.dart';
// ignore: undefined_hidden_name
import 'package:analyzer/error/error.dart' hide LintCode;
import 'package:analyzer/error/listener.dart';
import 'package:analyzer/source/source_range.dart';
import 'package:custom_lint_builder/custom_lint_builder.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/error/error.dart';
// ignore: undefined_hidden_name
import 'package:analyzer/error/error.dart' hide LintCode;
import 'package:analyzer/error/listener.dart';
import 'package:custom_lint_builder/custom_lint_builder.dart';
import 'package:mix_lint/src/utils/type_checker.dart';
Expand Down
3 changes: 2 additions & 1 deletion packages/mix_lint/lib/src/utils/rule_config.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:analyzer/error/error.dart';
// ignore: undefined_hidden_name
import 'package:analyzer/error/error.dart' hide LintCode;
import 'package:custom_lint_builder/custom_lint_builder.dart';

typedef RuleParameterParser<T> = T Function(Map<String, Object?> json);
Expand Down
2 changes: 1 addition & 1 deletion packages/mix_lint_test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
custom_lint: ^0.6.0
custom_lint: ^0.6.4
analyzer: ^6.0.0
analyzer_plugin: ^0.11.2
test: ^1.24.9
Expand Down
2 changes: 1 addition & 1 deletion packages/remix/demo/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
remix:
path: ../

mix: ^1.4.5
mix: ^1.4.4

dev_dependencies:
flutter_test:
Expand Down
4 changes: 2 additions & 2 deletions packages/remix/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ environment:
dependencies:
flutter:
sdk: flutter
mix: ^1.4.5
mix: ^1.4.4
mix_annotations: ^0.2.1

dev_dependencies:
flutter_test:
sdk: flutter
custom_lint: ^0.6.0
custom_lint: ^0.6.4
mix_lint: ^0.1.1
flutter_lints: ^4.0.0
mix_generator: ^0.2.2+1
Expand Down
34 changes: 34 additions & 0 deletions packages/remix/test/flutter_test_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'dart:async';

import 'package:flutter_test/flutter_test.dart';

import 'utils/extensions/local_file_comparator.dart';

/// Customise your threshold here
/// For example, the error threshold here is 0.5%
/// Golden tests will pass if the pixel difference is equal to or below 0.5%
const _kGoldenTestsThreshold = 0.5 / 100;

Future<void> testExecutable(FutureOr<void> Function() testMain) async {
if (goldenFileComparator is LocalFileComparator) {
final testUrl = (goldenFileComparator as LocalFileComparator).basedir;

goldenFileComparator = LocalFileComparatorWithThreshold(
// flutter_test's LocalFileComparator expects the test's URI to be passed
// as an argument, but it only uses it to parse the baseDir in order to
// obtain the directory where the golden tests will be placed.
// As such, we use the default `testUrl`, which is only the `baseDir` and
// append a generically named `test.dart` so that the `baseDir` is
// properly extracted.
Uri.parse('$testUrl/test.dart'),
_kGoldenTestsThreshold,
);
} else {
throw Exception(
'Expected `goldenFileComparator` to be of type `LocalFileComparator`, '
'but it is of type `${goldenFileComparator.runtimeType}`',
);
}

await testMain();
}
41 changes: 41 additions & 0 deletions packages/remix/test/utils/extensions/local_file_comparator.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';

/// Works just like [LocalFileComparator] but includes a [threshold] that, when
/// exceeded, marks the test as a failure.
class LocalFileComparatorWithThreshold extends LocalFileComparator {
/// Threshold above which tests will be marked as failing.
/// Ranges from 0 to 1, both inclusive.
final double threshold;

LocalFileComparatorWithThreshold(Uri testFile, this.threshold)
: assert(threshold >= 0 && threshold <= 1),
super(testFile);

/// Copy of [LocalFileComparator]'s [compare] method, except for the fact that
/// it checks if the [ComparisonResult.diffPercent] is not greater than
/// [threshold] to decide whether this test is successful or a failure.
@override
Future<bool> compare(Uint8List imageBytes, Uri golden) async {
final result = await GoldenFileComparator.compareLists(
imageBytes,
await getGoldenBytes(golden),
);

if (!result.passed && result.diffPercent <= threshold) {
debugPrint(
'A difference of ${result.diffPercent * 100}% was found, but it is '
'acceptable since it is not greater than the threshold of '
'${threshold * 100}%',
);

return true;
}

if (!result.passed) {
final error = await generateFailureOutput(result, golden, basedir);
throw FlutterError(error);
}
return result.passed;
}
}
2 changes: 0 additions & 2 deletions packages/remix/test/utils/extensions/widget_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ extension WidgetTesterExt on WidgetTester {
Future<void> pumpRxComponent(
Widget widget, {
MixThemeData? data,
Duration? duration,
}) async {
await pumpWidget(
MaterialApp(
Expand All @@ -16,7 +15,6 @@ extension WidgetTesterExt on WidgetTester {
child: widget,
),
),
duration,
);
}
}

0 comments on commit 0d9bc96

Please sign in to comment.