list_item_base.dart 985 B

1234567891011121314151617181920212223242526272829303132333435
  1. import '../../state/app_state.dart';
  2. import 'package:flutter/widgets.dart';
  3. /// Abstract base class for TOTP list item.
  4. ///
  5. /// Contains useful methods which are used to display the item.
  6. abstract class TotpListItemBase extends StatefulWidget {
  7. const TotpListItemBase(this.item, {super.key});
  8. /// The item/account that is displayed.
  9. final BaseItemType item;
  10. /// Seconds since epoch.
  11. static int get _secondsSinceEpoch {
  12. return DateTime.now().millisecondsSinceEpoch ~/ 1000;
  13. }
  14. /// Progress indicator value.
  15. double get indicatorValue {
  16. return (_secondsSinceEpoch % item.totp.period) / item.totp.period;
  17. }
  18. /// Returns the code of the item for the current time.
  19. String get codeUnformatted {
  20. return item.totp.getCode(_secondsSinceEpoch);
  21. }
  22. /// Returns the code of the item for the current time in formatted form.
  23. String get code {
  24. return item.totp.getPrettyCode(_secondsSinceEpoch);
  25. }
  26. @override
  27. State<StatefulWidget> createState();
  28. }