diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a7e08c1..0cc469a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,20 +39,29 @@ jobs: steps: # Setup - uses: actions/checkout@v1 - - uses: actions/setup-java@v1 - with: - java-version: '13.x' - - uses: subosito/flutter-action@v1 - with: - channel: 'stable' # Release - - run: | + - name: Create artifact + run: | rm -rf nomeyho_clock/ios rm -rf nomeyho_clock/android rm -rf nomeyho_clock/web - - run: zip -r nomeyho_clock.zip ./nomeyho_clock ./flutter_clock_helper - # Artifacts - - uses: actions/upload-artifact@v1 + zip -r nomeyho_clock.zip ./nomeyho_clock ./flutter_clock_helper + - name: Create Release + id: create_release + uses: actions/create-release@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false + - name: Upload Release Asset + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - name: nomeyho_clock.zip - path: nomeyho_clock.zip \ No newline at end of file + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./my-nomeyho_clock.zip + asset_name: my-nomeyho_clock.zip + asset_content_type: application/zip \ No newline at end of file diff --git a/nomeyho_clock/lib/widget/clock_painter.dart b/nomeyho_clock/lib/widget/clock_painter.dart new file mode 100644 index 0000000..01736a2 --- /dev/null +++ b/nomeyho_clock/lib/widget/clock_painter.dart @@ -0,0 +1,46 @@ +import 'dart:math' as math; + +import 'package:flutter/material.dart'; + +/// [CustomPainter] that draws a clock hand. +class HandPainter extends CustomPainter { + HandPainter({ + @required this.handSize, + @required this.lineWidth, + @required this.angleRadians, + @required this.color, + }) : assert(handSize != null), + assert(lineWidth != null), + assert(angleRadians != null), + assert(color != null), + assert(handSize >= 0.0), + assert(handSize <= 1.0); + + double handSize; + double lineWidth; + double angleRadians; + Color color; + + @override + void paint(Canvas canvas, Size size) { + final center = (Offset.zero & size).center; + // We want to start at the top, not at the x-axis, so add pi/2. + final angle = angleRadians - math.pi / 2.0; + final length = size.shortestSide * 0.5 * handSize; + final position = center + Offset(math.cos(angle), math.sin(angle)) * length; + final linePaint = Paint() + ..color = color + ..strokeWidth = lineWidth + ..strokeCap = StrokeCap.square; + + canvas.drawLine(center, position, linePaint); + } + + @override + bool shouldRepaint(HandPainter oldDelegate) { + return oldDelegate.handSize != handSize || + oldDelegate.lineWidth != lineWidth || + oldDelegate.angleRadians != angleRadians || + oldDelegate.color != color; + } +}