Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old package animated_check and implement it ourselves #1370

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions app/lib/common/components/animation/animated_check.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import 'dart:ui';

import 'package:flutter/material.dart';

import 'package:encointer_wallet/theme/theme.dart';

class AnimatedCheck extends StatelessWidget {
const AnimatedCheck({
required this.progress,
required this.size,
this.color,
super.key,
});

final Animation<double> progress;
final double size;
final Color? color;

@override
Widget build(BuildContext context) {
return CustomPaint(
foregroundPainter: AnimatedPathPainter(progress, color ?? context.colorScheme.primary),
child: SizedBox(width: size, height: size),
);
}
}

class AnimatedPathPainter extends CustomPainter {
const AnimatedPathPainter(this.animation, this.color) : super(repaint: animation);

final Animation<double> animation;
final Color color;

Path _createAnyPath(Size size) {
return Path()
..moveTo(0.27083 * size.width, 0.54167 * size.height)
..lineTo(0.41667 * size.width, 0.68750 * size.height)
..lineTo(0.75000 * size.width, 0.35417 * size.height);
}

Path createAnimatedPath(Path originalPath, double animationPercent) {
final totalLength =
// ignore: prefer_int_literals
originalPath.computeMetrics().fold(0.0, (double prev, PathMetric metric) => prev + metric.length);
final currentLength = totalLength * animationPercent;

return extractPathUntilLength(originalPath, currentLength);
}

Path extractPathUntilLength(Path originalPath, double length) {
var currentLength = 0.0;
final path = Path();
final metricsIterator = originalPath.computeMetrics().iterator;

while (metricsIterator.moveNext()) {
final metric = metricsIterator.current;
final nextLength = currentLength + metric.length;
final isLastSegment = nextLength > length;

if (isLastSegment) {
final remainingLength = length - currentLength;
final pathSegment = metric.extractPath(0, remainingLength);
path.addPath(pathSegment, Offset.zero);
break;
} else {
final pathSegment = metric.extractPath(0, metric.length);
path.addPath(pathSegment, Offset.zero);
}
currentLength = nextLength;
}
return path;
}

@override
void paint(Canvas canvas, Size size) {
final animationPercent = animation.value;
final path = createAnimatedPath(_createAnyPath(size), animationPercent);
final paint = Paint()
..color = color
..style = PaintingStyle.stroke
..strokeWidth = size.width * 0.06;
canvas.drawPath(path, paint);
}

@override
bool shouldRepaint(CustomPainter oldDelegate) => true;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';

import 'package:animated_check/animated_check.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:iconsax/iconsax.dart';
Expand All @@ -11,6 +10,7 @@ import 'package:encointer_wallet/common/components/gradient_elements.dart';
import 'package:encointer_wallet/theme/theme.dart';
import 'package:encointer_wallet/config.dart';
import 'package:encointer_wallet/utils/repository_provider.dart';
import 'package:encointer_wallet/common/components/animation/animated_check.dart';
import 'package:encointer_wallet/models/communities/community_identifier.dart';
import 'package:encointer_wallet/page/assets/transfer/payment_confirmation_page/components/payment_overview.dart';
import 'package:encointer_wallet/page/assets/transfer/payment_confirmation_page/components/transfer_state.dart';
Expand Down Expand Up @@ -192,11 +192,7 @@ class _PaymentConfirmationPageState extends State<PaymentConfirmationPage> with

return DecoratedBox(
decoration: const BoxDecoration(shape: BoxShape.circle, color: Colors.green),
child: AnimatedCheck(
progress: _animation!,
size: 100,
color: Colors.white,
),
child: AnimatedCheck(progress: _animation!, size: 100, color: Colors.white),
);
}
case TransferState.failed:
Expand Down
8 changes: 0 additions & 8 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.13.0"
animated_check:
dependency: "direct main"
description:
name: animated_check
sha256: "1da103a44b6aeacbecec799343b7170e627f4af465ca642b430c1d94922868aa"
url: "https://pub.dev"
source: hosted
version: "1.0.5"
animated_stack_widget:
dependency: transitive
description:
Expand Down
1 change: 0 additions & 1 deletion app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ dependencies:
package_info_plus: ^3.1.2
quiver: ^3.2.1
image_picker: ^0.8.8
animated_check: ^1.0.5 # Todo: #1269: replace with alternative package
share_plus: ^6.3.4
flutter_timezone: ^1.0.6

Expand Down
Loading