ANTIPALSU Label template editor using flutter

animated_battery.dart 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (c) 2021 Razeware LLC
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // Notwithstanding the foregoing, you may not use, copy, modify, merge, publish,
  14. // distribute, sublicense, create a derivative work, and/or sell copies of the
  15. // Software in any work that is designed, intended, or marketed for pedagogical
  16. // or instructional purposes related to programming, coding, application
  17. // development, or information technology. Permission for such use, copying,
  18. // modification, merger, publication, distribution, sublicensing, creation of
  19. // derivative works, or sale is expressly withheld.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27. // THE SOFTWARE.
  28. import 'battery_painter.dart';
  29. import 'package:flutter/material.dart';
  30. class AnimatedBattery extends StatefulWidget {
  31. const AnimatedBattery({Key? key}) : super(key: key);
  32. @override
  33. _AnimatedBatteryState createState() => _AnimatedBatteryState();
  34. }
  35. class _AnimatedBatteryState extends State<AnimatedBattery>
  36. with SingleTickerProviderStateMixin {
  37. final duration = const Duration(seconds: 5);
  38. late AnimationController _ctrl;
  39. @override
  40. void initState() {
  41. _ctrl = AnimationController(duration: duration, vsync: this)
  42. ..addListener(() => setState(() {}))
  43. ..forward()
  44. ..addStatusListener((status) {
  45. if (status == AnimationStatus.completed) {
  46. _ctrl.reverse();
  47. } else if (status == AnimationStatus.dismissed) {
  48. _ctrl.forward();
  49. }
  50. });
  51. super.initState();
  52. }
  53. @override
  54. Widget build(BuildContext context) {
  55. return CustomPaint(
  56. painter: BatteryPainter(charge: _ctrl.value),
  57. );
  58. }
  59. @override
  60. void dispose() {
  61. _ctrl.dispose();
  62. super.dispose();
  63. }
  64. }