import 'package:pb_authenticator_state/state.dart'; import 'package:pb_authenticator_totp/totp.dart'; import 'package:flutter/widgets.dart'; import 'package:collection/collection.dart' show ListEquality; // TODO: Transition to new type typedef BaseItemType = LegacyAuthenticatorItem; /// Represents app state. class AppState extends ChangeNotifier { final RepositoryBase _repository; AppState(this._repository); /// List of TOTP items (internal implementation). List? _items; /// TOTP items as list. List? get items { if (_items == null) { loadItems(); } return _items; } Future loadItems() async { _items = await _repository.loadItems(); notifyListeners(); } /// Adds a TOTP item to the list. Future addItem(TotpItem item) async { await _repository.addItem(item); await loadItems(); } /// Replace list of TOTP items. Future replaceItems(List items) async { await _repository.replaceItems(items); await loadItems(); } bool itemsChanged(List? newItems) { return !const ListEquality().equals(items, newItems); } }