diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..4747a2c --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,31 @@ +name: Publish + +on: + push: + tags: ['v*'] + +jobs: + publish: + name: Publish to pub.dev + + runs-on: ubuntu-latest + permissions: + id-token: write + + steps: + - name: Clone repository + uses: actions/checkout@v4 + + # This step adds the auth token for pub.dev + - name: Set up Dart + uses: dart-lang/setup-dart@v1 + with: + sdk: 3.2 + + - name: Set up Flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: 3.16.x + + - name: Publish and release + uses: leancodepl/mobile-tools/.github/actions/pub-release@pub-release-v1 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index c12b9c5..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Publish - -on: - push: - tags: ['v*'] - -jobs: - publish: - name: Publish to pub.dev - - runs-on: ubuntu-latest - permissions: - id-token: write - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Dart - uses: dart-lang/setup-dart@v1 - with: - sdk: 2.18.6 - - - name: Publish - run: dart pub publish -f diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..4d5082c --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,43 @@ +name: Test + +on: + push: + branches: [main] + tags-ignore: ['v*'] + pull_request: + branches: [main] + +jobs: + test: + name: Flutter ${{ matrix.flutter }} + + strategy: + fail-fast: false + matrix: + flutter: ['3.10.x', '3.13.x', '3.16.x'] + + runs-on: ubuntu-latest + + steps: + - name: Clone repository + uses: actions/checkout@v4 + + - name: Set up Flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: ${{ matrix.flutter }} + + - name: Install dependencies + run: flutter pub get + + - name: Run tests + if: success() || failure() + run: flutter test --coverage + + - name: Run analyzer + if: success() || failure() + run: flutter analyze + + - name: Run formatter + if: success() || failure() + run: dart format --set-exit-if-changed . diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index d134c59..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Test - -on: - push: - branches: [main] - ignore-tags: ['v*'] - pull_request: - branches: [main] - -jobs: - test: - name: Flutter ${{ matrix.flutter }} - - strategy: - fail-fast: false - matrix: - flutter: ['2.0.3', '3.7.3'] - - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup Flutter - uses: subosito/flutter-action@v1 - with: - flutter-version: ${{ matrix.flutter }} - - - name: Flutter version - run: flutter --version - - - name: Cache pub dependencies - uses: actions/cache@v2 - with: - path: ${{ env.FLUTTER_HOME }}/.pub-cache - key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.lock') }} - restore-keys: ${{ runner.os }}-pub- - - - name: Install dependencies - run: flutter pub get - - - name: Analyze - run: flutter analyze --fatal-infos - - - name: Test - run: flutter test diff --git a/analysis_options.yaml b/analysis_options.yaml index 4ac0e31..31551b6 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,10 +1 @@ -include: package:lint/analysis_options_package.yaml - -linter: - rules: - sort_constructors_first: true - prefer_single_quotes: true - -analyzer: - exclude: - - example +include: package:leancode_lint/analysis_options_package.yaml diff --git a/example/lib/main.dart b/example/lib/main.dart index 825ce3e..0c17272 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -25,14 +25,14 @@ class HomeScreen extends StatelessWidget { Text( 'Click me!', textAlign: TextAlign.center, - style: Theme.of(context).textTheme.headline4, + style: Theme.of(context).textTheme.headlineMedium, ), Expanded( child: Padding( padding: const EdgeInsets.fromLTRB(72, 0, 72, 64), child: DashedLine( path: path, - color: Theme.of(context).textTheme.headline4!.color!, + color: Theme.of(context).textTheme.headlineMedium!.color!, ), ), ), diff --git a/example/pubspec.lock b/example/pubspec.lock index 1687209..1e021c7 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,58 +5,57 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.5.0" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.1.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + url: "https://pub.dev" source: hosted - version: "1.15.0" + version: "1.17.1" dashed_line: dependency: "direct main" description: path: ".." relative: true source: path - version: "0.1.0+1" + version: "0.1.0+3" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -67,27 +66,46 @@ packages: description: flutter source: sdk version: "0.0.0" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" + url: "https://pub.dev" source: hosted - version: "0.12.10" + version: "0.12.15" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + url: "https://pub.dev" + source: hosted + version: "0.2.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.9.1" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.8.3" sky_engine: dependency: transitive description: flutter @@ -97,65 +115,66 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.9.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.0" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" svg_path_parser: dependency: transitive description: name: svg_path_parser - url: "https://pub.dartlang.org" + sha256: "9c0c53633baedeaae304b417f07d05f2dc2de3de558dc6a1d8db6e68e72e0d5f" + url: "https://pub.dev" source: hosted version: "1.0.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb + url: "https://pub.dev" source: hosted - version: "0.2.19" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" + version: "0.5.1" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.4" sdks: - dart: ">=2.12.0 <3.0.0" - flutter: ">=2.0.0" + dart: ">=3.0.0 <4.0.0" + flutter: ">=3.10.0" diff --git a/lib/dashed_line.dart b/lib/dashed_line.dart index 515074b..eb81e82 100644 --- a/lib/dashed_line.dart +++ b/lib/dashed_line.dart @@ -1,4 +1,2 @@ -library dashed_line; - export 'src/dashed_line.dart'; export 'src/line_fit.dart'; diff --git a/lib/src/dashed_line.dart b/lib/src/dashed_line.dart index a1d7518..304c9f4 100644 --- a/lib/src/dashed_line.dart +++ b/lib/src/dashed_line.dart @@ -16,7 +16,7 @@ import 'package:svg_path_parser/svg_path_parser.dart'; class DashedLine extends StatelessWidget { /// Creates a dashed line following a `path`. const DashedLine({ - Key? key, + super.key, required this.path, required this.color, this.lineFit = LineFit.contain, @@ -25,7 +25,7 @@ class DashedLine extends StatelessWidget { this.dashSpace = 8, this.dashCap = StrokeCap.butt, this.width = 1, - }) : super(key: key); + }); /// Creates a dashed line following a path defined using SVG path commands. /// @@ -36,7 +36,7 @@ class DashedLine extends StatelessWidget { /// - https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d#path_commands DashedLine.svgPath( String svgPath, { - Key? key, + super.key, required this.color, this.lineFit = LineFit.contain, this.alignment = Alignment.center, @@ -44,8 +44,7 @@ class DashedLine extends StatelessWidget { this.dashSpace = 8, this.dashCap = StrokeCap.butt, this.width = 1, - }) : path = parseSvgPath(svgPath), - super(key: key); + }) : path = parseSvgPath(svgPath); /// The path that the dashed line follows. /// diff --git a/lib/src/dashed_line_painter.dart b/lib/src/dashed_line_painter.dart index 5b57aa8..481dc00 100644 --- a/lib/src/dashed_line_painter.dart +++ b/lib/src/dashed_line_painter.dart @@ -4,7 +4,9 @@ import 'package:dashed_line/src/fitting_path_size.dart'; import 'package:dashed_line/src/line_fit.dart'; import 'package:flutter/rendering.dart'; +/// A [CustomPainter] that can draw dashed lines. class DashedLinePainter extends CustomPainter { + /// Creates a new [DashedLinePainter]. DashedLinePainter({ required this.path, required this.color, @@ -16,13 +18,29 @@ class DashedLinePainter extends CustomPainter { required this.strokeWidth, }); + /// Path that will be drawn by this painter. final Path path; + + /// The color of the dashed line. final Color color; + + /// How a line should be inscribed in a parent. final LineFit lineFit; + + /// How the whole dashed line should be aligned in the parent. final Alignment alignment; + + /// The length of a single dash. final double dashLength; + + /// The space between two neighboring dashes. final double dashSpace; + + /// The width of the edges, given in logical pixels measured in the direction + /// orthogonal to the direction of the path. final double strokeWidth; + + /// The kind of finish to place on the end of line. final StrokeCap strokeCap; @override @@ -43,8 +61,8 @@ class DashedLinePainter extends CustomPainter { ); final pathBounds = path.getBounds(); - // Offset needed to move the path into the painter bounds so - // that it doesn't overflow. + // Offset needed to move the path into the painter bounds so that it doesn't + // overflow. final negativeOffset = Offset( -pathBounds.left * scale.dx, -pathBounds.top * scale.dy, @@ -52,7 +70,7 @@ class DashedLinePainter extends CustomPainter { final pathMetrics = path.computeMetrics(); for (final pathMetric in pathMetrics) { - for (double dist = 0; + for (var dist = 0.0; dist < pathMetric.length; dist += dashLength + dashSpace) { final dashPath = pathMetric @@ -78,6 +96,5 @@ class DashedLinePainter extends CustomPainter { } @override - bool shouldRepaint(DashedLinePainter oldDottedLinePainter) => - path != oldDottedLinePainter.path; + bool shouldRepaint(DashedLinePainter oldDelegate) => path != oldDelegate.path; } diff --git a/lib/src/fitting_path_size.dart b/lib/src/fitting_path_size.dart index 38c7805..db8f7d7 100644 --- a/lib/src/fitting_path_size.dart +++ b/lib/src/fitting_path_size.dart @@ -3,10 +3,14 @@ import 'dart:ui'; import 'package:dashed_line/src/line_fit.dart'; -Offset fittingPathScale(Path path, Size containerSize, LineFit fit) { +/// Calculates the scale by which the [path] should be scaled to fit in a +/// container of size [containerSize], taking [lineFit] into account. +/// +/// The [Offset] returned should be interpreted as a scale in X and Y axes. +Offset fittingPathScale(Path path, Size containerSize, LineFit lineFit) { final pathSize = path.getBounds().size; - if (fit == LineFit.contain) { + if (lineFit == LineFit.contain) { final scale = min( containerSize.width / pathSize.width, containerSize.height / pathSize.height, @@ -21,9 +25,11 @@ Offset fittingPathScale(Path path, Size containerSize, LineFit fit) { } } -Size fittingPathSize(Path path, Size containerSize, LineFit fit) { +/// Calculates the size required to accomodate the [path] in a container of size +/// [containerSize], taking [lineFit] into account. +Size fittingPathSize(Path path, Size containerSize, LineFit lineFit) { final pathSize = path.getBounds().size; - final scale = fittingPathScale(path, containerSize, fit); + final scale = fittingPathScale(path, containerSize, lineFit); return Size(pathSize.width * scale.dx, pathSize.height * scale.dy); } diff --git a/pubspec.yaml b/pubspec.yaml index 7098725..e2433f4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,8 +4,8 @@ version: 0.1.0+3 repository: https://github.com/leancodepl/dashed_line environment: - sdk: '>=2.12.0 <3.0.0' - flutter: '>=2.0.0' + sdk: '>=3.0.0 <4.0.0' + flutter: '>=3.10.0' dependencies: flutter: @@ -15,4 +15,4 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - lint: ^1.5.3 + leancode_lint: ^5.0.0