yubioath-flutter/lib/android/state.dart

46 lines
1.3 KiB
Dart
Raw Normal View History

2022-03-03 18:43:36 +03:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../app/models.dart';
import '../app/state.dart';
import 'api/flutter_management_api_impl.dart';
import 'api/flutter_oath_api_impl.dart';
import 'api/impl.dart';
import 'command_providers.dart';
final androidSubPageProvider = StateNotifierProvider<SubPageNotifier, SubPage>(
(ref) => AndroidSubPageNotifier(ref));
class AndroidSubPageNotifier extends SubPageNotifier {
StateNotifierProviderRef ref;
final AppApi _api = AppApi();
AndroidSubPageNotifier(this.ref) : super(SubPage.oath) {
// TODO find more appropriate place where to setup these api's
FOathApi.setup(FOathApiImpl(ref));
FManagementApi.setup(FManagementApiImpl(ref));
_handleSubPage(SubPage.oath);
}
@override
void setSubPage(SubPage page) {
super.setSubPage(page);
_handleSubPage(page);
}
void _handleSubPage(SubPage subPage) async {
await _api.setContext(subPage.index);
}
}
final androidAttachedDevicesProvider = Provider<List<DeviceNode>>((ref) {
var currentDeviceData = ref.watch(androidDeviceDataProvider);
if (currentDeviceData != null) {
return [currentDeviceData.node];
}
return [];
});
final androidDeviceDataProvider =
2022-03-03 19:24:26 +03:00
Provider<YubiKeyData?>((ref) => ref.watch(androidYubikeyProvider));